Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoAutoRef.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24#ifndef SO_AUTO_REF_COUNTER_H
25#define SO_AUTO_REF_COUNTER_H
26
27#include <Inventor/SbBase.h>
28#include <Inventor/misc/SoRefCounter.h>
29
46{
47public:
50 : m_pointer(nullptr)
51 {}
52
54 SoAutoRef(const SoAutoRef& that)
55 : m_pointer(that.m_pointer)
56 {
57 if (m_pointer)
58 m_pointer->ref();
59 }
60
63 : m_pointer(pIn)
64 {
65 if (m_pointer)
66 m_pointer->ref();
67 }
68
71 {
72 if (m_pointer)
73 m_pointer->unref();
74 }
75
78 {
79 (*this) = that.m_pointer;
80 return *this;
81 }
82
85 {
86 if (m_pointer != ptr)
87 {
88 if (m_pointer)
89 m_pointer->unref();
90 m_pointer = ptr;
91 if (m_pointer)
92 m_pointer->ref();
93 }
94 return *this;
95 }
96
97 // Comparison operators with other SoAutoRef
98
99 bool operator==(const SoAutoRef& other) const
100 {
101 return m_pointer == other.m_pointer;
102 }
103
104 bool operator!=(const SoAutoRef& other) const
105 {
106 return m_pointer != other.m_pointer;
107 }
108
109 bool operator<(const SoAutoRef& other) const
110 {
111 return m_pointer < other.m_pointer;
112 }
113
114 bool operator<=(const SoAutoRef& other) const
115 {
116 return m_pointer < other.m_pointer;
117 }
118
119 bool operator>(const SoAutoRef& other) const
120 {
121 return m_pointer > other.m_pointer;
122 }
123
124 bool operator>=(const SoAutoRef& other) const
125 {
126 return m_pointer > other.m_pointer;
127 }
128
129 // Comparison operators with SoRefCounter*
130
131 bool operator==(const SoRefCounter* ptr) const
132 {
133 return m_pointer == ptr;
134 }
135
136 bool operator!=(const SoRefCounter* ptr) const
137 {
138 return m_pointer != ptr;
139 }
140
141 bool operator<(const SoRefCounter* ptr) const
142 {
143 return m_pointer < ptr;
144 }
145
146 bool operator<=(const SoRefCounter* ptr) const
147 {
148 return m_pointer < ptr;
149 }
150
151 bool operator>(const SoRefCounter* ptr) const
152 {
153 return m_pointer > ptr;
154 }
155
156 bool operator>=(const SoRefCounter* ptr) const
157 {
158 return m_pointer > ptr;
159 }
160
162 operator bool() const
163 {
164 return get() != nullptr;
165 }
166
168 bool operator!() const
169 {
170 return get() == nullptr;
171 }
172
175 { return *(get()); }
176
179 { return get(); }
180
183 { return get(); }
184
185private:
186 SoRefCounter* get() const
187 { return m_pointer; }
188
190 SoRefCounter* m_pointer;
191};
192
193// Reverse comparison operators with SoRefCounter*
194static inline bool operator==(const SoRefCounter* ptr, const SoAutoRef& ref)
195{
196 return ptr == ref.ptr();
197}
198
199static inline bool operator!=(const SoRefCounter* ptr, const SoAutoRef& ref)
200{
201 return ptr != ref.ptr();
202}
203
204static inline bool operator<(const SoRefCounter* ptr, const SoAutoRef& ref)
205{
206 return ptr < ref.ptr();
207}
208
209static inline bool operator<=(const SoRefCounter* ptr, const SoAutoRef& ref)
210{
211 return ptr <= ref.ptr();
212}
213
214static inline bool operator>(const SoRefCounter* ptr, const SoAutoRef& ref)
215{
216 return ptr > ref.ptr();
217}
218
219static inline bool operator>=(const SoRefCounter* ptr, const SoAutoRef& ref)
220{
221 return ptr >= ref.ptr();
222}
223
224// Included here to provide this service by default everywhere SoRefCounter
225// is already used, avoiding app to add a #include <Inventor/misc/SoAutoRef.h>
226#include <Inventor/misc/SoRef.h>
227
228#endif // SO_AUTO_REF_COUNTER_H
229
230
Implements smart pointers to SoRefCounter objects.
Definition SoAutoRef.h:46
SoRefCounter * operator->() const
Cast to C pointer.
Definition SoAutoRef.h:178
bool operator<(const SoAutoRef &other) const
Definition SoAutoRef.h:109
bool operator!=(const SoRefCounter *ptr) const
Definition SoAutoRef.h:136
bool operator==(const SoRefCounter *ptr) const
Definition SoAutoRef.h:131
bool operator<=(const SoAutoRef &other) const
Definition SoAutoRef.h:114
bool operator!() const
NOT operator.
Definition SoAutoRef.h:168
bool operator<=(const SoRefCounter *ptr) const
Definition SoAutoRef.h:146
SoAutoRef & operator=(const SoAutoRef &that)
Assign another SoAutoRef.
Definition SoAutoRef.h:77
bool operator!=(const SoAutoRef &other) const
Definition SoAutoRef.h:104
SoRefCounter * ptr() const
Cast to C pointer.
Definition SoAutoRef.h:182
bool operator==(const SoAutoRef &other) const
Definition SoAutoRef.h:99
SoAutoRef()
Default constructor.
Definition SoAutoRef.h:49
bool operator<(const SoRefCounter *ptr) const
Definition SoAutoRef.h:141
bool operator>(const SoAutoRef &other) const
Definition SoAutoRef.h:119
bool operator>=(const SoAutoRef &other) const
Definition SoAutoRef.h:124
SoAutoRef(SoRefCounter *pIn)
Construct from C++ pointer.
Definition SoAutoRef.h:62
SoAutoRef & operator=(SoRefCounter *ptr)
Assign ordinary C pointer.
Definition SoAutoRef.h:84
bool operator>=(const SoRefCounter *ptr) const
Definition SoAutoRef.h:156
SoAutoRef(const SoAutoRef &that)
Copy constructor.
Definition SoAutoRef.h:54
~SoAutoRef()
Destructor.
Definition SoAutoRef.h:70
bool operator>(const SoRefCounter *ptr) const
Definition SoAutoRef.h:151
SoRefCounter & operator*() const
Dereference pointer.
Definition SoAutoRef.h:174
Base class for ref-counted objects.
void unref() const
Removes a reference from an instance.
void ref() const
Adds a reference to an instance.