00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef HIDDEN_FROM_DOC
00022
00023 #ifndef _SB_PIMPL_MACRO_H_
00024 #define _SB_PIMPL_MACRO_H_
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define OIV_PIMPL_CXX11 0
00034
00035 #if !(OIV_PIMPL_CXX11)
00036 #include <Inventor/misc/SoRefCounter.h>
00037 #else
00038 #include <memory>
00039 #endif
00040
00106 template<typename PublicType>
00107 #if !(OIV_PIMPL_CXX11)
00108 class SbPImpl : public SoRefCounter
00109 #else
00110 class SbPImpl
00111 #endif
00112 {
00113 public:
00114
00118 SbPImpl( PublicType* p ) : m_public(p) {}
00119
00123 virtual ~SbPImpl() {}
00124
00128 template<typename SuperPublicType>
00129 SuperPublicType* getPublic () const { return static_cast<SuperPublicType*>(m_public); }
00130
00131 private:
00132
00133
00134 PublicType* m_public;
00135
00136 private:
00137
00138
00139 SbPImpl () {}
00140 };
00141
00142
00145 #define SO_PIMPL_PUBLIC_DECLARATION(Class) \
00146 class Class##Impl;
00147
00150 #define SO_PIMPL_BASE_PUBLIC_DECLARATION(Class) SO_PIMPL_PUBLIC_DECLARATION(Class)
00151
00154 #define SO_PIMPL_PUBLIC_HEADER(Class) \
00155 SoINTERNAL private:\
00156 friend class Class##Impl;\
00157
00158 Class(Class##Impl *impl);
00159
00163 #if OIV_PIMPL_CXX11 == 0
00164 #define SO_PIMPL_BASE_PUBLIC_HEADER(Class) \
00165 SO_PIMPL_PUBLIC_HEADER(Class) \
00166 SoRef< SbPImpl< Class > > m_impl; \
00167
00168 template<typename ImplType> \
00169 ImplType* getImpl() const { \
00170 assert(m_impl->getPublic< Class >() == this); \
00171 return static_cast< ImplType *>(m_impl.ptr()); \
00172 } \
00173
00174 void setImpl( SbPImpl< Class >* impl ) { m_impl = impl; }
00175 #elif OIV_PIMPL_CXX11 == 1
00176 #define SO_PIMPL_BASE_PUBLIC_HEADER(Class) \
00177 SO_PIMPL_PUBLIC_HEADER(Class) \
00178 std::auto_ptr< SbPImpl< Class > > m_impl; \
00179
00180 template<typename ImplType> \
00181 ImplType* getImpl() const { \
00182 assert(m_impl->getPublic< Class >() == this); \
00183 return static_cast< ImplType *>(m_impl.ptr()); \
00184 } \
00185
00186 void setImpl ( SbPImpl< Class >* impl ) { m_impl.reset(impl); }
00187 #else
00188 #define SO_PIMPL_BASE_PUBLIC_HEADER(Class) \
00189 SO_PIMPL_PUBLIC_HEADER(Class);\
00190 std::unique_ptr< SbPImpl< Class > > m_impl; \
00191
00192 template<typename ImplType> \
00193 ImplType* getImpl() const { \
00194 assert(m_impl->getPublic< Class >() == this); \
00195 return static_cast< ImplType *>(m_impl.ptr()); \
00196 } \
00197
00198 void setImpl( SbPImpl< Class >* impl ) { m_impl.reset( impl ); }
00199 #endif
00200
00201 #endif //_SB_PIMPL_MACRO_H_
00202
00203 #endif // HIDDEN_FROM_DOC
00204