Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoRef.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_REF_H
25#define SO_REF_H
26
27#include <Inventor/misc/SoAutoRef.h>
28
88template <typename T>
89class SoRef : public SoAutoRef
90{
91public:
94 {};
95
97 SoRef(const SoRef<T>& that)
98 :SoAutoRef(that)
99 {
100 }
101
103 SoRef(T* pIn)
104 :SoAutoRef(dynamic_cast<T*>(pIn))
105 {
106 }
107
109 template<typename Y>
110 SoRef(const SoRef<Y>& that)
111 {
112 m_pointer = that.ptr();
113 if (m_pointer)
114 m_pointer->ref();
115 }
116
118 inline T* releaseNoDelete()
119 {
120 T* p = dynamic_cast<T*>(m_pointer);
121 if (m_pointer)
122 {
123 m_pointer->unrefNoDelete();
124 m_pointer = NULL;
125 }
126 return p;
127 }
128
129
132 {
133 (*this) = (T*)(that.m_pointer);
134 return *this;
135 }
136
138 template<typename Y>
140 {
141 (*this) = dynamic_cast<T*>(that.ptr());
142 return *this;
143 }
144
147 {
148 if (m_pointer != ptr) {
149 if (m_pointer)
150 m_pointer->unref();
151 m_pointer = ptr;
152 if (m_pointer)
153 m_pointer->ref();
154 }
155 return *this;
156 }
157
159 T& operator*() const
160 { return *((T*)m_pointer); }
161
163 T* operator->() const
164 { return ((T*)(m_pointer)); }
165
167 T* ptr() const
168 { return ((T*)(m_pointer)); }
169
170};
171
172#endif // SO_REF_H
173
174
Implements smart pointers to SoRefCounter objects.
Definition SoAutoRef.h:46
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
SoRef(T *pIn)
Construct from C++ pointer.
Definition SoRef.h:103
SoRef(const SoRef< Y > &that)
Construct from another SoRef.
Definition SoRef.h:110
T & operator*() const
Dereference pointer.
Definition SoRef.h:159
T * operator->() const
Cast to C pointer.
Definition SoRef.h:163
SoRef< T > & operator=(const SoRef< Y > &that)
Assign to another SoRef if the types are assignable (from derived to base classes).
Definition SoRef.h:139
SoRef< T > & operator=(T *ptr)
Assign ordinary C pointer.
Definition SoRef.h:146
SoRef(const SoRef< T > &that)
Copy constructor.
Definition SoRef.h:97
T * releaseNoDelete()
Release reference and return the object stored.
Definition SoRef.h:118
SoRef< T > & operator=(const SoRef< T > &that)
Assign another SoRef.
Definition SoRef.h:131
SoRef()
Default constructor.
Definition SoRef.h:93
T * ptr() const
Cast to C pointer.
Definition SoRef.h:167