DUDS
Distributed Update of Data from Something
duds::SomethingWeakRef< ST > Class Template Reference

A weak reference to a Something object. More...

#include <SomethingRef.hpp>

Collaboration diagram for duds::SomethingWeakRef< ST >:

Public Member Functions

 SomethingWeakRef ()=default
 Makes an uninitalized reference to nothing. More...
 
 SomethingWeakRef (const SomethingRef &)=default
 The default copy constructor. More...
 
 SomethingWeakRef (const weak_ptr< ST > &s)
 Makes a new reference to Something from a weak pointer. More...
 
 SomethingWeakRef (const shared_ptr< ST > &s)
 Makes a new reference to Something from a shared pointer. More...
 
bool expired () const noexcept
 Tells if the weak pointer to Something has expired. More...
 
shared_ptr< ST > lock () const noexcept
 Attempts to obtain a shared pointer to the referenced Something. More...
 
template<class S >
bool operator!= (const S &s) const
 Something objects are compared using their UUID. More...
 
template<class S >
bool operator< (const S &s) const
 Something objects are compared using their UUID. More...
 
template<class S >
bool operator<= (const S &s) const
 Something objects are compared using their UUID. More...
 
template<class S >
bool operator== (const S &s) const
 Something objects are compared using their UUID. More...
 
template<class S >
bool operator> (const S &s) const
 Something objects are compared using their UUID. More...
 
template<class S >
bool operator>= (const S &s) const
 Something objects are compared using their UUID. More...
 
void reset () noexcept
 Loses the reference to Something. More...
 
const boost::uuids::uuid & uuid () const
 Returns the object's unique identifier. More...
 
const weak_ptr< ST > weak () const
 Returns the weak pointer to Something. More...
 

Private Attributes

boost::uuids::uuid someId
 A unique identifier for Something that is valid across all peers. More...
 
weak_ptr< ST > wp
 A weak pointer to a Something. More...
 

Detailed Description

template<class ST = Something>
class duds::SomethingWeakRef< ST >

A weak reference to a Something object.

This object has its own copy of the Something's UUID and can be compared with Something and SomethingRef objects based on the UUID without accessing the referenced Something. This allows for containers that hold sets of sorted Something objects without managing the memory or lifespan of the objects.

Template Parameters
STThe Something type. It should be Something or a class derived from Something.
Todo:
Add templated conversions between compatible SomethingWeakRef types using different ST.
Author
Jeff Jackowski
Todo:
Decide if this should be used.

Definition at line 39 of file SomethingRef.hpp.

Constructor & Destructor Documentation

◆ SomethingWeakRef() [1/4]

template<class ST = Something>
duds::SomethingWeakRef< ST >::SomethingWeakRef ( )
default

Makes an uninitalized reference to nothing.

◆ SomethingWeakRef() [2/4]

template<class ST = Something>
duds::SomethingWeakRef< ST >::SomethingWeakRef ( const SomethingRef )
default

The default copy constructor.

◆ SomethingWeakRef() [3/4]

template<class ST = Something>
duds::SomethingWeakRef< ST >::SomethingWeakRef ( const weak_ptr< ST > &  s)
inline

Makes a new reference to Something from a weak pointer.

Precondition
The weak pointer can produce a shared pointer.
Parameters
sThe weak pointer to Something.
Exceptions
err?The provided weak pointer cannot produce a shared pointer.

Definition at line 63 of file SomethingRef.hpp.

◆ SomethingWeakRef() [4/4]

template<class ST = Something>
duds::SomethingWeakRef< ST >::SomethingWeakRef ( const shared_ptr< ST > &  s)
inline

Makes a new reference to Something from a shared pointer.

Precondition
The shared pointer points to Something.
Parameters
sThe shared pointer to Something.
Exceptions
err?The provided shared pointer points to nothing.

Definition at line 77 of file SomethingRef.hpp.

Member Function Documentation

◆ expired()

template<class ST = Something>
bool duds::SomethingWeakRef< ST >::expired ( ) const
inlinenoexcept

Tells if the weak pointer to Something has expired.

Definition at line 99 of file SomethingRef.hpp.

◆ lock()

template<class ST = Something>
shared_ptr<ST> duds::SomethingWeakRef< ST >::lock ( ) const
inlinenoexcept

Attempts to obtain a shared pointer to the referenced Something.

Returns
A shared pointer to the Something if not expired. Otherwise, a shared pointer to nothing.

Definition at line 107 of file SomethingRef.hpp.

◆ operator!=()

template<class ST = Something>
template<class S >
bool duds::SomethingWeakRef< ST >::operator!= ( const S &  s) const
inline

Something objects are compared using their UUID.

Definition at line 158 of file SomethingRef.hpp.

◆ operator<()

template<class ST = Something>
template<class S >
bool duds::SomethingWeakRef< ST >::operator< ( const S &  s) const
inline

Something objects are compared using their UUID.

Definition at line 123 of file SomethingRef.hpp.

◆ operator<=()

template<class ST = Something>
template<class S >
bool duds::SomethingWeakRef< ST >::operator<= ( const S &  s) const
inline

Something objects are compared using their UUID.

Definition at line 137 of file SomethingRef.hpp.

◆ operator==()

template<class ST = Something>
template<class S >
bool duds::SomethingWeakRef< ST >::operator== ( const S &  s) const
inline

Something objects are compared using their UUID.

Definition at line 151 of file SomethingRef.hpp.

◆ operator>()

template<class ST = Something>
template<class S >
bool duds::SomethingWeakRef< ST >::operator> ( const S &  s) const
inline

Something objects are compared using their UUID.

Definition at line 130 of file SomethingRef.hpp.

◆ operator>=()

template<class ST = Something>
template<class S >
bool duds::SomethingWeakRef< ST >::operator>= ( const S &  s) const
inline

Something objects are compared using their UUID.

Definition at line 144 of file SomethingRef.hpp.

◆ reset()

template<class ST = Something>
void duds::SomethingWeakRef< ST >::reset ( )
inlinenoexcept

Loses the reference to Something.

Precondition
This object is not being used as a key for a sorted container.
Postcondition
The weak pointer will be expired, and the UUID will be zero.

Definition at line 115 of file SomethingRef.hpp.

◆ uuid()

template<class ST = Something>
const boost::uuids::uuid& duds::SomethingWeakRef< ST >::uuid ( ) const
inline

Returns the object's unique identifier.

Definition at line 87 of file SomethingRef.hpp.

◆ weak()

template<class ST = Something>
const weak_ptr<ST> duds::SomethingWeakRef< ST >::weak ( ) const
inline

Returns the weak pointer to Something.

Definition at line 93 of file SomethingRef.hpp.

Member Data Documentation

◆ someId

template<class ST = Something>
boost::uuids::uuid duds::SomethingWeakRef< ST >::someId
private

A unique identifier for Something that is valid across all peers.

Definition at line 43 of file SomethingRef.hpp.

Referenced by duds::SomethingRef< ST >::reset(), and duds::SomethingWeakRef< ST >::uuid().

◆ wp

template<class ST = Something>
weak_ptr<ST> duds::SomethingWeakRef< ST >::wp
private

A weak pointer to a Something.

Definition at line 47 of file SomethingRef.hpp.

Referenced by duds::SomethingWeakRef< ST >::weak().


The documentation for this class was generated from the following file: