Spicy
Public Member Functions | Static Public Member Functions | List of all members
hilti::rt::ValueReference< T > Class Template Reference

#include <reference.h>

Public Member Functions

 ValueReference ()
 
 ValueReference (T t)
 
 ValueReference (std::shared_ptr< T > t)
 
 ValueReference (const ValueReference &other)
 
 ValueReference (ValueReference &&other) noexcept=default
 
 ~ValueReference ()
 
bool isNull () const
 
const T * get () const
 
std::shared_ptr< T > asSharedPtr () const
 
void reset ()
 
const T & operator* () const
 
T & operator* ()
 
const T * operator-> () const
 
T * operator-> ()
 
bool operator== (const ValueReference< T > &other) const
 
bool operator== (const T &other) const
 
bool operator!= (const ValueReference< T > &other) const
 
bool operator!= (const T &other) const
 
ValueReferenceoperator= (T other)
 
ValueReferenceoperator= (const ValueReference &other)
 
ValueReferenceoperator= (ValueReference &&other) noexcept
 

Static Public Member Functions

static ValueReference self (T *t)
 

Detailed Description

template<typename T>
class hilti::rt::ValueReference< T >

Class representing HILTI's value_ref<T> type. This class stores an value of type T on the heap and imposes value semantics on it. In particular, copying a ValueReference will link the new instance to its own copy of the managed value.

Generally, a value reference will always have a value associated with it. There are however ways to create it without one. Accesses that require a value, are checked and will abort in that case.

Other reference types (StrongReference, WeakReference) can bind to an existing value reference, essentially creating handles to its value. They then become joined managers of the value.

Note
It seems we could clean up this class and get rid of the internal variant altogether. We need the variant only to potentially store a raw pointer coming in through the corresponding constructor. However, we require that pointer to point to a Controllable and hence could turn it into a shared_ptr right there. On the downside, that would mean a shared_from_this() call even if the resulting instance is never used – which with the current code generator could happen frequently (at least once we optimized to use this instead of the self wrapper when possible). So leaving it alone for now.

Constructor & Destructor Documentation

◆ ValueReference() [1/5]

template<typename T>
hilti::rt::ValueReference< T >::ValueReference ( )
inline

Instantiates a reference containing a new value of T initialized to its default value.

◆ ValueReference() [2/5]

template<typename T>
hilti::rt::ValueReference< T >::ValueReference ( t)
inline

Instantiates a reference containing a new value of T initialized to a given value.

Parameters
tvalue to initialize new instance with

◆ ValueReference() [3/5]

template<typename T>
hilti::rt::ValueReference< T >::ValueReference ( std::shared_ptr< T >  t)
inlineexplicit

Instantiates a new reference from an existing std::shared_ptr to a value of type T. This does not copy the pointer's target value; the new reference will keep a pointer to the same value.

This constructor is mostly for internal purposes to create a new value reference that's associated with an existing StrongReference.

Parameters
tshared pointer to link to

◆ ValueReference() [4/5]

template<typename T>
hilti::rt::ValueReference< T >::ValueReference ( const ValueReference< T > &  other)
inline

Copy constructor. The new instance will refer to a copy of the source's value.

◆ ValueReference() [5/5]

template<typename T>
hilti::rt::ValueReference< T >::ValueReference ( ValueReference< T > &&  other)
defaultnoexcept

Move constructor.

◆ ~ValueReference()

template<typename T>
hilti::rt::ValueReference< T >::~ValueReference ( )
inline

Destructor.

Member Function Documentation

◆ asSharedPtr()

template<typename T>
std::shared_ptr<T> hilti::rt::ValueReference< T >::asSharedPtr ( ) const
inline

Returns a shared pointer to the referred value. The result may be a null pointer if the instance does not refer to a valid value.

For this to work, the value reference must have either (1) create the contained value itself through one of the standard constructor; or (2) if created through an explicit pointer constructor, the instance must be located on the heap and be the instance of a classed derived from Controllable<T>.

