Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SbPImpl.h
Go to the documentation of this file.
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-2017 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20
21#ifndef HIDDEN_FROM_DOC
22
23#ifndef _SB_PIMPL_MACRO_H_
24#define _SB_PIMPL_MACRO_H_
25
26
27// Define supported C++ level for PIMPL design, not that
28// C++ 11 is fully supported if __cplusplus >= 201103L.
29// This value defines the way we store the implementation class:
30// "0", using SoRef
31// "1", using std::auto_ptr
32// "2", using std::unique_ptr (c++ 11 should be at least partially supported)
33#define OIV_PIMPL_CXX11 0
34
35#if !(OIV_PIMPL_CXX11)
37#else
38#include <memory>
39#endif
40
148namespace inventor
149{
150namespace impl
151{
152
156template<typename PublicType>
157#if !(OIV_PIMPL_CXX11)
158class SbPImpl : public SoRefCounter
159#else
160class SbPImpl
161#endif
162{
163public:
164
168 SbPImpl( PublicType* p ) : m_public(p) {}
169
173 virtual ~SbPImpl() {}
174
178 template<typename SuperPublicType>
179 SuperPublicType* getPublic () const { return static_cast<SuperPublicType*>(m_public); }
180
181private:
182
183 // public node
184 PublicType* m_public;
185
186private:
187
188 // force using constructor with parameter
189 SbPImpl () {}
190};
191
192} // namespace impl
193} // namespace inventor
194
197#define SO_PIMPL_PUBLIC_DECLARATION(Class) \
198namespace inventor\
199{\
200namespace impl\
201{\
202class Class##Impl;\
203}\
204}
205
208#define SO_PIMPL_BASE_PUBLIC_DECLARATION(Class) SO_PIMPL_PUBLIC_DECLARATION(Class)
209
212#define SO_PIMPL_PUBLIC_HEADER(Class) \
213SoINTERNAL private:\
214 friend class inventor::impl::Class##Impl;\
215
216 Class(inventor::impl::Class##Impl *impl);
217
223#define SO_PIMPL_ABSTRACT_PUBLIC_HEADER(Class, ParentClass) \
224SoINTERNAL private:\
225
226 Class(inventor::impl::ParentClass##Impl *impl);
227
231#define SO_PIMPL_FINAL_PUBLIC_HEADER(Class) \
232SoINTERNAL private:\
233 friend class inventor::impl::Class##Impl;
234
238#if OIV_PIMPL_CXX11 == 0
239#define SO_PIMPL_BASE_PUBLIC_HEADER(Class) \
240SO_PIMPL_PUBLIC_HEADER(Class) \
241 SoRef< inventor::impl::SbPImpl< Class > > m_impl; \
242
243 template<typename ImplType> \
244 ImplType* getImpl() const { \
245 assert(m_impl->getPublic< Class >() == this); \
246 return static_cast< ImplType *>(m_impl.ptr()); \
247 } \
248
249 void setImpl( inventor::impl::SbPImpl< Class >* impl ) { m_impl = impl; }
250#elif OIV_PIMPL_CXX11 == 1
251#define SO_PIMPL_BASE_PUBLIC_HEADER(Class) \
252SO_PIMPL_PUBLIC_HEADER(Class) \
253 std::auto_ptr< inventor::impl::SbPImpl< Class > > m_impl; \
254
255 template<typename ImplType> \
256 ImplType* getImpl() const { \
257 assert(m_impl->getPublic< Class >() == this); \
258 return static_cast< ImplType *>(m_impl.ptr()); \
259 } \
260
261 void setImpl ( inventor::impl::SbPImpl< Class >* impl ) { m_impl.reset(impl); }
262#else
263#define SO_PIMPL_BASE_PUBLIC_HEADER(Class) \
264SO_PIMPL_PUBLIC_HEADER(Class);\
265 std::unique_ptr< inventor::impl::SbPImpl< Class > > m_impl; \
266
267 template<typename ImplType> \
268 ImplType* getImpl() const { \
269 assert(m_impl->getPublic< Class >() == this); \
270 return static_cast< ImplType *>(m_impl.ptr()); \
271 } \
272
273 void setImpl( inventor::impl::SbPImpl< Class >* impl ) { m_impl.reset( impl ); }
274#endif
275
276#endif //_SB_PIMPL_MACRO_H_
277
278#endif // HIDDEN_FROM_DOC
Base class for ref-counted objects.