ug4
Loading...
Searching...
No Matches
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
41
44// Policies
45
47// FreeDelete
48template <typename T>
50{
51 public:
52 static void free(const T* data) {if(data) delete data;}
53};
54
56// FreeDelete
57template <typename T>
59{
60 public:
61 static void free(const T* data) {if(data) delete[] data;}
62};
63
65// FreeRelease
66template <typename T>
68{
69 public:
70 static void free(const T* data) {data->Release;}
71};
72
73
75// PREDECLARATIONS
76template <class T, template <class TT> class FreePolicy = FreeDelete> class SmartPtr;
77template <class T, template <class TT> class FreePolicy = FreeDelete> class ConstSmartPtr;
78
79
82
84 public:
86};
87
90
91
93// SmartPtr
105template <typename T, template <class TT> class FreePolicy>
107{
108 friend class ConstSmartPtr<T, FreePolicy>;
109 friend class SmartPtr<void>;
110 friend class ConstSmartPtr<void>;
111
112 public:
113 using element_type = T;
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;
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();
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
179 return m_ptr == 0;
180 }
181
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:
292};
293
294template <typename T, template <class TT> class FreePolicy>
296{
297 friend class ConstSmartPtr<void>;
298
299 public:
300 using element_type = T;
301 explicit ConstSmartPtr() : m_ptr(0), m_refCount(0) {}
302 explicit ConstSmartPtr(const T* ptr) : m_ptr(ptr), m_refCount(0) {if(ptr) m_refCount = new int(1);}
305 {
306 if(m_refCount) (*m_refCount)++;
307 }
308
312 template <class TPtr>
314 m_ptr(sp.get()),
316 {
317 if(m_refCount) (*m_refCount)++;
318 }
319
320 template <class TPtr>
322 m_ptr(sp.get()),
324 {
325 if(m_refCount) (*m_refCount)++;
326 }
327
329
330 const T* operator->() const {return m_ptr;}
331
332 const T& operator*() const {return *m_ptr;}
333
335 if(m_ptr)
336 release();
337 m_ptr = sp.m_ptr;
339 if(m_refCount)
340 (*m_refCount)++;
341 return *this;
342 }
343
344 template <class TIn>
346 if(m_ptr)
347 release();
348 m_ptr = sp.get();
350 if(m_refCount)
351 (*m_refCount)++;
352 return *this;
353 }
354
356 if(m_ptr)
357 release();
358 m_ptr = sp.m_ptr;
360 if(m_refCount)
361 (*m_refCount)++;
362 return *this;
363 }
364
365 template <class TIn>
367 if(m_ptr)
368 release();
369 m_ptr = sp.get();
371 if(m_refCount)
372 (*m_refCount)++;
373 return *this;
374 }
375
377 if(m_ptr)
378 release();
379 m_ptr = 0;
380 m_refCount = 0;
381 return *this;
382 }
383
384 bool operator==(const ConstSmartPtr& sp) const{
385 return (this->get() == sp.get());
386 }
387
388 template <class TPtr>
390 return (this->get() == sp.get());
391 }
392
394 return m_ptr == 0;
395 }
396
397 bool operator!=(const ConstSmartPtr& sp) const{
398 return !(this->operator==(sp));
399 }
400
401 template <class TPtr>
403 return !(this->operator==(sp));
404 }
405
407 return m_ptr != NULL;
408 }
409
410 const T* get() const {return m_ptr;}
411
412 int refcount() const {if(m_refCount) return *m_refCount; return 0;}
413
415 inline bool valid() const {return m_ptr != NULL;}
416
417 // pointer compat -- behave like std::shared_ptr<T>
418 explicit operator bool() const noexcept { return m_ptr != NULL; }
419
421 inline bool invalid() const {return m_ptr == NULL;}
422
424 template <class TDest>
426 const TDest* p = dynamic_cast<const TDest*>(m_ptr);
428 else return ConstSmartPtr<TDest, FreePolicy>(NULL);
429 }
430
432 template <class TDest>
434 const TDest* p = static_cast<const TDest*>(m_ptr);
436 else return ConstSmartPtr<TDest, FreePolicy>(NULL);
437 }
438
440 template <class TDest>
442 const TDest* p = reinterpret_cast<const TDest*>(m_ptr);
444 else return ConstSmartPtr<TDest, FreePolicy>(NULL);
445 }
446
449 return SmartPtr<T, FreePolicy>(const_cast<T*>(m_ptr), m_refCount);
450 }
451
453 template <class TDest>
454 bool is_of_type() const
455 {
456 return dynamic_cast<TDest*>(m_ptr) != NULL;
457 }
458
460
462 explicit ConstSmartPtr(const T* ptr, int* refCount) : m_ptr(ptr), m_refCount(refCount)
463 {
464 if(m_refCount)
465 (*m_refCount)++;
466 }
467
469
473 int* refcount_ptr() const {return m_refCount;}
474
475 private:
477 void release() {
478 if(m_refCount)
479 {
480 (*m_refCount)--;
481 if((*m_refCount) < 1)
482 {
483 delete m_refCount;
484 //delete m_ptr;
485 FreePolicy<T>::free(m_ptr);
486 }
487 }
488 }
489
490 // this release method is required by SmartPtr<void>
491 static void free_void_ptr(void* ptr){
492 FreePolicy<T>::free(reinterpret_cast<T*>(ptr));
493 }
494
495 private:
496 const T* m_ptr;
498};
503
504template <typename T, template <class TT> class FreePolicy>
508
509
524template <>
525class SmartPtr<void>
526{
527 friend class ConstSmartPtr<void>;
528
529 public:
530 using element_type = void;
531 explicit SmartPtr() : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
532
533 SmartPtr(NullSmartPtr) : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
534
536 m_ptr(sp.m_ptr),
537 m_refCountPtr(sp.m_refCountPtr),
538 m_freeFunc(sp.m_freeFunc)
539 {
540 if(m_refCountPtr) (*m_refCountPtr)++;
541 }
542
543 explicit SmartPtr(void* ptr, void (*freeFunc)(const void*)) :
544 m_ptr(ptr),
545 m_refCountPtr(0),
546 m_freeFunc(freeFunc)
547 {
548 if(ptr) m_refCountPtr = new int(1);
549 }
550
551 template <class T>
553 m_ptr((void*)sp.m_ptr),
554 m_refCountPtr(sp.m_refCount),
555 m_freeFunc(&SmartPtr<T>::free_void_ptr)
556 {
557 if(m_refCountPtr) (*m_refCountPtr)++;
558 }
559
561
563 {
564 if(m_ptr)
565 release();
566 m_ptr = sp.m_ptr;
567 m_refCountPtr = sp.m_refCountPtr;
568 if(m_refCountPtr)
569 (*m_refCountPtr)++;
570 m_freeFunc = sp.m_freeFunc;
571 return *this;
572 }
573
574 template <class T>
576 {
577 if(m_ptr)
578 release();
579 m_ptr = sp.m_ptr;
580 m_refCountPtr = sp.m_refCount;
581 if(m_refCountPtr)
582 (*m_refCountPtr)++;
583 m_freeFunc = &SmartPtr<T>::free_void_ptr;
584 return *this;
585 }
586
587 template <class T>
589 {
590 if(m_ptr)
591 release();
592 m_ptr = 0;
593 m_refCountPtr = 0;
594 m_freeFunc = 0;
595 return *this;
596 }
597
599
600 template <class T, template <class TPtr> class TFreePolicy>
602 return SmartPtr<T, TFreePolicy>(reinterpret_cast<T*>(m_ptr), m_refCountPtr);
603 }
604
606
609 template <class T, template <class TPtr> class TFreePolicy>
610 void set_impl(void* ptr)
611 {
612 m_ptr = ptr;
614 }
615
617 inline bool valid() const {return m_ptr != NULL;}
618
619 // pointer compat -- behave like std::shared_ptr<T>
620 explicit operator bool() const noexcept { return m_ptr != NULL; }
621
623 inline bool invalid() const {return m_ptr == NULL;}
624
625 void invalidate() {if(valid()) release(); m_ptr = NULL;}
626
627 void* get() {return m_ptr;}
628 const void* get() const {return m_ptr;}
629
630 int refcount() const {if(m_refCountPtr) return *m_refCountPtr; return 0;}
631
632 private:
633 void release() {
634 if(m_refCountPtr)
635 {
636 (*m_refCountPtr)--;
637 if((*m_refCountPtr) < 1)
638 {
639 delete m_refCountPtr;
640 m_freeFunc(m_ptr);
641 }
642 }
643 }
644
645 void* m_ptr;
647 void (*m_freeFunc)(const void*);
648};
649
650template <>
651class ConstSmartPtr<void>
652{
653 public:
654 using element_type = void;
655 explicit ConstSmartPtr() : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
656
657 explicit ConstSmartPtr(void* ptr, void (*freeFunc)(const void*)) :
658 m_ptr(ptr),
659 m_refCountPtr(0),
660 m_freeFunc(freeFunc)
661 {
662 if(ptr) m_refCountPtr = new int(1);
663 }
664
665 ConstSmartPtr(NullSmartPtr) : m_ptr(0), m_refCountPtr(0), m_freeFunc(0) {}
666
668 m_ptr(sp.m_ptr),
669 m_refCountPtr(sp.m_refCountPtr),
670 m_freeFunc(sp.m_freeFunc)
671 {
672 if(m_refCountPtr) (*m_refCountPtr)++;
673 }
674
676 m_ptr(sp.m_ptr),
677 m_refCountPtr(sp.m_refCountPtr),
678 m_freeFunc(sp.m_freeFunc)
679 {
680 if(m_refCountPtr) (*m_refCountPtr)++;
681 }
682
683 template <class T, template <class TPtr> class TFreePolicy>
685 m_ptr((void*)sp.m_ptr),
686 m_refCountPtr(sp.m_refCount),
687 m_freeFunc(&SmartPtr<T, TFreePolicy>::free_void_ptr)
688 {
689 if(m_refCountPtr) (*m_refCountPtr)++;
690 }
691
692 template <class T, template <class TPtr> class TFreePolicy>
694 m_ptr((void*)sp.m_ptr),
695 m_refCountPtr(sp.m_refCount),
696 m_freeFunc(&SmartPtr<T, TFreePolicy>::free_void_ptr)
697 {
698 if(m_refCountPtr) (*m_refCountPtr)++;
699 }
700
702
704 {
705 if(m_ptr)
706 release();
707 m_ptr = sp.m_ptr;
708 m_refCountPtr = sp.m_refCountPtr;
709 if(m_refCountPtr)
710 (*m_refCountPtr)++;
711 m_freeFunc = sp.m_freeFunc;
712 return *this;
713 }
714
716 {
717 if(m_ptr)
718 release();
719 m_ptr = sp.m_ptr;
720 m_refCountPtr = sp.m_refCountPtr;
721 if(m_refCountPtr)
722 (*m_refCountPtr)++;
723 m_freeFunc = sp.m_freeFunc;
724 return *this;
725 }
726
727 template <class T, template <class TPtr> class TFreePolicy>
729 {
730 if(m_ptr)
731 release();
732 m_ptr = sp.m_ptr;
733 m_refCountPtr = sp.m_refCount;
734 if(m_refCountPtr)
735 (*m_refCountPtr)++;
737 return *this;
738 }
739
740 template <class T, template <class TPtr> class TFreePolicy>
742 {
743 if(m_ptr)
744 release();
745 m_ptr = sp.m_ptr;
746 m_refCountPtr = sp.m_refCount;
747 if(m_refCountPtr)
748 (*m_refCountPtr)++;
750 return *this;
751 }
752
754 {
755 if(m_ptr)
756 release();
757 m_ptr = 0;
758 m_refCountPtr = 0;
759 m_freeFunc = 0;
760 return *this;
761 }
762
764
765 template <class T, template <class TPtr> class TFreePolicy>
767 return ConstSmartPtr<T, TFreePolicy>(reinterpret_cast<const T*>(m_ptr), m_refCountPtr);
768 }
769
771
774 template <class T, template <class TPtr> class TFreePolicy>
775 void set_impl(const void* ptr)
776 {
777 m_ptr = ptr;
779 }
780
782 inline bool valid() const {return m_ptr != NULL;}
783
784 // pointer compat -- behave like std::shared_ptr<T>
785 explicit operator bool() const noexcept { return m_ptr != NULL; }
786
788 inline bool invalid() const {return m_ptr == NULL;}
789
790 void invalidate() {if(valid()) release(); m_ptr = NULL;}
791
792 const void* get() const {return m_ptr;}
793
794 int refcount() const {if(m_refCountPtr) return *m_refCountPtr; return 0;}
795
796 private:
797 void release() {
798 if(m_refCountPtr)
799 {
800 (*m_refCountPtr)--;
801 if((*m_refCountPtr) < 1)
802 {
803 delete m_refCountPtr;
804 m_freeFunc(const_cast<void*>(m_ptr));
805 }
806 }
807 }
808
809 const void* m_ptr;
811 void (*m_freeFunc)(const void*);
812};
813
814
815
816namespace std
817{
818 template <class T, template <class TPtr> class TFreePolicy>
819 struct less<SmartPtr<T, TFreePolicy> >
820#if (__cplusplus < 201103L)
821 : public binary_function<SmartPtr<T, TFreePolicy>, SmartPtr<T, TFreePolicy>, bool>
822#endif
823 {
825 const SmartPtr<T, TFreePolicy>& rhs) const
826 {
827 return less<T*>()(lhs.get(), rhs.get());
828 }
829 };
830}
831
832
834// Creation helper for SmartPtr
836
838template <typename T, template <class TT> class FreePolicy>
840{
841 return SmartPtr<T, FreePolicy>(inst);
842}
843
845template <typename T>
847{
848 return SmartPtr<T>(inst);
849}
850
851// boost::pointee has become deprecated. In C++11, it should be replaced by
852// std::pointer_traits<my_ptr<T>>::element_type
853
854
855// end group ugbase_common_util
857
858#endif
parameterString p
ConstSmartPtr< T, TFreePolicy > cast_reinterpret() const
Returns a SmartPtr with the specified type and shared reference counting.
Definition smart_pointer.h:766
ConstSmartPtr< void > & operator=(const SmartPtr< T, TFreePolicy > &sp)
Definition smart_pointer.h:728
ConstSmartPtr< void > & operator=(const ConstSmartPtr< void > &sp)
Definition smart_pointer.h:715
ConstSmartPtr(const SmartPtr< void > &sp)
Definition smart_pointer.h:667
ConstSmartPtr()
Definition smart_pointer.h:655
ConstSmartPtr< void > & operator=(NullSmartPtr)
Definition smart_pointer.h:753
void release()
Definition smart_pointer.h:797
const void * m_ptr
Definition smart_pointer.h:809
int * m_refCountPtr
Definition smart_pointer.h:810
ConstSmartPtr(const ConstSmartPtr< void > &sp)
Definition smart_pointer.h:675
const void * get() const
Definition smart_pointer.h:792
ConstSmartPtr(NullSmartPtr)
Definition smart_pointer.h:665
void element_type
Definition smart_pointer.h:654
ConstSmartPtr(const SmartPtr< T, TFreePolicy > &sp)
Definition smart_pointer.h:684
void invalidate()
Definition smart_pointer.h:790
ConstSmartPtr(void *ptr, void(*freeFunc)(const void *))
Definition smart_pointer.h:657
int refcount() const
Definition smart_pointer.h:794
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition smart_pointer.h:788
ConstSmartPtr< void > & operator=(const ConstSmartPtr< T, TFreePolicy > &sp)
Definition smart_pointer.h:741
ConstSmartPtr< void > & operator=(const SmartPtr< void > &sp)
Definition smart_pointer.h:703
~ConstSmartPtr()
Definition smart_pointer.h:701
ConstSmartPtr(const ConstSmartPtr< T, TFreePolicy > &sp)
Definition smart_pointer.h:693
bool valid() const
returns true if the pointer is valid, false if not.
Definition smart_pointer.h:782
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:775
Definition smart_pointer.h:296
const T * get() const
Definition smart_pointer.h:410
ConstSmartPtr & operator=(const SmartPtr< T, FreePolicy > &sp)
Definition smart_pointer.h:334
bool operator==(NullSmartPtr) const
Definition smart_pointer.h:393
ConstSmartPtr< TDest, FreePolicy > cast_reinterpret() const
performs a static cast
Definition smart_pointer.h:441
bool valid() const
returns true if the pointer is valid, false if not.
Definition smart_pointer.h:415
ConstSmartPtr(const T *ptr)
Definition smart_pointer.h:302
int * m_refCount
Definition smart_pointer.h:497
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition smart_pointer.h:421
bool is_of_type() const
Definition smart_pointer.h:454
ConstSmartPtr(const ConstSmartPtr< TPtr, FreePolicy > &sp)
Definition smart_pointer.h:321
T element_type
Definition smart_pointer.h:300
ConstSmartPtr< T, FreePolicy > & operator=(const SmartPtr< TIn, FreePolicy > &sp)
Definition smart_pointer.h:345
static void free_void_ptr(void *ptr)
Definition smart_pointer.h:491
ConstSmartPtr< TDest, FreePolicy > cast_static() const
performs a static cast
Definition smart_pointer.h:433
ConstSmartPtr()
Definition smart_pointer.h:301
ConstSmartPtr(const SmartPtr< TPtr, FreePolicy > &sp)
Definition smart_pointer.h:313
const T * operator->() const
Definition smart_pointer.h:330
ConstSmartPtr< TDest, FreePolicy > cast_dynamic() const
preforms a dynamic cast
Definition smart_pointer.h:425
const T * m_ptr
Definition smart_pointer.h:496
ConstSmartPtr(NullSmartPtr)
Definition smart_pointer.h:303
int refcount() const
Definition smart_pointer.h:412
ConstSmartPtr(const T *ptr, int *refCount)
WARNING: this method is DANGEROUS!
Definition smart_pointer.h:462
bool operator!=(const ConstSmartPtr &sp) const
Definition smart_pointer.h:397
bool operator!=(NullSmartPtr) const
Definition smart_pointer.h:406
bool operator==(const SmartPtr< TPtr, FreePolicy > &sp) const
Definition smart_pointer.h:389
~ConstSmartPtr()
Definition smart_pointer.h:328
ConstSmartPtr & operator=(NullSmartPtr)
Definition smart_pointer.h:376
ConstSmartPtr(const ConstSmartPtr &sp)
Definition smart_pointer.h:304
ConstSmartPtr< T, FreePolicy > & operator=(const ConstSmartPtr< TIn, FreePolicy > &sp)
Definition smart_pointer.h:366
ConstSmartPtr & operator=(const ConstSmartPtr &sp)
Definition smart_pointer.h:355
const T & operator*() const
Definition smart_pointer.h:332
SmartPtr< T, FreePolicy > cast_const() const
performs a const cast
Definition smart_pointer.h:448
bool operator==(const ConstSmartPtr &sp) const
Definition smart_pointer.h:384
int * refcount_ptr() const
WARNING: this method is dangerous!
Definition smart_pointer.h:473
void release()
decrements the refCount and frees the encapsulated pointer if required.
Definition smart_pointer.h:477
bool operator!=(const SmartPtr< TPtr, FreePolicy > &sp) const
Definition smart_pointer.h:402
Definition smart_pointer.h:59
static void free(const T *data)
Definition smart_pointer.h:61
Definition smart_pointer.h:50
static void free(const T *data)
Definition smart_pointer.h:52
Definition smart_pointer.h:68
static void free(const T *data)
Definition smart_pointer.h:70
Used to construct empty smart pointers.
Definition smart_pointer.h:83
NullSmartPtr()
Definition smart_pointer.h:85
void release()
Definition smart_pointer.h:633
SmartPtr< void > & operator=(const SmartPtr< void > &sp)
Definition smart_pointer.h:562
void invalidate()
Definition smart_pointer.h:625
~SmartPtr()
Definition smart_pointer.h:560
SmartPtr(NullSmartPtr)
Definition smart_pointer.h:533
SmartPtr< void > & operator=(const SmartPtr< T > &sp)
Definition smart_pointer.h:575
int refcount() const
Definition smart_pointer.h:630
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition smart_pointer.h:623
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:610
SmartPtr(const SmartPtr< void > &sp)
Definition smart_pointer.h:535
SmartPtr(const SmartPtr< T > &sp)
Definition smart_pointer.h:552
SmartPtr< void > & operator=(NullSmartPtr)
Definition smart_pointer.h:588
SmartPtr< T, TFreePolicy > cast_reinterpret() const
Returns a SmartPtr with the specified type and shared reference counting.
Definition smart_pointer.h:601
SmartPtr(void *ptr, void(*freeFunc)(const void *))
Definition smart_pointer.h:543
SmartPtr()
Definition smart_pointer.h:531
void * get()
Definition smart_pointer.h:627
void * m_ptr
Definition smart_pointer.h:645
void element_type
Definition smart_pointer.h:530
bool valid() const
returns true if the pointer is valid, false if not.
Definition smart_pointer.h:617
const void * get() const
Definition smart_pointer.h:628
int * m_refCountPtr
Definition smart_pointer.h:646
Definition smart_pointer.h:107
SmartPtr & operator=(NullSmartPtr)
Definition smart_pointer.h:141
bool operator!=(NullSmartPtr) const
Definition smart_pointer.h:182
T * get()
returns encapsulated pointer
Definition smart_pointer.h:197
SmartPtr< TDest, FreePolicy > cast_reinterpret() const
performs a reinterpret cast
Definition smart_pointer.h:232
T * m_ptr
Definition smart_pointer.h:290
SmartPtr(NullSmartPtr)
Definition smart_pointer.h:116
T element_type
Definition smart_pointer.h:113
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
SmartPtr & operator=(const SmartPtr &sp)
Definition smart_pointer.h:149
bool operator==(const ConstSmartPtr< TPtr, FreePolicy > &sp) const
Definition smart_pointer.h:187
const T * operator->() const
Definition smart_pointer.h:136
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
T * get_nonconst() const
WARNING: this method is DANGEROUS!
Definition smart_pointer.h:265
int * refcount_ptr() const
WARNING: this method is DANGEROUS!
Definition smart_pointer.h:263
bool operator==(NullSmartPtr) const
Definition smart_pointer.h:178
SmartPtr< T, FreePolicy > & operator=(const SmartPtr< TIn, FreePolicy > &sp)
Definition smart_pointer.h:160
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:505
T * operator->()
Definition smart_pointer.h:135
const T * get() const
returns encapsulated pointer
Definition smart_pointer.h:200
T & operator*()
Definition smart_pointer.h:138
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< TDest, FreePolicy > cast_dynamic() const
preforms a dynamic cast
Definition smart_pointer.h:216
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
SmartPtr< TDest, FreePolicy > cast_static() const
performs a static cast
Definition smart_pointer.h:224
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
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition smart_pointer.h:89
if(!(yy_init))
Definition lexer.cpp:997
Definition smart_pointer.h:817
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:839
bool operator()(const SmartPtr< T, TFreePolicy > &lhs, const SmartPtr< T, TFreePolicy > &rhs) const
Definition smart_pointer.h:824