1 #ifndef SimTK_SimTKCOMMON_REFERENCE_PTR_H_ 2 #define SimTK_SimTKCOMMON_REFERENCE_PTR_H_ 96 { assert(mustBeZero==0); }
105 {
if (&src !=
this)
reset();
return *
this; }
118 {
reset(&t);
return *
this; }
123 {
reset(tp);
return *
this; }
135 T*
get()
const noexcept {
return p;}
141 "An attempt was made to dereference a null pointer.");
160 void reset(T* tp=
nullptr) noexcept {p=tp;}
165 std::swap(p, other.p);
169 bool empty() const noexcept {
return !p;}
173 explicit operator bool() const noexcept {
return !
empty();}
189 DEPRECATED_14(
"use get() rather than implicit conversion to T*")
190 operator T*() const noexcept {
return p;}
211 template <
class T>
inline void 219 template <
class charT,
class traits,
class T>
220 inline std::basic_ostream<charT,traits>&
221 operator<<(std::basic_ostream<charT,traits>& os,
223 { os << p.
get();
return os; }
230 template <
class T,
class U>
233 {
return lhs.
get() == rhs.
get(); }
239 {
return lhs.
empty(); }
245 {
return rhs.
empty(); }
253 template <
class T,
class U>
254 inline bool operator<(const ReferencePtr<T>& lhs,
256 {
return lhs.
get() < rhs.get(); }
263 inline bool operator<(const ReferencePtr<T>& lhs, std::nullptr_t)
271 inline bool operator<(std::nullptr_t, const ReferencePtr<T>& rhs)
272 {
return !rhs.empty(); }
279 template <
class T,
class U>
282 {
return !(lhs==rhs); }
288 {
return !(lhs==
nullptr); }
294 {
return !(
nullptr==rhs); }
298 template <
class T,
class U>
301 {
return rhs < lhs; }
306 {
return nullptr < lhs; }
312 {
return rhs <
nullptr; }
317 template <
class T,
class U>
320 {
return !(lhs < rhs); }
325 {
return !(lhs <
nullptr); }
331 {
return !(
nullptr < rhs); }
337 template <
class T,
class U>
338 inline bool operator<=(const ReferencePtr<T>& lhs,
340 {
return !(rhs < lhs); }
345 inline bool operator<=(const ReferencePtr<T>& lhs, std::nullptr_t)
346 {
return !(
nullptr < lhs); }
351 inline bool operator<=(std::nullptr_t, const ReferencePtr<T>& rhs)
352 {
return !(rhs <
nullptr); }
360 { assert(mustBeZero==0);
return !(lhs==
nullptr); }
364 #endif // SimTK_SimTKCOMMON_REFERENCE_PTR_H_ bool operator>=(const ReferencePtr< T > &lhs, std::nullptr_t)
nullptr greater-or-equal test defined as !(lhs < nullptr).
Definition: ReferencePtr.h:324
T & getRef() const
Return a reference to the target object.
Definition: ReferencePtr.h:139
T * get() const noexcept
Return the contained pointer, or null if the container is empty.
Definition: ReferencePtr.h:135
ReferencePtr & operator=(const ReferencePtr &src) noexcept
Copy assignment sets the pointer to nullptr (except for a self-assign); see class comments for why...
Definition: ReferencePtr.h:104
ReferencePtr() noexcept
Default constructor creates an empty object.
Definition: ReferencePtr.h:69
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
ReferencePtr & operator=(ReferencePtr &&src) noexcept
Move assignment copies the pointer from the source and leaves the source empty.
Definition: ReferencePtr.h:109
ReferencePtr & operator=(T *tp) noexcept
This form of assignment replaces the current pointer with the given one; no destruction occurs...
Definition: ReferencePtr.h:122
bool operator==(const ReferencePtr< T > &lhs, const ReferencePtr< U > &rhs)
Compare for equality the managed pointers contained in two compatible ReferencePtr containers...
Definition: ReferencePtr.h:231
T element_type
Type of the contained object.
Definition: ReferencePtr.h:62
~ReferencePtr() noexcept
Destructor does nothing.
Definition: ReferencePtr.h:128
void swap(ReferencePtr< T > &p1, ReferencePtr< T > &p2) noexcept
This is an overload of the STL std::swap() algorithm which uses the cheap built-in swap() member of t...
Definition: ReferencePtr.h:212
void swap(ReferencePtr &other) noexcept
Swap the contents of this ReferencePtr with another one.
Definition: ReferencePtr.h:164
bool operator>(const ReferencePtr< T > &lhs, std::nullptr_t)
nullptr greater-than test defined as nullptr < lhs.
Definition: ReferencePtr.h:305
ReferencePtr & operator=(T &t) noexcept
This form of assignment replaces the currently-referenced object by a reference to the source object;...
Definition: ReferencePtr.h:117
bool operator>(std::nullptr_t, const ReferencePtr< T > &rhs)
nullptr greater-than test defined as rhs < nullptr.
Definition: ReferencePtr.h:311
#define DEPRECATED_14(MSG)
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:289
bool operator!=(std::nullptr_t, const ReferencePtr< T > &rhs)
nullptr inequality test defined as !(nullptr==rhs).
Definition: ReferencePtr.h:293
bool empty() const noexcept
Return true if this container is empty.
Definition: ReferencePtr.h:169
ReferencePtr(const ReferencePtr &) noexcept
Copy constructor unconditionally sets the pointer to null; see class comments for why...
Definition: ReferencePtr.h:85
ReferencePtr(T *tp) noexcept
Construct from a given pointer stores the pointer.
Definition: ReferencePtr.h:77
bool operator!=(const ReferencePtr< T > &lhs, std::nullptr_t)
nullptr inequality test defined as !(lhs==nullptr).
Definition: ReferencePtr.h:287
T & operator*() const
The "dereference" operator returns a reference to the target object.
Definition: ReferencePtr.h:151
bool operator==(const ReferencePtr< T > &lhs, std::nullptr_t)
Comparison against nullptr; same as lhs.empty().
Definition: ReferencePtr.h:238
ReferencePtr(T &t) noexcept
Construct from a reference stores the address of the supplied object.
Definition: ReferencePtr.h:81
T & reference
Type of a reference to the contained object.
Definition: ReferencePtr.h:64
ReferencePtr(ReferencePtr &&src) noexcept
Move constructor copies the pointer from the source and leaves the source empty.
Definition: ReferencePtr.h:89
#define SimTK_ERRCHK(cond, whereChecked, msg)
Definition: ExceptionMacros.h:324
This is a smart pointer that implements "cross reference" semantics where a pointer data member of so...
Definition: ReferencePtr.h:60
Mandatory first inclusion for any Simbody source or header file.
T * pointer
Type of a pointer to the contained object.
Definition: ReferencePtr.h:63
ReferencePtr(std::nullptr_t) noexcept
Constructor from nullptr is the same as the default constructor.
Definition: ReferencePtr.h:74
bool operator>=(std::nullptr_t, const ReferencePtr< T > &rhs)
nullptr greater-or-equal test defined as !(nullptr < rhs).
Definition: ReferencePtr.h:330
void clear() noexcept
(Deprecated) Use reset() instead.
Definition: ReferencePtr.h:185
T * release() noexcept
Extract the pointer from this container, leaving the container empty.
Definition: ReferencePtr.h:177
bool operator!=(const ReferencePtr< T > &lhs, const ReferencePtr< U > &rhs)
Pointer inequality test defined as !(lhs==rhs).
Definition: ReferencePtr.h:280
T * operator->() const
Return the contained pointer.
Definition: ReferencePtr.h:147
bool operator>(const ReferencePtr< T > &lhs, const ReferencePtr< U > &rhs)
Pointer greater-than test defined as rhs < lhs.
Definition: ReferencePtr.h:299
bool operator==(std::nullptr_t, const ReferencePtr< T > &rhs)
Comparison against nullptr; same as rhs.empty().
Definition: ReferencePtr.h:244
bool operator>=(const ReferencePtr< T > &lhs, const ReferencePtr< U > &rhs)
Pointer greater-or-equal test defined as !(lhs < rhs).
Definition: ReferencePtr.h:318
void reset(T *tp=nullptr) noexcept
Replace the stored pointer with a different one; no destruction occurs.
Definition: ReferencePtr.h:160