1 #ifndef SimTK_SimTKCOMMON_CLONE_PTR_H_
2 #define SimTK_SimTKCOMMON_CLONE_PTR_H_
57 explicit ClonePtr(T** obj) : p(*obj) { *obj=0; }
63 explicit ClonePtr(
const T* obj) : p(obj?obj->clone():0) { }
68 explicit ClonePtr(
const T& obj) : p(&obj?obj.clone():0) { }
79 {
reset(c.p?c.p->clone():0);
return *
this; }
84 {
reset(&t ? t.clone() :0);
return *
this; }
89 {
reset(tp);
return *
this; }
99 if (p == other.p)
return true;
112 if (p == other.p)
return false;
113 if (
empty())
return true;
114 if (other.
empty())
return false;
142 operator const T&()
const {
return getRef(); }
149 operator bool()
const {
return !
empty(); }
163 "An attempt was made to dereference a null pointer.");
171 "An attempt was made to dereference a null pointer.");
188 void reset(T* tp) {
if (tp!=p) {
delete p; p=tp;} }
195 if (*tpp!=p) {
delete p; p=*tpp;}
218 template <
class T>
inline void
225 #endif // SimTK_SimTKCOMMON_CLONE_PTR_H_
T * operator&()
This "address of" operator returns a writable pointer to the contained object (or null if none)...
Definition: ClonePtr.h:137
ClonePtr & operator=(T *tp)
This form of assignment replaces the currently-held object by the given source object and takes over ...
Definition: ClonePtr.h:88
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
ClonePtr()
Default constructor creates an empty object.
Definition: ClonePtr.h:51
ClonePtr(const T *obj)
Given a pointer to a read-only object, create a new heap-allocated copy of that object via its clone(...
Definition: ClonePtr.h:63
T * release()
Extract the object from this container, leaving the container empty and transferring ownership to the...
Definition: ClonePtr.h:183
bool operator==(const ClonePtr &other) const
Compare the contained objects for equality using the contained objects' operator==() operator...
Definition: ClonePtr.h:98
bool operator!=(const ClonePtr &other) const
Compare the contained objects for inequality using operator==().
Definition: ClonePtr.h:104
const T * getPtr() const
Return a const pointer to the contained object if any, or null.
Definition: ClonePtr.h:156
T & updRef()
Return a writable reference to the contained object.
Definition: ClonePtr.h:161
ClonePtr(T *obj)
Given a pointer to a writable heap-allocated object, take over ownership of that object.
Definition: ClonePtr.h:54
ClonePtr(const T &obj)
Given a read-only reference to an object, create a new heap-allocated copy of that object via its clo...
Definition: ClonePtr.h:68
void reset(T *tp)
Replace the contents of this container with the supplied heap-allocated object, taking over ownership...
Definition: ClonePtr.h:188
T element_type
Definition: ClonePtr.h:46
const T * operator&() const
This "address of" operator returns a const pointer to the contained object (or null if none)...
Definition: ClonePtr.h:134
Wrap a pointer to an abstract base class in a way that makes it behave like a concrete class...
Definition: ClonePtr.h:44
T & operator*()
This "dereference" operator returns a writable reference to the contained object. ...
Definition: ClonePtr.h:130
const T & operator*() const
This "dereference" operator returns a const reference to the contained object.
Definition: ClonePtr.h:127
~ClonePtr()
Destructor deletes the referenced object.
Definition: ClonePtr.h:92
const T & getRef() const
Return a const reference to the contained object.
Definition: ClonePtr.h:169
#define SimTK_ERRCHK(cond, whereChecked, msg)
Definition: ExceptionMacros.h:324
ClonePtr & operator=(const ClonePtr &c)
Copy assignment replaces the currently-held object by a heap-allocated copy of the object held in the...
Definition: ClonePtr.h:78
ClonePtr(const ClonePtr &c)
Copy constructor is deep; the new ClonePtr object contains a new copy of the object in the source...
Definition: ClonePtr.h:72
ClonePtr & operator=(const T &t)
This form of assignment replaces the currently-held object by a heap-allocated copy of the source obj...
Definition: ClonePtr.h:83
bool operator<(const ClonePtr &other) const
Provide an ordering for use in sorted containers using the contained objects' operator<().
Definition: ClonePtr.h:111
T * operator->()
Dereference a writable pointer to the contained object.
Definition: ClonePtr.h:123
void swap(ClonePtr &other)
Swap the contents of this ClonePtr with another one, with ownership changing hands but no copying per...
Definition: ClonePtr.h:200
T * pointer
Definition: ClonePtr.h:47
void clear()
Make this container empty, deleting the currently contained object if there is one.
Definition: ClonePtr.h:179
bool empty() const
Return true if this container is empty.
Definition: ClonePtr.h:176
T * updPtr()
Return a writable pointer to the contained object if any, or null.
Definition: ClonePtr.h:153
T & reference
Definition: ClonePtr.h:48
ClonePtr(T **obj)
Given a pointer to a writable heap-allocated object, take over ownership of that object and set the o...
Definition: ClonePtr.h:57
void reset(T **tpp)
Replace the contents of this container with the supplied heap-allocated object, taking over ownership...
Definition: ClonePtr.h:194
void swap(SimTK::ClonePtr< T > &p1, SimTK::ClonePtr< T > &p2)
This is a specialization of the STL std::swap() algorithm which uses the cheap built-in swap() member...
Definition: ClonePtr.h:219
const T * operator->() const
Dereference a const pointer to the contained object.
Definition: ClonePtr.h:120