Exceptions
IllegalReferenceif no shared pointer can be constructed for the contained instance.

◆ get()

template<typename T>
const T* hilti::rt::ValueReference< T >::get ( ) const
inline

Returns a pointer to the referred value. The result may be null if the instance does not refer to a valid value.

◆ isNull()

template<typename T>
bool hilti::rt::ValueReference< T >::isNull ( ) const
inline

Returns true if the reference does not contain a value. This will rarely happen, except when explicitly constructed that way through an existing pointer.

◆ operator!=() [1/2]

template<typename T>
bool hilti::rt::ValueReference< T >::operator!= ( const ValueReference< T > &  other) const
inline

Compares the values of two references.

Exceptions
NullReferenceif one of the instances does not refer to a valid value

◆ operator!=() [2/2]

template<typename T>
bool hilti::rt::ValueReference< T >::operator!= ( const T &  other) const
inline

Compares the values of two references.

Exceptions
NullReferenceif one of the instances does not refer to a valid value

◆ operator*() [1/2]

template<typename T>
const T& hilti::rt::ValueReference< T >::operator* ( ) const
inline

Returns a reference to the contained value.

Exceptions
NullReferenceif the instance does not refer to a valid value

◆ operator*() [2/2]

template<typename T>
T& hilti::rt::ValueReference< T >::operator* ( )
inline

Returns a reference to the contained value.

Exceptions
NullReferenceif the instance does not refer to a valid value

◆ operator->() [1/2]

template<typename T>
const T* hilti::rt::ValueReference< T >::operator-> ( ) const
inline

Returns a pointer to the contained value.

Exceptions
NullReferenceif the instance does not refer to a valid value

◆ operator->() [2/2]

template<typename T>
T* hilti::rt::ValueReference< T >::operator-> ( )
inline

Returns a pointer to the contained value.

Exceptions
NullReferenceif the instance does not refer to a valid value

◆ operator=() [1/3]

template<typename T>
ValueReference& hilti::rt::ValueReference< T >::operator= ( other)
inline

Assigns to the contained value. Assigning does not invalidate other references associated with the same value; they'll see the change.

Exceptions
NullReferenceif the instance does not currently refer to a valid value

◆ operator=() [2/3]

template<typename T>
ValueReference& hilti::rt::ValueReference< T >::operator= ( const ValueReference< T > &  other)
inline

Assigns to the contained value. Assigning does not invalidate other references associated with the same value; they'll see the change.

Exceptions
NullReferenceif the instance does not currently refer to a valid value

◆ operator=() [3/3]

template<typename T>
ValueReference& hilti::rt::ValueReference< T >::operator= ( ValueReference< T > &&  other)
inlinenoexcept

Assigns to the contained value. Assigning does not invalidate other references associated with the same value; they'll see the change.

Exceptions
NullReferenceif the instance does not currently refer to a valid value

◆ operator==() [1/2]

template<typename T>
bool hilti::rt::ValueReference< T >::operator== ( const ValueReference< T > &  other) const
inline

Compares the values of two references.

Exceptions
NullReferenceif one of the instances does not refer to a valid value

◆ operator==() [2/2]

template<typename T>
bool hilti::rt::ValueReference< T >::operator== ( const T &  other) const
inline

Compares the values of two references.

Exceptions
NullReferenceif one of the instances does not refer to a valid value

◆ reset()

template<typename T>
void hilti::rt::ValueReference< T >::reset ( )
inline

Resets the contained value to a fresh copy of a T value initialized to its default.

◆ self()

template<typename T>
static ValueReference hilti::rt::ValueReference< T >::self ( T *  t)
inlinestatic

Shortcut to create a new instance referring to an existing value of type T. T must be derived from Controllable<T>.

This is for internal use by the code generator to wrap this inside methods into a value reference.


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