SyDEVS  v0.7
Simulation-based analysis of complex systems involving people, devices, physical elements, and dynamic environments.
sydevs::pointer Class Reference

A data type which represents a pointer to anything. More...

#include <pointer.h>

Public Member Functions

 pointer () noexcept
 Constructs a null pointer instance. More...
 
 pointer (std::nullptr_t X) noexcept
 Constructs a null pointer instance from a nullptr. More...
 
template<typename T >
 pointer (T *ptr)
 Constructs a pointer instance referencing the same data as ptr. More...
 
 pointer (const pointer &) noexcept=default
 Copy constructor. More...
 
pointeroperator= (const pointer &) noexcept=default
 Copy assignment. More...
 
 pointer (pointer &&) noexcept=default
 Move constructor. More...
 
pointeroperator= (pointer &&) noexcept=default
 Move assignment. More...
 
 ~pointer ()=default
 Destructor. More...
 
void reset () noexcept
 Modifies the pointer to reference nullptr. More...
 
template<typename T >
void reset (T *ptr)
 Modifies the pointer to reference the same data as ptr. More...
 
template<typename T >
T & dereference () const
 Returns the referenced data, casting it to type T. More...
 
 operator bool () const noexcept
 Returns true if the pointer does not reference nullptr. More...
 

Detailed Description

A data type which represents a pointer to anything.

A pointer instance encapsulates std::shared_ptr<void>, which is essentially a reference-counted pointer to any type of data. The example below demonstrates how to use the class.

auto val = pointer(new int64(7));
val.reset();
val.reset(new float64(-0.5));
if (val) {
auto x = val.dereference<float64>();
}
pointer() noexcept
Constructs a null pointer instance.
Definition: pointer.h:68
double float64
Definition: number_types.h:23
int64_t int64
Definition: number_types.h:15

Constructor & Destructor Documentation

◆ pointer() [1/5]

sydevs::pointer::pointer ( )
inlinenoexcept

Constructs a null pointer instance.

◆ pointer() [2/5]

sydevs::pointer::pointer ( std::nullptr_t  X)
inlineexplicitnoexcept

Constructs a null pointer instance from a nullptr.

◆ pointer() [3/5]

template<typename T >
sydevs::pointer::pointer ( T *  ptr)
inlineexplicit

Constructs a pointer instance referencing the same data as ptr.

◆ pointer() [4/5]

sydevs::pointer::pointer ( const pointer )
defaultnoexcept

Copy constructor.

◆ pointer() [5/5]

sydevs::pointer::pointer ( pointer &&  )
defaultnoexcept

Move constructor.

◆ ~pointer()

sydevs::pointer::~pointer ( )
default

Destructor.

Member Function Documentation

◆ dereference()

template<typename T >
T & sydevs::pointer::dereference
inline

Returns the referenced data, casting it to type T.

◆ operator bool()

sydevs::pointer::operator bool ( ) const
inlineexplicitnoexcept

Returns true if the pointer does not reference nullptr.

◆ operator=() [1/2]

pointer& sydevs::pointer::operator= ( const pointer )
defaultnoexcept

Copy assignment.

◆ operator=() [2/2]

pointer& sydevs::pointer::operator= ( pointer &&  )
defaultnoexcept

Move assignment.

◆ reset() [1/2]

void sydevs::pointer::reset ( )
inlinenoexcept

Modifies the pointer to reference nullptr.

◆ reset() [2/2]

template<typename T >
void sydevs::pointer::reset ( T *  ptr)
inline

Modifies the pointer to reference the same data as ptr.


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