CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
smart_ptr.hpp
Go to the documentation of this file.
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-2010 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 
00080       bool operator==( const self_type& that ) const;
00081       bool operator!=( const self_type& that ) const;
00082       bool operator<( const self_type& that ) const;
00083       bool operator<=( const self_type& that ) const;
00084       bool operator>( const self_type& that ) const;
00085       bool operator>=( const self_type& that ) const;
00086 
00087       pointer operator->();
00088       pointer operator->() const;
00089       reference operator*();
00090       reference operator*() const;
00091 
00092     private:
00093       void copy( const self_type& that );
00094       void release();
00095 
00096     private:
00098       unsigned int* m_ref_count;
00099 
00101       pointer m_ptr;
00102 
00103     }; // class smart_ptr
00104   } // namespace memory
00105 } // namespace claw
00106 
00107 #include <claw/impl/smart_ptr.tpp>
00108 
00109 #endif // __CLAW_SMART_PTR_HPP__