libyui
 
Loading...
Searching...
No Matches
ImplPtr.h
1/*
2 Copyright (C) 2000-2012 Novell, Inc
3 This library is free software; you can redistribute it and/or modify
4 it under the terms of the GNU Lesser General Public License as
5 published by the Free Software Foundation; either version 2.1 of the
6 License, or (at your option) version 3.0 of the License. This library
7 is distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 License for more details. You should have received a copy of the GNU
11 Lesser General Public License along with this library; if not, write
12 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13 Floor, Boston, MA 02110-1301 USA
14*/
15
16
17/*-/
18
19 File: ImplPtr.h
20
21 Author: Michael Andres <ma@suse.de>
22
23/-*/
24
25#ifndef ImplPtr_h
26#define ImplPtr_h
27
28#include <boost/noncopyable.hpp>
29#include <boost/scoped_ptr.hpp>
30
41template<class _Impl>
42class ImplPtr : private boost::noncopyable
43{
44#if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR )
45 typedef typename boost::scoped_ptr<_Impl>::unspecified_bool_type unspecified_bool_type;
46#endif
47
48public:
49 typedef _Impl element_type;
50
51 explicit
52 ImplPtr( _Impl * impl_r = 0 ) : _impl( impl_r ) {}
53
54public:
55 void reset( _Impl * impl_r = 0 ) { _impl.reset( impl_r ); }
56
57 void swap( ImplPtr rhs ) { _impl.swap( rhs._impl ); }
58
59public:
60#if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS ) || defined( BOOST_NO_CXX11_NULLPTR )
61 operator unspecified_bool_type() const { return _impl; }
62#else
63 explicit operator bool () const { return _impl.get() != 0; }
64#endif
65
66 const _Impl & operator*() const { return *_impl; }
67 const _Impl * operator->() const { return _impl.get(); }
68 const _Impl * get() const { return _impl.get(); }
69
70 _Impl & operator*() { return *_impl; }
71 _Impl * operator->() { return _impl.get(); }
72 _Impl * get() { return _impl.get(); }
73
74private:
75 boost::scoped_ptr<_Impl> _impl;
76};
77
78template<class _Impl>
79inline bool operator==( ImplPtr<_Impl> & lhs, ImplPtr<_Impl> & rhs ) { return lhs.get() == rhs.get(); }
80
81template<class _Impl>
82inline bool operator!=( ImplPtr<_Impl> & lhs, ImplPtr<_Impl> & rhs ) { return lhs.get() != rhs.get(); }
83
84template<class _Impl>
85inline bool operator< ( ImplPtr<_Impl> & lhs, ImplPtr<_Impl> & rhs ) { return lhs.get() < rhs.get(); }
86
87#endif // ImplPtr_h
Definition ImplPtr.h:43