libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: ImplPtr.h 00020 00021 Author: Michael Andres <ma@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef ImplPtr_h 00026 #define ImplPtr_h 00027 00028 #include <boost/noncopyable.hpp> 00029 #include <boost/scoped_ptr.hpp> 00030 00031 /** 00032 * Helper template class for implementation pointers (pointers to a private 00033 * class or structure that hold the member variables of a higher-level class 00034 * that is part of a public API). 00035 * 00036 * This pointer class maintains constness of its parent class, i.e. if it is 00037 * used in a const class the class this pointer points to will also be const. 00038 * 00039 * This class automatically deletes the class it points to in its destructor. 00040 **/ 00041 template<class _Impl> 00042 class ImplPtr : private boost::noncopyable 00043 { 00044 #if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR ) 00045 typedef typename boost::scoped_ptr<_Impl>::unspecified_bool_type unspecified_bool_type; 00046 #endif 00047 00048 public: 00049 typedef _Impl element_type; 00050 00051 explicit 00052 ImplPtr( _Impl * impl_r = 0 ) : _impl( impl_r ) {} 00053 00054 public: 00055 void reset( _Impl * impl_r = 0 ) { _impl.reset( impl_r ); } 00056 00057 void swap( ImplPtr rhs ) { _impl.swap( rhs._impl ); } 00058 00059 public: 00060 #if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR ) 00061 operator unspecified_bool_type() const { return _impl; } 00062 #else 00063 explicit operator bool () const { return _impl.get() != 0; } 00064 #endif 00065 00066 const _Impl & operator*() const { return *_impl; } 00067 const _Impl * operator->() const { return _impl.get(); } 00068 const _Impl * get() const { return _impl.get(); } 00069 00070 _Impl & operator*() { return *_impl; } 00071 _Impl * operator->() { return _impl.get(); } 00072 _Impl * get() { return _impl.get(); } 00073 00074 private: 00075 boost::scoped_ptr<_Impl> _impl; 00076 }; 00077 00078 template<class _Impl> 00079 inline bool operator==( ImplPtr<_Impl> & lhs, ImplPtr<_Impl> & rhs ) { return lhs.get() == rhs.get(); } 00080 00081 template<class _Impl> 00082 inline bool operator!=( ImplPtr<_Impl> & lhs, ImplPtr<_Impl> & rhs ) { return lhs.get() != rhs.get(); } 00083 00084 template<class _Impl> 00085 inline bool operator< ( ImplPtr<_Impl> & lhs, ImplPtr<_Impl> & rhs ) { return lhs.get() < rhs.get(); } 00086 00087 #endif // ImplPtr_h