00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2008 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien_jorge@yahoo.fr 00024 */ 00031 #ifndef __CLAW_SMART_PTR_HPP__ 00032 #define __CLAW_SMART_PTR_HPP__ 00033 00034 namespace claw 00035 { 00036 namespace memory 00037 { 00050 template<typename T> 00051 class smart_ptr 00052 { 00053 public: 00055 typedef T value_type; 00056 00058 typedef smart_ptr<value_type> self_type; 00059 00061 typedef T& reference; 00062 00064 typedef T* pointer; 00065 00067 typedef const T& const_reference; 00068 00070 typedef const T* const const_pointer; 00071 00072 public: 00073 smart_ptr(); 00074 smart_ptr( pointer data ); 00075 smart_ptr( const self_type& that ); 00076 ~smart_ptr(); 00077 00078 self_type& operator=( const self_type& that ); 00079 bool operator==( const self_type& that ) const; 00080 bool operator!=( const self_type& that ) const; 00081 pointer operator->(); 00082 const_pointer operator->() const; 00083 reference operator*(); 00084 const_reference operator*() const; 00085 00086 private: 00087 void copy( const self_type& that ); 00088 void release(); 00089 00090 private: 00092 unsigned int* m_ref_count; 00093 00095 pointer m_ptr; 00096 00097 }; // class smart_ptr 00098 } // namespace memory 00099 } // namespace claw 00100 00101 #include <claw/impl/smart_ptr.tpp> 00102 00103 #endif // __CLAW_SMART_PTR_HPP__