1 #ifndef SimTK_PRIVATE_IMPLEMENTATION_H_ 2 #define SimTK_PRIVATE_IMPLEMENTATION_H_ 105 template <
class HANDLE,
class IMPL,
bool PTR=false>
137 void disown(HANDLE& newOwner);
234 const HANDLE& downcastToHandle()
const {
return static_cast<const HANDLE&
>(*this);}
235 HANDLE& updDowncastToHandle() {
return static_cast<HANDLE&
>(*this);}
264 template <
class HANDLE,
class IMPL>
267 mutable int handleCount;
277 int getHandleCount()
const;
281 void incrementHandleCount()
const;
286 int decrementHandleCount()
const;
312 void setOwnerHandle(HANDLE& p);
317 int removeOwnerHandle();
322 void replaceOwnerHandle(HANDLE& p);
326 bool hasOwnerHandle()
const;
335 const HANDLE& getOwnerHandle()
const;
338 template <
class H,
class IMPL,
bool PTR>
339 std::ostream& operator<<(std::ostream& o, const PIMPLHandle<H,IMPL,PTR>& h);
343 #define SimTK_INSERT_DERIVED_HANDLE_DECLARATIONS(DERIVED, DERIVED_IMPL, PARENT) \ 344 const DERIVED_IMPL& getImpl() const;\ 345 DERIVED_IMPL& updImpl();\ 346 const PARENT& upcast() const;\ 347 PARENT& updUpcast();\ 348 static bool isInstanceOf(const PARENT& p);\ 349 static const DERIVED& downcast(const PARENT& p);\ 350 static DERIVED& updDowncast(PARENT& p); 354 #define SimTK_INSERT_DERIVED_HANDLE_DEFINITIONS(DERIVED, DERIVED_IMPL, PARENT) \ 355 const DERIVED_IMPL& DERIVED::getImpl() const {\ 356 return SimTK_DYNAMIC_CAST_DEBUG<const DERIVED_IMPL&>(PARENT::getImpl());\ 358 DERIVED_IMPL& DERIVED::updImpl() {\ 359 return SimTK_DYNAMIC_CAST_DEBUG<DERIVED_IMPL&>(PARENT::updImpl());\ 361 const PARENT& DERIVED::upcast() const {\ 362 return static_cast<const PARENT&>(*this);\ 364 PARENT& DERIVED::updUpcast() {\ 365 return static_cast<PARENT&>(*this);\ 367 bool DERIVED::isInstanceOf(const PARENT& p) {\ 368 return dynamic_cast<const DERIVED_IMPL*>(&p.getImpl()) != 0;\ 370 const DERIVED& DERIVED::downcast(const PARENT& p) {\ 371 assert(isInstanceOf(p));\ 372 return static_cast<const DERIVED&>(p);\ 374 DERIVED& DERIVED::updDowncast(PARENT& p) {\ 375 assert(isInstanceOf(p));\ 376 return static_cast<DERIVED&>(p);\ 381 #endif // SimTK_PRIVATE_IMPLEMENTATION_H_ const IMPL & getImpl() const
Get a const reference to the implementation associated with this Handle.
Definition: PrivateImplementation.h:173
void clearHandle()
Make this an empty handle, deleting the implementation object if this handle is the owner of it...
Definition: PrivateImplementation_Defs.h:238
void setImpl(IMPL *p)
Set the implementation for this empty handle.
Definition: PrivateImplementation_Defs.h:226
bool isSameHandle(const HANDLE &other) const
Determine whether the supplied handle is the same object as "this" PIMPLHandle.
Definition: PrivateImplementation_Defs.h:164
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
PIMPLHandle()
The default constructor makes this an empty handle.
Definition: PrivateImplementation.h:187
This class provides some infrastructure useful in making SimTK Private Implementation (PIMPL) classes...
Definition: PrivateImplementation.h:106
HandleBase ParentHandle
Definition: PrivateImplementation.h:116
void disown(HANDLE &newOwner)
Give up ownership of the implementation to an empty handle.
Definition: PrivateImplementation_Defs.h:178
bool hasSameImplementation(const HANDLE &other) const
Determine whether the supplied handle is a reference to the same implementation object as is referenc...
Definition: PrivateImplementation_Defs.h:170
This class provides some infrastructure useful in creating PIMPL Implementation classes (the ones ref...
Definition: PrivateImplementation.h:265
This file contains macros which are convenient to use for sprinkling error checking around liberally ...
int getImplHandleCount() const
Return the number of handles the implementation believes are referencing it.
Definition: PrivateImplementation_Defs.h:250
bool isEmptyHandle() const
Returns true if this handle is empty, that is, does not refer to any implementation object...
Definition: PrivateImplementation.h:120
~PIMPLHandle()
Note that the destructor is non-virtual.
Definition: PrivateImplementation_Defs.h:136
PIMPLHandle< HANDLE, IMPL, PTR > HandleBase
Definition: PrivateImplementation.h:115
bool isOwnerHandle() const
Returns true if this handle is the owner of the implementation object to which it refers...
Definition: PrivateImplementation_Defs.h:158
PIMPLHandle & operator=(const PIMPLHandle &source)
Copy assignment makes the current handle either a deep (value) or shallow (reference) copy of the sup...
Definition: PrivateImplementation_Defs.h:151
IMPL & updImpl()
Get a writable reference to the implementation associated with this Handle.
Definition: PrivateImplementation.h:178
Mandatory first inclusion for any Simbody source or header file.
PIMPLHandle & copyAssign(const HANDLE &source)
This is real copy assignment, with ordinary C++ object ("value") semantics.
Definition: PrivateImplementation_Defs.h:210
PIMPLHandle & referenceAssign(const HANDLE &source)
"Copy" assignment but with shallow (pointer) semantics.
Definition: PrivateImplementation_Defs.h:193