ug4
smart_pointer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __SMART_POINTER__
34 #define __SMART_POINTER__
35 
36 #include <functional>
37 #include <cstring>
38 #include <boost/pointee.hpp>
39 
42 
45 // Policies
46 
48 // FreeDelete
49 template <typename T>
51 {
52  public:
53  static void free(const T* data) {if(data) delete data;}
54 };
55 
57 // FreeDelete
58 template <typename T>
60 {
61  public:
62  static void free(const T* data) {if(data) delete[] data;}
63 };
64 
66 // FreeRelease
67 template <typename T>
69 {
70  public:
71  static void free(const T* data) {data->Release;}
72 };
73 
74 
76 // PREDECLARATIONS
77 template <class T, template <class TT> class FreePolicy = FreeDelete> class SmartPtr;
78 template <class T, template <class TT> class FreePolicy = FreeDelete> class ConstSmartPtr;
79 
80 
83 
85  public:
87 };
88 
91 
92 
94 // SmartPtr
106 template <typename T, template <class TT> class FreePolicy>
107 class SmartPtr
108 {
109  friend class ConstSmartPtr<T, FreePolicy>;
110  friend class SmartPtr<void>;
111  friend class ConstSmartPtr<void>;
112 
113  public:
114  explicit SmartPtr() : m_ptr(0), m_refCount(0) {}
115  explicit SmartPtr(T* ptr) : m_ptr(ptr), m_refCount(0) {if(ptr) m_refCount = new int(1);}
118  {
119  if(m_refCount) (*m_refCount)++;
120  }
121 
125  template <class TPtr>
127  m_ptr(sp.get_nonconst()),
129  {
130  if(m_refCount) (*m_refCount)++;
131  }
132 
134 
135  T* operator->() {return m_ptr;}
136  const T* operator->() const {return m_ptr;}
137 
138  T& operator*() {return *m_ptr;}
139  const T& operator*() const {return *m_ptr;}
140 
142  if(m_ptr)
143  release();
144  m_ptr = 0;
145  m_refCount = 0;
146  return *this;
147  }
148 
150  if(m_ptr)
151  release();
152  m_ptr = sp.m_ptr;
153  m_refCount = sp.m_refCount;
154  if(m_refCount)
155  (*m_refCount)++;
156  return *this;
157  }
158 
159  template <class TIn>
161  if(m_ptr)
162  release();
163  m_ptr = sp.get_nonconst();
164  m_refCount = sp.refcount_ptr();
165  if(m_refCount)
166  (*m_refCount)++;
167  return *this;
168  }
169 
170  bool operator==(const SmartPtr& sp) const {
171  return (this->get() == sp.get());
172  }
173 
174  bool operator!=(const SmartPtr& sp) const {
175  return !(this->operator==(sp));
176  }
177 
178  bool operator==(NullSmartPtr) const {
179  return m_ptr == 0;
180  }
181 
182  bool operator!=(NullSmartPtr) const {
183  return m_ptr != 0;
184  }
185 
186  template <class TPtr>
188  return (this->get() == sp.get());
189  }
190 
191  template <class TPtr>
193  return !(this->operator==(sp));
194  }
195 
197  T* get() {return m_ptr;}
198 
200  const T* get() const {return m_ptr;}
201 
203  int refcount() const {if(m_refCount) return *m_refCount; return 0;}
204 
206  inline bool valid() const {return m_ptr != NULL;}
207 
208  // pointer compat -- behave like std::shared_ptr<T>
209  explicit operator bool() const noexcept { return m_ptr != NULL; }
210 
212  inline bool invalid() const {return m_ptr == NULL;}
213 
215  template <class TDest>
217  TDest* p = dynamic_cast<TDest*>(m_ptr);
219  else return SmartPtr<TDest, FreePolicy>(NULL);
220  }
221 
223  template <class TDest>
225  TDest* p = static_cast<TDest*>(m_ptr);
227  else return SmartPtr<TDest, FreePolicy>(NULL);
228  }
229 
231  template <class TDest>
233  TDest* p = reinterpret_cast<TDest*>(m_ptr);
235  else return SmartPtr<TDest, FreePolicy>(NULL);
236  }
237 
239  template <class TDest>
240  bool is_of_type() const
241  {
242  return dynamic_cast<TDest*>(m_ptr) != NULL;
243  }
244 
247 
249 
251  explicit SmartPtr(T* ptr, int* refCount) : m_ptr(ptr), m_refCount(refCount)
252  {
253  if(m_refCount)
254  (*m_refCount)++;
255  }
256 
258 
263  int* refcount_ptr() const {return m_refCount;}
264 
265  T* get_nonconst() const {return m_ptr;}
268  private:
270  void release() {
271  if(m_refCount)
272  {
273  (*m_refCount)--;
274  if((*m_refCount) < 1)
275  {
276  delete m_refCount;
277  //delete m_ptr;
278  FreePolicy<T>::free(m_ptr);
279  }
280  }
281  }
282 
284 
285  static void free_void_ptr(const void* ptr){
286  FreePolicy<T>::free(reinterpret_cast<const T*>(ptr));
287  }
288 
289  private:
290  T* m_ptr;
292 };
293 
294 template <typename T, template <class TT> class FreePolicy>
296 {
297  friend class ConstSmartPtr<void>;
298 
299  public:
300  explicit ConstSmartPtr() : m_ptr(0), m_refCount(0) {}
301  explicit ConstSmartPtr(const T* ptr) : m_ptr(ptr), m_refCount(0) {if(ptr) m_refCount = new int(1);}
304  {
305  if(m_refCount) (*m_refCount)++;
306  }
307 
311  template <class TPtr>
313  m_ptr(sp.get()),
315  {
316  if(m_refCount) (*m_refCount)++;
317  }
318 
319  template <class TPtr>
321  m_ptr(sp.get()),
323  {
324  if(m_refCount) (*m_refCount)++;
325  }
326 
328 
329  const T* operator->() const {return m_ptr;}
330 
331  const T& operator*() const {return *m_ptr;}
332 
334  if(m_ptr)
335  release();
336  m_ptr = sp.m_ptr;
337  m_refCount = sp.m_refCount;
338  if(m_refCount)
339  (*m_refCount)++;
340  return *this;
341  }
342 
343  template <class TIn>
345  if(m_ptr)
346  release();
347  m_ptr = sp.get();
348  m_refCount = sp.refcount_ptr();
349  if(m_refCount)
350  (*m_refCount)++;
351  return *this;
352  }
353 
355  if(m_ptr)
356  release();
357  m_ptr = sp.m_ptr;
358  m_refCount = sp.m_refCount;
359  if(m_refCount)
360  (*m_refCount)++;
361  return *this;
362  }
363 
364  template <class TIn>
366  if(m_ptr)
367  release();
368  m_ptr = sp.get();
369  m_refCount = sp.refcount_ptr();
370  if(m_refCount)
371  (*m_refCount)++;
372  return *this;
373  }
374 
376  if(m_ptr)
377  release();
378  m_ptr = 0;
379  m_refCount = 0;
380  return *this;
381  }
382 
383  bool operator==(const ConstSmartPtr& sp) const{
384  return (this->get() == sp.get());
385  }
386 
387  template <class TPtr>
388  bool operator==(const SmartPtr<TPtr, FreePolicy>& sp) const{
389  return (this->get() == sp.get());
390  }
391 
393  return m_ptr == 0;
394  }
395 
396  bool operator!=(const ConstSmartPtr& sp) const{
397  return !(this->operator==(sp));
398  }
399 
400  template <class TPtr>
401  bool operator!=(const SmartPtr<TPtr, FreePolicy>& sp) const{
402  return !(this->operator==(sp));
403  }
404 
406  return m_ptr != NULL;
407  }
408 
409  const T* get() const {return m_ptr;}
410 
411  int refcount() const {if(m_refCount) return *m_refCount; return 0;}
412 
414  inline bool valid() const {return m_ptr != NULL;}
415 
416  // pointer compat -- behave like std::shared_ptr<T>
417  explicit operator bool() const noexcept { return m_ptr != NULL; }
418 
420  inline bool invalid() const {return m_ptr == NULL;}
421 
423  template <class TDest>
425  const TDest* p = dynamic_cast<const TDest*>(m_ptr);
427  else return ConstSmartPtr<TDest, FreePolicy>(NULL);
428  }
429 
431  template <class TDest>
433  const TDest* p = static_cast<const TDest*>(m_ptr);
435  else return ConstSmartPtr<TDest, FreePolicy>(NULL);
436  }
437 
439  template <class TDest>
441  const TDest* p = reinterpret_cast<const TDest*>(m_ptr);
443  else return ConstSmartPtr<TDest, FreePolicy>(NULL);
444  }
445 
448  return SmartPtr<T, FreePolicy>(const_cast<T*>(m_ptr), m_refCount);
449  }
450 
452  template <class TDest>
453  bool is_of_type() const
454  {
455  return dynamic_cast<TDest*>(m_ptr) != NULL;
456  }
457 
459 
461  explicit ConstSmartPtr(const T* ptr, int* refCount) : m_ptr(ptr), m_refCount(refCount)
462  {
463  if(m_refCount)
464  (*m_refCount)++;
465  }
466 
468 
472  int* refcount_ptr() const {return m_refCount;}
473 
474  private:
476  void release() {
477  if(m_refCount)
478  {
479  (*m_refCount)--;
480  if((*m_refCount) < 1)
481  {
482  delete m_refCount;
483  //delete m_ptr;
484  FreePolicy<T>::free(m_ptr);
485  }
486  }
487  }
488 
489  // this release method is required by SmartPtr<void>
490  static void free_void_ptr(void* ptr){
491  FreePolicy<T>::free(reinterpret_cast<T*>(ptr));
492  }
493 
494  private:
495  const T* m_ptr;
497 };
502 
503 template <typename T, template <class TT> class FreePolicy>
505  return ConstSmartPtr<T, FreePolicy>(*this);
506 }
507 
508 
523 template <>
524 class SmartPtr<void>
525 {
526  friend class ConstSmartPtr<void>;
527 
528  public:
529  explicit SmartPtr() : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
530 
531  SmartPtr(NullSmartPtr) : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
532 
534  m_ptr(sp.m_ptr),
535  m_refCountPtr(sp.m_refCountPtr),
536  m_freeFunc(sp.m_freeFunc)
537  {
538  if(m_refCountPtr) (*m_refCountPtr)++;
539  }
540 
541  explicit SmartPtr(void* ptr, void (*freeFunc)(const void*)) :
542  m_ptr(ptr),
543  m_refCountPtr(0),
544  m_freeFunc(freeFunc)
545  {
546  if(ptr) m_refCountPtr = new int(1);
547  }
548 
549  template <class T>
550  SmartPtr(const SmartPtr<T>& sp) :
551  m_ptr((void*)sp.m_ptr),
552  m_refCountPtr(sp.m_refCount),
553  m_freeFunc(&SmartPtr<T>::free_void_ptr)
554  {
555  if(m_refCountPtr) (*m_refCountPtr)++;
556  }
557 
559 
561  {
562  if(m_ptr)
563  release();
564  m_ptr = sp.m_ptr;
565  m_refCountPtr = sp.m_refCountPtr;
566  if(m_refCountPtr)
567  (*m_refCountPtr)++;
568  m_freeFunc = sp.m_freeFunc;
569  return *this;
570  }
571 
572  template <class T>
574  {
575  if(m_ptr)
576  release();
577  m_ptr = sp.m_ptr;
578  m_refCountPtr = sp.m_refCount;
579  if(m_refCountPtr)
580  (*m_refCountPtr)++;
581  m_freeFunc = &SmartPtr<T>::free_void_ptr;
582  return *this;
583  }
584 
585  template <class T>
587  {
588  if(m_ptr)
589  release();
590  m_ptr = 0;
591  m_refCountPtr = 0;
592  m_freeFunc = 0;
593  return *this;
594  }
595 
597 
598  template <class T, template <class TPtr> class TFreePolicy>
600  return SmartPtr<T, TFreePolicy>(reinterpret_cast<T*>(m_ptr), m_refCountPtr);
601  }
602 
604 
607  template <class T, template <class TPtr> class TFreePolicy>
608  void set_impl(void* ptr)
609  {
610  m_ptr = ptr;
612  }
613 
615  inline bool valid() const {return m_ptr != NULL;}
616 
617  // pointer compat -- behave like std::shared_ptr<T>
618  explicit operator bool() const noexcept { return m_ptr != NULL; }
619 
621  inline bool invalid() const {return m_ptr == NULL;}
622 
623  void invalidate() {if(valid()) release(); m_ptr = NULL;}
624 
625  void* get() {return m_ptr;}
626  const void* get() const {return m_ptr;}
627 
628  int refcount() const {if(m_refCountPtr) return *m_refCountPtr; return 0;}
629 
630  private:
631  void release() {
632  if(m_refCountPtr)
633  {
634  (*m_refCountPtr)--;
635  if((*m_refCountPtr) < 1)
636  {
637  delete m_refCountPtr;
638  m_freeFunc(m_ptr);
639  }
640  }
641  }
642 
643  void* m_ptr;
645  void (*m_freeFunc)(const void*);
646 };
647 
648 template <>
649 class ConstSmartPtr<void>
650 {
651  public:
652  explicit ConstSmartPtr() : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
653 
654  explicit ConstSmartPtr(void* ptr, void (*freeFunc)(const void*)) :
655  m_ptr(ptr),
656  m_refCountPtr(0),
657  m_freeFunc(freeFunc)
658  {
659  if(ptr) m_refCountPtr = new int(1);
660  }
661 
662  ConstSmartPtr(NullSmartPtr) : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
663 
665  m_ptr(sp.m_ptr),
666  m_refCountPtr(sp.m_refCountPtr),
667  m_freeFunc(sp.m_freeFunc)
668  {
669  if(m_refCountPtr) (*m_refCountPtr)++;
670  }
671 
673  m_ptr(sp.m_ptr),
674  m_refCountPtr(sp.m_refCountPtr),
675  m_freeFunc(sp.m_freeFunc)
676  {
677  if(m_refCountPtr) (*m_refCountPtr)++;
678  }
679 
680  template <class T, template <class TPtr> class TFreePolicy>
682  m_ptr((void*)sp.m_ptr),
683  m_refCountPtr(sp.m_refCount),
684  m_freeFunc(&SmartPtr<T, TFreePolicy>::free_void_ptr)
685  {
686  if(m_refCountPtr) (*m_refCountPtr)++;
687  }
688 
689  template <class T, template <class TPtr> class TFreePolicy>
691  m_ptr((void*)sp.m_ptr),
692  m_refCountPtr(sp.m_refCount),
693  m_freeFunc(&SmartPtr<T, TFreePolicy>::free_void_ptr)
694  {
695  if(m_refCountPtr) (*m_refCountPtr)++;
696  }
697 
699 
701  {
702  if(m_ptr)
703  release();
704  m_ptr = sp.m_ptr;
705  m_refCountPtr = sp.m_refCountPtr;
706  if(m_refCountPtr)
707  (*m_refCountPtr)++;
708  m_freeFunc = sp.m_freeFunc;
709  return *this;
710  }
711 
713  {
714  if(m_ptr)
715  release();
716  m_ptr = sp.m_ptr;
717  m_refCountPtr = sp.m_refCountPtr;
718  if(m_refCountPtr)
719  (*m_refCountPtr)++;
720  m_freeFunc = sp.m_freeFunc;
721  return *this;
722  }
723 
724  template <class T, template <class TPtr> class TFreePolicy>
726  {
727  if(m_ptr)
728  release();
729  m_ptr = sp.m_ptr;
730  m_refCountPtr = sp.m_refCount;
731  if(m_refCountPtr)
732  (*m_refCountPtr)++;
734  return *this;
735  }
736 
737  template <class T, template <class TPtr> class TFreePolicy>
739  {
740  if(m_ptr)
741  release();
742  m_ptr = sp.m_ptr;
743  m_refCountPtr = sp.m_refCount;
744  if(m_refCountPtr)
745  (*m_refCountPtr)++;
747  return *this;
748  }
749 
751  {
752  if(m_ptr)
753  release();
754  m_ptr = 0;
755  m_refCountPtr = 0;
756  m_freeFunc = 0;
757  return *this;
758  }
759 
761 
762  template <class T, template <class TPtr> class TFreePolicy>
764  return ConstSmartPtr<T, TFreePolicy>(reinterpret_cast<const T*>(m_ptr), m_refCountPtr);
765  }
766 
768 
771  template <class T, template <class TPtr> class TFreePolicy>
772  void set_impl(const void* ptr)
773  {
774  m_ptr = ptr;
776  }
777 
779  inline bool valid() const {return m_ptr != NULL;}
780 
781  // pointer compat -- behave like std::shared_ptr<T>
782  explicit operator bool() const noexcept { return m_ptr != NULL; }
783 
785  inline bool invalid() const {return m_ptr == NULL;}
786 
787  void invalidate() {if(valid()) release(); m_ptr = NULL;}
788 
789  const void* get() const {return m_ptr;}
790 
791  int refcount() const {if(m_refCountPtr) return *m_refCountPtr; return 0;}
792 
793  private:
794  void release() {
795  if(m_refCountPtr)
796  {
797  (*m_refCountPtr)--;
798  if((*m_refCountPtr) < 1)
799  {
800  delete m_refCountPtr;
801  m_freeFunc(const_cast<void*>(m_ptr));
802  }
803  }
804  }
805 
806  const void* m_ptr;
808  void (*m_freeFunc)(const void*);
809 };
810 
811 
812 
813 namespace std
814 {
815  template <class T, template <class TPtr> class TFreePolicy>
816  struct less<SmartPtr<T, TFreePolicy> >
817 #if (__cplusplus < 201103L)
818  : public binary_function<SmartPtr<T, TFreePolicy>, SmartPtr<T, TFreePolicy>, bool>
819 #endif
820  {
822  const SmartPtr<T, TFreePolicy>& rhs) const
823  {
824  return less<T*>()(lhs.get(), rhs.get());
825  }
826  };
827 }
828 
829 
831 // Creation helper for SmartPtr
833 
835 template <typename T, template <class TT> class FreePolicy>
837 {
838  return SmartPtr<T, FreePolicy>(inst);
839 }
840 
842 template <typename T>
844 {
845  return SmartPtr<T>(inst);
846 }
847 
848 namespace boost
849 {
850  template <class T>
851  struct pointee<SmartPtr<T> >
852  {
853  typedef T type;
854  };
855 
856  template <class T>
857  struct pointee<ConstSmartPtr<T> >
858  {
859  typedef T type;
860  };
861 }
862 
863 // end group ugbase_common_util
865 
866 #endif
parameterString p
Definition: smart_pointer.h:650
ConstSmartPtr(const SmartPtr< void > &sp)
Definition: smart_pointer.h:664
ConstSmartPtr()
Definition: smart_pointer.h:652
void release()
Definition: smart_pointer.h:794
const void * m_ptr
Definition: smart_pointer.h:806
ConstSmartPtr< void > & operator=(const ConstSmartPtr< T, TFreePolicy > &sp)
Definition: smart_pointer.h:738
ConstSmartPtr< T, TFreePolicy > cast_reinterpret() const
Returns a SmartPtr with the specified type and shared reference counting.
Definition: smart_pointer.h:763
int * m_refCountPtr
Definition: smart_pointer.h:807
ConstSmartPtr< void > & operator=(const ConstSmartPtr< void > &sp)
Definition: smart_pointer.h:712
ConstSmartPtr(const ConstSmartPtr< void > &sp)
Definition: smart_pointer.h:672
const void * get() const
Definition: smart_pointer.h:789
ConstSmartPtr(NullSmartPtr)
Definition: smart_pointer.h:662
ConstSmartPtr< void > & operator=(const SmartPtr< void > &sp)
Definition: smart_pointer.h:700
ConstSmartPtr(const SmartPtr< T, TFreePolicy > &sp)
Definition: smart_pointer.h:681
void invalidate()
Definition: smart_pointer.h:787
ConstSmartPtr(void *ptr, void(*freeFunc)(const void *))
Definition: smart_pointer.h:654
int refcount() const
Definition: smart_pointer.h:791
void(* m_freeFunc)(const void *)
Definition: smart_pointer.h:808
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:785
~ConstSmartPtr()
Definition: smart_pointer.h:698
ConstSmartPtr(const ConstSmartPtr< T, TFreePolicy > &sp)
Definition: smart_pointer.h:690
ConstSmartPtr< void > & operator=(NullSmartPtr)
Definition: smart_pointer.h:750
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:779
ConstSmartPtr< void > & operator=(const SmartPtr< T, TFreePolicy > &sp)
Definition: smart_pointer.h:725
void set_impl(const void *ptr)
sets the void* to a different location correspoding to a cast to a new type T
Definition: smart_pointer.h:772
Definition: smart_pointer.h:296
const T & operator*() const
Definition: smart_pointer.h:331
bool operator==(NullSmartPtr) const
Definition: smart_pointer.h:392
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:414
ConstSmartPtr(const T *ptr)
Definition: smart_pointer.h:301
int * m_refCount
Definition: smart_pointer.h:496
ConstSmartPtr< TDest, FreePolicy > cast_reinterpret() const
performs a static cast
Definition: smart_pointer.h:440
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:420
ConstSmartPtr & operator=(const ConstSmartPtr &sp)
Definition: smart_pointer.h:354
bool is_of_type() const
Definition: smart_pointer.h:453
ConstSmartPtr(const ConstSmartPtr< TPtr, FreePolicy > &sp)
Definition: smart_pointer.h:320
ConstSmartPtr< T, FreePolicy > & operator=(const SmartPtr< TIn, FreePolicy > &sp)
Definition: smart_pointer.h:344
ConstSmartPtr< T, FreePolicy > & operator=(const ConstSmartPtr< TIn, FreePolicy > &sp)
Definition: smart_pointer.h:365
ConstSmartPtr & operator=(NullSmartPtr)
Definition: smart_pointer.h:375
static void free_void_ptr(void *ptr)
Definition: smart_pointer.h:490
ConstSmartPtr()
Definition: smart_pointer.h:300
ConstSmartPtr(const SmartPtr< TPtr, FreePolicy > &sp)
Definition: smart_pointer.h:312
SmartPtr< T, FreePolicy > cast_const() const
performs a const cast
Definition: smart_pointer.h:447
ConstSmartPtr & operator=(const SmartPtr< T, FreePolicy > &sp)
Definition: smart_pointer.h:333
const T * m_ptr
Definition: smart_pointer.h:495
ConstSmartPtr(NullSmartPtr)
Definition: smart_pointer.h:302
int refcount() const
Definition: smart_pointer.h:411
ConstSmartPtr(const T *ptr, int *refCount)
WARNING: this method is DANGEROUS!
Definition: smart_pointer.h:461
const T * operator->() const
Definition: smart_pointer.h:329
bool operator!=(const ConstSmartPtr &sp) const
Definition: smart_pointer.h:396
bool operator!=(NullSmartPtr) const
Definition: smart_pointer.h:405
int * refcount_ptr() const
WARNING: this method is dangerous!
Definition: smart_pointer.h:472
bool operator==(const SmartPtr< TPtr, FreePolicy > &sp) const
Definition: smart_pointer.h:388
~ConstSmartPtr()
Definition: smart_pointer.h:327
ConstSmartPtr(const ConstSmartPtr &sp)
Definition: smart_pointer.h:303
ConstSmartPtr< TDest, FreePolicy > cast_dynamic() const
preforms a dynamic cast
Definition: smart_pointer.h:424
ConstSmartPtr< TDest, FreePolicy > cast_static() const
performs a static cast
Definition: smart_pointer.h:432
bool operator==(const ConstSmartPtr &sp) const
Definition: smart_pointer.h:383
const T * get() const
Definition: smart_pointer.h:409
void release()
decrements the refCount and frees the encapsulated pointer if required.
Definition: smart_pointer.h:476
bool operator!=(const SmartPtr< TPtr, FreePolicy > &sp) const
Definition: smart_pointer.h:401
Definition: smart_pointer.h:60
static void free(const T *data)
Definition: smart_pointer.h:62
Definition: smart_pointer.h:51
static void free(const T *data)
Definition: smart_pointer.h:53
Definition: smart_pointer.h:69
static void free(const T *data)
Definition: smart_pointer.h:71
Used to construct empty smart pointers.
Definition: smart_pointer.h:84
NullSmartPtr()
Definition: smart_pointer.h:86
Definition: smart_pointer.h:525
void release()
Definition: smart_pointer.h:631
void invalidate()
Definition: smart_pointer.h:623
~SmartPtr()
Definition: smart_pointer.h:558
SmartPtr(NullSmartPtr)
Definition: smart_pointer.h:531
SmartPtr< void > & operator=(const SmartPtr< void > &sp)
Definition: smart_pointer.h:560
int refcount() const
Definition: smart_pointer.h:628
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:621
SmartPtr< void > & operator=(const SmartPtr< T > &sp)
Definition: smart_pointer.h:573
SmartPtr< void > & operator=(NullSmartPtr)
Definition: smart_pointer.h:586
void(* m_freeFunc)(const void *)
Definition: smart_pointer.h:645
void set_impl(void *ptr)
sets the void* to a different location correspoding to a cast to a new type T
Definition: smart_pointer.h:608
SmartPtr(const SmartPtr< void > &sp)
Definition: smart_pointer.h:533
SmartPtr(const SmartPtr< T > &sp)
Definition: smart_pointer.h:550
SmartPtr(void *ptr, void(*freeFunc)(const void *))
Definition: smart_pointer.h:541
SmartPtr()
Definition: smart_pointer.h:529
void * get()
Definition: smart_pointer.h:625
const void * get() const
Definition: smart_pointer.h:626
SmartPtr< T, TFreePolicy > cast_reinterpret() const
Returns a SmartPtr with the specified type and shared reference counting.
Definition: smart_pointer.h:599
void * m_ptr
Definition: smart_pointer.h:643
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:615
int * m_refCountPtr
Definition: smart_pointer.h:644
Definition: smart_pointer.h:108
SmartPtr< TDest, FreePolicy > cast_static() const
performs a static cast
Definition: smart_pointer.h:224
bool operator!=(NullSmartPtr) const
Definition: smart_pointer.h:182
SmartPtr & operator=(const SmartPtr &sp)
Definition: smart_pointer.h:149
T * get_nonconst() const
WARNING: this method is DANGEROUS!
Definition: smart_pointer.h:265
const T * operator->() const
Definition: smart_pointer.h:136
SmartPtr< TDest, FreePolicy > cast_reinterpret() const
performs a reinterpret cast
Definition: smart_pointer.h:232
SmartPtr< T, FreePolicy > & operator=(const SmartPtr< TIn, FreePolicy > &sp)
Definition: smart_pointer.h:160
T * m_ptr
Definition: smart_pointer.h:290
SmartPtr(NullSmartPtr)
Definition: smart_pointer.h:116
static void free_void_ptr(const void *ptr)
this release method is required by SmartPtr<void>
Definition: smart_pointer.h:285
SmartPtr(const SmartPtr &sp)
Definition: smart_pointer.h:117
T * get()
returns encapsulated pointer
Definition: smart_pointer.h:197
bool operator==(const ConstSmartPtr< TPtr, FreePolicy > &sp) const
Definition: smart_pointer.h:187
int * refcount_ptr() const
WARNING: this method is DANGEROUS!
Definition: smart_pointer.h:263
int * m_refCount
Definition: smart_pointer.h:291
const T & operator*() const
Definition: smart_pointer.h:139
bool is_of_type() const
Definition: smart_pointer.h:240
SmartPtr< TDest, FreePolicy > cast_dynamic() const
preforms a dynamic cast
Definition: smart_pointer.h:216
bool operator==(NullSmartPtr) const
Definition: smart_pointer.h:178
bool operator!=(const ConstSmartPtr< TPtr, FreePolicy > &sp) const
Definition: smart_pointer.h:192
ConstSmartPtr< T, FreePolicy > cast_const() const
performs a const cast
Definition: smart_pointer.h:504
SmartPtr()
Definition: smart_pointer.h:114
bool valid() const
returns true if the pointer is valid, false if not.
Definition: smart_pointer.h:206
SmartPtr(T *ptr, int *refCount)
WARNING: this method is DANGEROUS!
Definition: smart_pointer.h:251
SmartPtr & operator=(NullSmartPtr)
Definition: smart_pointer.h:141
void release()
decrements the refCount and frees the encapsulated pointer if required.
Definition: smart_pointer.h:270
int refcount() const
returns refcount
Definition: smart_pointer.h:203
SmartPtr(const SmartPtr< TPtr, FreePolicy > &sp)
Definition: smart_pointer.h:126
~SmartPtr()
Definition: smart_pointer.h:133
T & operator*()
Definition: smart_pointer.h:138
const T * get() const
returns encapsulated pointer
Definition: smart_pointer.h:200
SmartPtr(T *ptr)
Definition: smart_pointer.h:115
bool operator==(const SmartPtr &sp) const
Definition: smart_pointer.h:170
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:212
bool operator!=(const SmartPtr &sp) const
Definition: smart_pointer.h:174
T * operator->()
Definition: smart_pointer.h:135
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
if(!(yy_init))
Definition: lexer.cpp:997
Definition: boost_serialization_routines.h:49
Definition: smart_pointer.h:814
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition: smart_pointer.h:836
T type
Definition: smart_pointer.h:859
T type
Definition: smart_pointer.h:853
bool operator()(const SmartPtr< T, TFreePolicy > &lhs, const SmartPtr< T, TFreePolicy > &rhs) const
Definition: smart_pointer.h:821