Simbody
3.5
|
Wrap a pointer to an abstract base class in a way that makes it behave like a concrete class. More...
Public Types | |
typedef T | element_type |
typedef T * | pointer |
typedef T & | reference |
Public Member Functions | |
ClonePtr () | |
Default constructor creates an empty object. More... | |
ClonePtr (T *obj) | |
Given a pointer to a writable heap-allocated object, take over ownership of that object. More... | |
ClonePtr (T **obj) | |
Given a pointer to a writable heap-allocated object, take over ownership of that object and set the original pointer to null. More... | |
ClonePtr (const T *obj) | |
Given a pointer to a read-only object, create a new heap-allocated copy of that object via its clone() method and make this ClonePtr object the owner of the copy. More... | |
ClonePtr (const T &obj) | |
Given a read-only reference to an object, create a new heap-allocated copy of that object via its clone() method and make this ClonePtr object the owner of the copy. More... | |
ClonePtr (const ClonePtr &c) | |
Copy constructor is deep; the new ClonePtr object contains a new copy of the object in the source, created via the source object's clone() method. More... | |
ClonePtr & | operator= (const ClonePtr &c) |
Copy assignment replaces the currently-held object by a heap-allocated copy of the object held in the source container. More... | |
ClonePtr & | operator= (const T &t) |
This form of assignment replaces the currently-held object by a heap-allocated copy of the source object. More... | |
ClonePtr & | operator= (T *tp) |
This form of assignment replaces the currently-held object by the given source object and takes over ownership of the source object. More... | |
~ClonePtr () | |
Destructor deletes the referenced object. More... | |
bool | operator== (const ClonePtr &other) const |
Compare the contained objects for equality using the contained objects' operator==() operator. More... | |
bool | operator!= (const ClonePtr &other) const |
Compare the contained objects for inequality using operator==(). More... | |
bool | operator< (const ClonePtr &other) const |
Provide an ordering for use in sorted containers using the contained objects' operator<(). More... | |
const T * | operator-> () const |
Dereference a const pointer to the contained object. More... | |
T * | operator-> () |
Dereference a writable pointer to the contained object. More... | |
const T & | operator* () const |
This "dereference" operator returns a const reference to the contained object. More... | |
T & | operator* () |
This "dereference" operator returns a writable reference to the contained object. More... | |
const T * | operator& () const |
This "address of" operator returns a const pointer to the contained object (or null if none). More... | |
T * | operator& () |
This "address of" operator returns a writable pointer to the contained object (or null if none). More... | |
operator const T & () const | |
This is an implicit conversion from ClonePtr<T> to a const reference to the contained object. More... | |
operator T & () | |
This is an implicit conversion from ClonePtr<T> to a writable reference to the contained object. More... | |
operator bool () const | |
This is an implicit conversion to type bool that returns true if the container is non-null (that is, not empty). More... | |
T * | updPtr () |
Return a writable pointer to the contained object if any, or null. More... | |
const T * | getPtr () const |
Return a const pointer to the contained object if any, or null. More... | |
T & | updRef () |
Return a writable reference to the contained object. More... | |
const T & | getRef () const |
Return a const reference to the contained object. More... | |
bool | empty () const |
Return true if this container is empty. More... | |
void | clear () |
Make this container empty, deleting the currently contained object if there is one. More... | |
T * | release () |
Extract the object from this container, leaving the container empty and transferring ownership to the caller. More... | |
void | reset (T *tp) |
Replace the contents of this container with the supplied heap-allocated object, taking over ownership of that object and deleting the current one first if necessary. More... | |
void | reset (T **tpp) |
Replace the contents of this container with the supplied heap-allocated object, taking over ownership of that object, deleting the current one first if necessary, and setting the caller's supplied pointer to null. More... | |
void | swap (ClonePtr &other) |
Swap the contents of this ClonePtr with another one, with ownership changing hands but no copying performed. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
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 of the ClonePtr class. More... | |
Wrap a pointer to an abstract base class in a way that makes it behave like a concrete class.
This is similar to std::unique_ptr in that it does not permit shared ownership of the object. However, unlike std::unique_ptr, ClonePtr supports copy and assigment operations, by insisting that the contained object have a clone() method that returns a pointer to a heap-allocated deep copy of the concrete object.
We define operator==() and operator<() here that delegate to the contained object; if you want to use those the contained type must support that operator.
This class is entirely inline and has no computational or space overhead; it contains just a single pointer and does no reference counting.
typedef T SimTK::ClonePtr< T >::element_type |
typedef T* SimTK::ClonePtr< T >::pointer |
typedef T& SimTK::ClonePtr< T >::reference |
|
inline |
Default constructor creates an empty object.
|
inlineexplicit |
Given a pointer to a writable heap-allocated object, take over ownership of that object.
|
inlineexplicit |
Given a pointer to a writable heap-allocated object, take over ownership of that object and set the original pointer to null.
|
inlineexplicit |
Given a pointer to a read-only object, create a new heap-allocated copy of that object via its clone() method and make this ClonePtr object the owner of the copy.
Ownership of the original object is not affected. If the supplied pointer is null, the resulting ClonePtr object is empty.
|
inlineexplicit |
Given a read-only reference to an object, create a new heap-allocated copy of that object via its clone() method and make this ClonePtr object the owner of the copy.
Ownership of the original object is not affected.
|
inline |
Copy constructor is deep; the new ClonePtr object contains a new copy of the object in the source, created via the source object's clone() method.
If the source container is empty this one will be empty also.
|
inline |
Destructor deletes the referenced object.
|
inline |
Copy assignment replaces the currently-held object by a heap-allocated copy of the object held in the source container.
The copy is created using the source object's clone() method. The currently-held object is deleted. If the source container is empty this one will be empty after the assignment.
|
inline |
This form of assignment replaces the currently-held object by a heap-allocated copy of the source object.
The copy is created using the source object's clone() method. The currently-held object is deleted.
|
inline |
This form of assignment replaces the currently-held object by the given source object and takes over ownership of the source object.
The currently-held object is deleted.
|
inline |
Compare the contained objects for equality using the contained objects' operator==() operator.
If both containers are empty or both refer to the same object they will test equal; if only one is empty they will test not equal. Otherwise the objects are compared.
|
inline |
Compare the contained objects for inequality using operator==().
|
inline |
Provide an ordering for use in sorted containers using the contained objects' operator<().
If both containers are empty or both refer to the same object they will test equal; if only one is empty that one is considered less than the other one. Otherwise the objects are compared using T::operator<().
|
inline |
Dereference a const pointer to the contained object.
This will fail if the container is empty.
|
inline |
Dereference a writable pointer to the contained object.
This will fail if the container is empty.
|
inline |
This "dereference" operator returns a const reference to the contained object.
This will fail if the container is empty.
|
inline |
This "dereference" operator returns a writable reference to the contained object.
This will fail if the container is empty.
|
inline |
This "address of" operator returns a const pointer to the contained object (or null if none).
|
inline |
This "address of" operator returns a writable pointer to the contained object (or null if none).
|
inline |
This is an implicit conversion from ClonePtr<T> to a const reference to the contained object.
This will fail if the container is empty.
|
inline |
This is an implicit conversion from ClonePtr<T> to a writable reference to the contained object.
|
inline |
This is an implicit conversion to type bool that returns true if the container is non-null (that is, not empty).
|
inline |
Return a writable pointer to the contained object if any, or null.
You can use the "address of" operator&() instead if you prefer.
|
inline |
Return a const pointer to the contained object if any, or null.
You can use the "address of" operator&() instead if you prefer.
|
inline |
Return a writable reference to the contained object.
Don't call this if this container is empty. There is also an implicit conversion to reference that allows ClonePtr<T> to be used as though it were a T&.
|
inline |
Return a const reference to the contained object.
Don't call this if this container is empty. There is also an implicit conversion to reference that allows ClonePtr<T> to be used as though it were a T&.
|
inline |
Return true if this container is empty.
|
inline |
Make this container empty, deleting the currently contained object if there is one.
|
inline |
Extract the object from this container, leaving the container empty and transferring ownership to the caller.
A pointer to the object is returned. No destruction occurs.
|
inline |
Replace the contents of this container with the supplied heap-allocated object, taking over ownership of that object and deleting the current one first if necessary.
Nothing happens if the supplied pointer is the same as the one already stored.
|
inline |
Replace the contents of this container with the supplied heap-allocated object, taking over ownership of that object, deleting the current one first if necessary, and setting the caller's supplied pointer to null.
If the supplied pointer is the same as the one we're already storing, then we just set the caller's pointer to null and return.
|
inline |
Swap the contents of this ClonePtr with another one, with ownership changing hands but no copying performed.
|
related |