00001 // $Id: intrusive_refcount.hh 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2006 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 #ifndef HH_SENF_Utils_intrusive_refcount_ 00027 #define HH_SENF_Utils_intrusive_refcount_ 1 00028 00029 // Custom includes 00030 #include <boost/utility.hpp> 00031 00032 //#include "intrusive_refcount.mpp" 00033 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00034 00035 namespace senf { 00036 00037 template <class Self> class intrusive_refcount_t; 00038 00044 class intrusive_refcount_base 00045 : public boost::noncopyable 00046 { 00047 public: 00048 typedef unsigned refcount_t; 00049 00050 virtual ~intrusive_refcount_base(); 00051 00052 refcount_t refcount() const; 00053 bool is_shared() const; 00054 00055 protected: 00056 intrusive_refcount_base(); 00057 00058 void add_ref(); 00059 bool release(); 00060 00061 private: 00062 refcount_t refcount_; 00063 00064 template <class S> void intrusive_ptr_add_ref(); 00065 template <class S> void intrusive_ptr_release(); 00066 00067 template <class S> 00068 friend void senf::intrusive_ptr_add_ref(intrusive_refcount_t<S> const * p); 00069 template <class S> 00070 friend void senf::intrusive_ptr_release(intrusive_refcount_t<S> const * p); 00071 }; 00072 00119 template <class Self> 00120 class intrusive_refcount_t 00121 : public intrusive_refcount_base 00122 { 00123 protected: 00124 intrusive_refcount_t(); 00125 }; 00126 00153 class intrusive_refcount 00154 : public intrusive_refcount_t<intrusive_refcount> 00155 { 00156 protected: 00157 intrusive_refcount(); 00158 }; 00159 00160 template <class Self> 00161 void intrusive_ptr_add_ref(intrusive_refcount_t<Self> const * p); 00162 template <class Self> 00163 void intrusive_ptr_release(intrusive_refcount_t<Self> const * p); 00164 00165 } 00166 00167 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00168 #include "intrusive_refcount.cci" 00169 //#include "intrusive_refcount.ct" 00170 #include "intrusive_refcount.cti" 00171 #endif 00172 00173 00174 // Local Variables: 00175 // mode: c++ 00176 // fill-column: 100 00177 // c-file-style: "senf" 00178 // indent-tabs-mode: nil 00179 // ispell-local-dictionary: "american" 00180 // compile-command: "scons -u test" 00181 // comment-column: 40 00182 // End: