Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

pimpl_ptr.cti

Go to the documentation of this file.
00001 // $Id: pimpl_ptr.cti 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2010
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 //#include "pimpl_ptr.ih"
00027 
00028 // Custom includes
00029 #include "IgnoreValue.hh"
00030 
00031 #define prefix_ inline
00032 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00033 
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 // senf::pimpl_ptr<T,CloneAllocator>
00036 
00037 template <typename T, class CloneAllocator>
00038 prefix_ senf::pimpl_ptr<T,CloneAllocator>::pimpl_ptr(T* pointee)
00039     : p (pointee)
00040 {
00041     // Is it fair to assume pointer assignment to be atomic on multi-threaded platforms ?
00042     doCopy_ = &myCopyFn;
00043     doDelete_ = &myDeleteFn;
00044 }
00045 
00046 template <typename T, class CloneAllocator>
00047 prefix_ senf::pimpl_ptr<T,CloneAllocator>::pimpl_ptr(const pimpl_ptr & rhs)
00048     : p (doCopy_(rhs.p))
00049 {}
00050 
00051 template <typename T, class CloneAllocator>
00052 prefix_ senf::pimpl_ptr<T,CloneAllocator>::~pimpl_ptr()
00053     throw()
00054 {
00055     doDelete_(p);
00056 }
00057 
00058 template <typename T, class CloneAllocator>
00059 prefix_ const T* senf::pimpl_ptr<T,CloneAllocator>::get()
00060     const throw()
00061 {
00062     return p;
00063 }
00064 
00065 template <typename T, class CloneAllocator>
00066 prefix_ T* senf::pimpl_ptr<T,CloneAllocator>::get()
00067     throw()
00068 {
00069     return p;
00070 }
00071 
00072 template <typename T, class CloneAllocator>
00073 prefix_ const T* senf::pimpl_ptr<T,CloneAllocator>::operator->()
00074     const throw()
00075 {
00076     return p;
00077 }
00078 
00079 template <typename T, class CloneAllocator>
00080 prefix_ T* senf::pimpl_ptr<T,CloneAllocator>::operator->()
00081     throw()
00082 {
00083     return p;
00084 }
00085 
00086 template <typename T, class CloneAllocator>
00087 prefix_ const T& senf::pimpl_ptr<T,CloneAllocator>::operator*()
00088     const throw()
00089 {
00090     return *p;
00091 }
00092 
00093 template <typename T, class CloneAllocator>
00094 prefix_ T& senf::pimpl_ptr<T,CloneAllocator>::operator*()
00095     throw()
00096 {
00097     return *p;
00098 }
00099 
00100 template <typename T, class CloneAllocator>
00101 prefix_ void senf::pimpl_ptr<T,CloneAllocator>::swap(pimpl_ptr & with)
00102     throw()
00103 {
00104     std::swap(p, with.p);
00105 }
00106 
00107 template <typename T, class CloneAllocator>
00108 prefix_ senf::pimpl_ptr<T,CloneAllocator> &
00109 senf::pimpl_ptr<T,CloneAllocator>::operator=(const pimpl_ptr & rhs)
00110 {
00111     T* pp = doCopy_(rhs.p);
00112     doDelete_(p);
00113     p = pp;
00114     return *this;
00115 }
00116 
00117 template <typename T, class CloneAllocator>
00118 prefix_ void senf::pimpl_ptr<T,CloneAllocator>::myDeleteFn(T* p)
00119 {
00120     return CloneAllocator::deallocate_clone(p);
00121 }
00122 
00123 template <typename T, class CloneAllocator>
00124 prefix_ T* senf::pimpl_ptr<T,CloneAllocator>::myCopyFn(const T* p)
00125 {
00126     return CloneAllocator::allocate_clone(*p);
00127 }
00128 
00129 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00130 
00131 template <class T, class CloneAllocator>
00132 prefix_ void std::swap(senf::pimpl_ptr<T,CloneAllocator> & lhs,
00133                        senf::pimpl_ptr<T,CloneAllocator> & rhs)
00134     throw()
00135 {
00136     lhs.swap(rhs);
00137 }
00138 
00139 template <class T, class CloneAllocator>
00140 typename senf::pimpl_ptr<T,CloneAllocator>::Copier
00141     senf::pimpl_ptr<T,CloneAllocator>::doCopy_ (0);
00142 
00143 template <class T, class CloneAllocator>
00144 typename senf::pimpl_ptr<T,CloneAllocator>::Deleter
00145     senf::pimpl_ptr<T,CloneAllocator>::doDelete_ (0);
00146 
00147 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00148 #undef prefix_
00149 
00150 
00151 // Local Variables:
00152 // mode: c++
00153 // fill-column: 100
00154 // comment-column: 40
00155 // c-file-style: "senf"
00156 // indent-tabs-mode: nil
00157 // ispell-local-dictionary: "american"
00158 // compile-command: "scons -u test"
00159 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research