• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • misc
boost_intrusive_pointer.hpp
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 
19 
20 // This code comes from the boost::intrusive_ptr. I adapted it to
21 // suit my needs ( no dependencies on other boost libs, change the
22 // namespace to avoid conflicts,
23 
24 #ifndef MYBOOST_INTRUSIVE_PTR_HPP_INCLUDED
25 #define MYBOOST_INTRUSIVE_PTR_HPP_INCLUDED
26 
27 //
28 // intrusive_ptr.hpp
29 //
30 // Copyright (c) 2001, 2002 Peter Dimov
31 //
32 // Permission to copy, use, modify, sell and distribute this software
33 // is granted provided this copyright notice appears in all copies.
34 // This software is provided "as is" without express or implied
35 // warranty, and with no claim as to its suitability for any purpose.
36 //
37 // See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation.
38 //
39 
40 #include <functional> // for std::less
41 #include <iosfwd> // for std::basic_ostream
42 
43 
44 namespace myboost
45 {
46 
47 //
48 // intrusive_ptr
49 //
50 // A smart pointer that uses intrusive reference counting.
51 //
52 // Relies on unqualified calls to
53 //
54 // void intrusive_ptr_add_ref(T * p);
55 // void intrusive_ptr_release(T * p);
56 //
57 // (p != 0)
58 //
59 // The object is responsible for destroying itself.
60 //
61 
62 template<class T> class intrusive_ptr
63 {
64 private:
65 
66  typedef intrusive_ptr this_type;
67 
68 public:
69 
70  typedef T element_type;
71 
72  intrusive_ptr(): p_(0)
73  {
74  }
75 
76  intrusive_ptr(T * p, bool add_ref = true): p_(p)
77  {
78  if(p_ != 0 && add_ref) intrusive_ptr_add_ref(p_);
79  }
80 
81 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
82 
83  template<class U> intrusive_ptr(intrusive_ptr<U> const & rhs): p_(rhs.get())
84  {
85  if(p_ != 0) intrusive_ptr_add_ref(p_);
86  }
87 
88 #endif
89 
90  intrusive_ptr(intrusive_ptr const & rhs): p_(rhs.p_)
91  {
92  if(p_ != 0) intrusive_ptr_add_ref(p_);
93  }
94 
95  ~intrusive_ptr()
96  {
97  if(p_ != 0) intrusive_ptr_release(p_);
98  }
99 
100 #if !defined(BOOST_NO_MEMBER_TEMPLATES) || defined(BOOST_MSVC6_MEMBER_TEMPLATES)
101 
102  template<class U> intrusive_ptr & operator=(intrusive_ptr<U> const & rhs)
103  {
104  this_type(rhs).swap(*this);
105  return *this;
106  }
107 
108 #endif
109 
110  intrusive_ptr & operator=(intrusive_ptr const & rhs)
111  {
112  this_type(rhs).swap(*this);
113  return *this;
114  }
115 
116  intrusive_ptr & operator=(T * rhs)
117  {
118  this_type(rhs).swap(*this);
119  return *this;
120  }
121 
122  T * get() const
123  {
124  return p_;
125  }
126 
127  T & operator*() const
128  {
129  return *p_;
130  }
131 
132  T * operator->() const
133  {
134  return p_;
135  }
136 
137  typedef T * (intrusive_ptr::*unspecified_bool_type) () const;
138 
139  operator unspecified_bool_type () const
140  {
141  return p_ == 0? 0: &intrusive_ptr::get;
142  }
143 
144  // operator! is a Borland-specific workaround
145  bool operator! () const
146  {
147  return p_ == 0;
148  }
149 
150  void swap(intrusive_ptr & rhs)
151  {
152  T * tmp = p_;
153  p_ = rhs.p_;
154  rhs.p_ = tmp;
155  }
156 
157 private:
158 
159  T * p_;
160 };
161 
162 template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
163 {
164  return a.get() == b.get();
165 }
166 
167 template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b)
168 {
169  return a.get() != b.get();
170 }
171 
172 template<class T> inline bool operator==(intrusive_ptr<T> const & a, T * b)
173 {
174  return a.get() == b;
175 }
176 
177 template<class T> inline bool operator!=(intrusive_ptr<T> const & a, T * b)
178 {
179  return a.get() != b;
180 }
181 
182 template<class T> inline bool operator==(T * a, intrusive_ptr<T> const & b)
183 {
184  return a == b.get();
185 }
186 
187 template<class T> inline bool operator!=(T * a, intrusive_ptr<T> const & b)
188 {
189  return a != b.get();
190 }
191 
192 #if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
193 
194 // Resolve the ambiguity between our op!= and the one in rel_ops
195 
196 template<class T> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
197 {
198  return a.get() != b.get();
199 }
200 
201 #endif
202 
203 template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b)
204 {
205  return std::less<T *>()(a.get(), b.get());
206 }
207 
208 template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs)
209 {
210  lhs.swap(rhs);
211 }
212 
213 // mem_fn support
214 
215 template<class T> T * get_pointer(intrusive_ptr<T> const & p)
216 {
217  return p.get();
218 }
219 
220 template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p)
221 {
222  return static_cast<T *>(p.get());
223 }
224 
225 template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p)
226 {
227  return dynamic_cast<T *>(p.get());
228 }
229 
230 // operator<<
231 
232 #if defined(__GNUC__) && (__GNUC__ < 3)
233 
234 template<class Y> std::ostream & operator<< (std::ostream & os, intrusive_ptr<Y> const & p)
235 {
236  os << p.get();
237  return os;
238 }
239 
240 #else
241 
242 template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p)
243 {
244  os << p.get();
245  return os;
246 }
247 
248 #endif
249 
250 } // namespace myboost
251 
252 #ifdef BOOST_MSVC
253 # pragma warning(pop)
254 #endif
255 
256 #endif // #ifndef MYBOOST_INTRUSIVE_PTR_HPP_INCLUDED
myboost::operator!=
bool operator!=(intrusive_ptr< T > const &a, intrusive_ptr< U > const &b)
Definition: boost_intrusive_pointer.hpp:167
myboost::intrusive_ptr::intrusive_ptr
intrusive_ptr()
Definition: boost_intrusive_pointer.hpp:72
myboost::intrusive_ptr::operator=
intrusive_ptr & operator=(T *rhs)
Definition: boost_intrusive_pointer.hpp:116
myboost::intrusive_ptr::~intrusive_ptr
~intrusive_ptr()
Definition: boost_intrusive_pointer.hpp:95
myboost::intrusive_ptr::operator=
intrusive_ptr & operator=(intrusive_ptr< U > const &rhs)
Definition: boost_intrusive_pointer.hpp:102
myboost::intrusive_ptr::intrusive_ptr
intrusive_ptr(intrusive_ptr const &rhs)
Definition: boost_intrusive_pointer.hpp:90
myboost::intrusive_ptr
Definition: boost_intrusive_pointer.hpp:62
myboost::intrusive_ptr::operator!
bool operator!() const
Definition: boost_intrusive_pointer.hpp:145
myboost::intrusive_ptr::intrusive_ptr
intrusive_ptr(T *p, bool add_ref=true)
Definition: boost_intrusive_pointer.hpp:76
myboost::intrusive_ptr::operator*
T & operator*() const
Definition: boost_intrusive_pointer.hpp:127
myboost::dynamic_pointer_cast
intrusive_ptr< T > dynamic_pointer_cast(intrusive_ptr< U > const &p)
Definition: boost_intrusive_pointer.hpp:225
myboost::intrusive_ptr::unspecified_bool_type
T *(intrusive_ptr::* unspecified_bool_type)() const
Definition: boost_intrusive_pointer.hpp:137
myboost::intrusive_ptr::operator=
intrusive_ptr & operator=(intrusive_ptr const &rhs)
Definition: boost_intrusive_pointer.hpp:110
myboost::intrusive_ptr::operator->
T * operator->() const
Definition: boost_intrusive_pointer.hpp:132
myboost::intrusive_ptr::swap
void swap(intrusive_ptr &rhs)
Definition: boost_intrusive_pointer.hpp:150
myboost::operator==
bool operator==(intrusive_ptr< T > const &a, intrusive_ptr< U > const &b)
Definition: boost_intrusive_pointer.hpp:162
myboost::intrusive_ptr::element_type
T element_type
Definition: boost_intrusive_pointer.hpp:70
myboost::intrusive_ptr::intrusive_ptr
intrusive_ptr(intrusive_ptr< U > const &rhs)
Definition: boost_intrusive_pointer.hpp:83
intrusive_ptr_release
void intrusive_ptr_release(ObjectCalcer *p)
Definition: object_calcer.cc:95
myboost::static_pointer_cast
intrusive_ptr< T > static_pointer_cast(intrusive_ptr< U > const &p)
Definition: boost_intrusive_pointer.hpp:220
myboost::get_pointer
T * get_pointer(intrusive_ptr< T > const &p)
Definition: boost_intrusive_pointer.hpp:215
myboost::swap
void swap(intrusive_ptr< T > &lhs, intrusive_ptr< T > &rhs)
Definition: boost_intrusive_pointer.hpp:208
myboost::intrusive_ptr::get
T * get() const
Definition: boost_intrusive_pointer.hpp:122
intrusive_ptr_add_ref
void intrusive_ptr_add_ref(ObjectCalcer *p)
Definition: object_calcer.cc:90
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal