cartobase 6.0.6
rcptrtrick.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34
35#ifndef CARTOBASE_SMART_RCPTRTRICK_H
36#define CARTOBASE_SMART_RCPTRTRICK_H
37
40
41namespace carto
42{
43
50 {
51 public:
55 template <typename T>
56 static void releaseOwnership( rc_ptr<T> & );
57 static void releaseOwnership( RCObject & );
59 template <typename T>
60 static void restoreOwnership( rc_ptr<T> & );
61 static void restoreOwnership( RCObject & );
63 template <typename T>
65 template <typename T>
68 template <typename T>
71 };
72
73
74 template <typename T> inline
76 {
77 if( x._pcount && *x._pcount > 0 )
78 ++(*x._pcount);
79 }
80
81
83 {
84 if( x._refCounter > 0 )
85 ++x._refCounter;
86 }
87
88
89 template <typename T> inline
91 {
92 if( x._pcount && *x._pcount > 0 )
93 --(*x._pcount);
94 }
95
96
98 {
99 if( x._refCounter > 0 )
100 --x._refCounter;
101 }
102
103
104 template <typename T> inline
106 {
107 return x->_refCounter;
108 }
109
110
111 template <typename T> inline
113 {
114 return *x._pcount;
115 }
116
117
119 {
120 return x._refCounter;
121 }
122
123
124 template <typename T> inline
127 {
128 return x->weak_count;
129 }
130
131
134 {
135 return x.weak_count;
136 }
137
138}
139
140#endif
141
Base class for reference counted objects (intrusive)
Definition rcptr.h:110
int RefCounterType
Definition rcptr.h:127
SharedObject allows to work with combined reference counting pointers and weak (Observer) pointers.
Definition sharedptr.h:48
rc_ptr_trick merely makes a public access to the reference counter inside a rc_ptr.
Definition rcptrtrick.h:50
static RCObject::RefCounterType & refCount(shared_ptr< T > &)
allows complete read-write access to the counter
Definition rcptrtrick.h:105
static void releaseOwnership(rc_ptr< T > &)
just increments the ref-counter of the underlying rc_ptr so that the rc_ptr will never delete the obj...
Definition rcptrtrick.h:75
static void restoreOwnership(rc_ptr< T > &)
decrements the ref-counter
Definition rcptrtrick.h:90
static RCObject::RefCounterType & weakCount(weak_shared_ptr< T > &)
Definition rcptrtrick.h:126
Reference-counting pointer.
Definition rcptr.h:640
A multi-purpose general smart pointer, which can act as either a rc_ptr, a weak_ptr or a weak_shared_...
Definition sharedptr.h:153
weak_shared_ptr: increments a reference count, is told and becomes null whenever the shared object is...
Definition sharedptr.h:95