Drake
AbstractValue Class Referenceabstract

A fully type-erased container class. More...

#include <drake/systems/framework/value.h>

Inheritance diagram for AbstractValue:
[legend]

Public Member Functions

 AbstractValue ()
 
virtual ~AbstractValue ()
 
virtual std::unique_ptr< AbstractValueClone () const =0
 Returns a copy of this AbstractValue. More...
 
virtual void SetFrom (const AbstractValue &other)=0
 Copies or clones the value in other to this value. More...
 
virtual void SetFromOrThrow (const AbstractValue &other)=0
 Like SetFrom, but throws on mismatched types even in Release builds. More...
 
template<typename T >
const T & GetValue () const
 Returns the value wrapped in this AbstractValue, which must be of exactly type T. More...
 
template<typename T >
const T & GetValueOrThrow () const
 Like GetValue, but throws on mismatched types even in Release builds. More...
 
template<typename T >
T & GetMutableValue ()
 Returns the value wrapped in this AbstractValue, which must be of exactly type T. More...
 
template<typename T >
T & GetMutableValueOrThrow ()
 Like GetMutableValue, but throws on mismatched types even in Release builds. More...
 
template<typename T >
void SetValue (const T &value_to_set)
 Sets the value wrapped in this AbstractValue, which must be of exactly type T. More...
 
template<typename T >
void SetValueOrThrow (const T &value_to_set)
 Like SetValue, but throws on mismatched types even in Release builds. More...
 
Does not allow copy, move, or assignment
 AbstractValue (const AbstractValue &)=delete
 
AbstractValueoperator= (const AbstractValue &)=delete
 
 AbstractValue (AbstractValue &&)=delete
 
AbstractValueoperator= (AbstractValue &&)=delete
 

Static Public Member Functions

template<typename T >
static std::unique_ptr< AbstractValueMake (const T &value)
 Returns an AbstractValue containing the given value. More...
 

Detailed Description

A fully type-erased container class.

Only Value<T> should inherit directly from AbstractValue. User-defined classes that define additional type-erased features should inherit from Value<T>.

Most methods offer two variants, e.g., SetFrom and SetFromOrThrow. The former variants are optimized to use static_casts in Release builds but will not throw exceptions when concrete Value types are mismatched; the latter variants are guaranteed to throw on mismatched types, but may be slower at runtime. Prefer using the faster version only in performance- sensitive code (e.g., inner loops), and the safer version otherwise.

Constructor & Destructor Documentation

AbstractValue ( const AbstractValue )
delete
AbstractValue ( AbstractValue &&  )
delete
AbstractValue ( )
inline
~AbstractValue ( )
virtual

Member Function Documentation

virtual std::unique_ptr<AbstractValue> Clone ( ) const
pure virtual

Returns a copy of this AbstractValue.

Implemented in Value< T >.

Here is the caller graph for this function:

T& GetMutableValue ( )
inline

Returns the value wrapped in this AbstractValue, which must be of exactly type T.

T cannot be a superclass, abstract or otherwise. In Debug builds, if the types don't match, std::bad_cast will be thrown. In Release builds, this is not guaranteed. Intentionally not const: holders of const references to the AbstractValue should not be able to mutate the value it contains.

Here is the caller graph for this function:

T& GetMutableValueOrThrow ( )
inline

Like GetMutableValue, but throws on mismatched types even in Release builds.

const T& GetValue ( ) const
inline

Returns the value wrapped in this AbstractValue, which must be of exactly type T.

T cannot be a superclass, abstract or otherwise. In Debug builds, if the types don't match, std::bad_cast will be thrown. In Release builds, this is not guaranteed.

TODO(david-german-tri): Once this uses static_cast under the hood in Release builds, lower-case it.

Here is the caller graph for this function:

const T& GetValueOrThrow ( ) const
inline

Like GetValue, but throws on mismatched types even in Release builds.

Here is the caller graph for this function:

static std::unique_ptr<AbstractValue> Make ( const T &  value)
inlinestatic

Returns an AbstractValue containing the given value.

Here is the caller graph for this function:

AbstractValue& operator= ( const AbstractValue )
delete
AbstractValue& operator= ( AbstractValue &&  )
delete
virtual void SetFrom ( const AbstractValue other)
pure virtual

Copies or clones the value in other to this value.

In Debug builds, if the types don't match, std::bad_cast will be thrown. In Release builds, this is not guaranteed.

Implemented in Value< T >.

Here is the caller graph for this function:

virtual void SetFromOrThrow ( const AbstractValue other)
pure virtual

Like SetFrom, but throws on mismatched types even in Release builds.

Implemented in Value< T >.

void SetValue ( const T &  value_to_set)
inline

Sets the value wrapped in this AbstractValue, which must be of exactly type T.

T cannot be a superclass, abstract or otherwise.

Parameters
value_to_setThe value to be copied or cloned into this AbstractValue. In Debug builds, if the types don't match, std::bad_cast will be thrown. In Release builds, this is not guaranteed.

Here is the caller graph for this function:

void SetValueOrThrow ( const T &  value_to_set)
inline

Like SetValue, but throws on mismatched types even in Release builds.


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