A container class for an arbitrary type T (with some restrictions).
This class inherits from AbstractValue and therefore at runtime can be passed between functions without mentioning T.
Example:
(Advanced.) User-defined classes with additional features may subclass Value, but should take care to override Clone().
T | Must be copy-constructible or cloneable. Must not be a pointer, array, nor have const, volatile, or reference qualifiers. |
#include <drake/common/value.h>
Public Member Functions | |
Value () | |
Constructs a Value<T> using T's default constructor, if available. More... | |
Value (const T &v) | |
Constructs a Value<T> by copying or cloning the given value v . More... | |
template<typename... Args> | |
Value (Args &&... args) | |
Constructs a Value<T> by forwarding the given args to T's constructor, if available. More... | |
Value (std::unique_ptr< T > v) | |
Constructs a Value<T> by copying or moving the given value v . More... | |
~Value () override | |
const T & | get_value () const |
Returns a const reference to the stored value. More... | |
T & | get_mutable_value () |
Returns a mutable reference to the stored value. More... | |
void | set_value (const T &v) |
Replaces the stored value with a new one. More... | |
std::unique_ptr< AbstractValue > | Clone () const override |
Returns a copy of this AbstractValue. More... | |
void | SetFrom (const AbstractValue &other) override |
Copies the value in other to this value. More... | |
const std::type_info & | type_info () const final |
Returns typeid of the contained object of type T. More... | |
const std::type_info & | static_type_info () const final |
Returns typeid(T) for this Value<T> object. More... | |
std::string | GetNiceTypeName () const |
Returns a human-readable name for the underlying type T. More... | |
virtual const std::type_info & | static_type_info () const=0 |
Returns typeid(T) for this Value<T> object. More... | |
Does not allow copy, move, or assignment | |
Value (const Value &)=delete | |
Value & | operator= (const Value &)=delete |
Value (Value &&)=delete | |
Value & | operator= (Value &&)=delete |
Public Member Functions inherited from AbstractValue | |
virtual | ~AbstractValue () |
template<typename T > | |
const T & | get_value () const |
Returns the value wrapped in this AbstractValue as a const reference. More... | |
template<typename T > | |
T & | get_mutable_value () |
Returns the value wrapped in this AbstractValue as mutable reference. More... | |
template<typename T > | |
void | set_value (const T &v) |
Sets the value wrapped in this AbstractValue. More... | |
template<typename T > | |
const T * | maybe_get_value () const |
Returns the value wrapped in this AbstractValue, if T matches the originally declared type of this AbstractValue. More... | |
template<typename T > | |
T * | maybe_get_mutable_value () |
Returns the mutable value wrapped in this AbstractValue, if T matches the originally declared type of this AbstractValue. More... | |
std::string | GetNiceTypeName () const |
Returns a human-readable name for the underlying type T. More... | |
AbstractValue (const AbstractValue &)=delete | |
AbstractValue & | operator= (const AbstractValue &)=delete |
AbstractValue (AbstractValue &&)=delete | |
AbstractValue & | operator= (AbstractValue &&)=delete |
Additional Inherited Members | |
Static Public Member Functions inherited from AbstractValue | |
static std::unique_ptr< AbstractValue > | Make () |
Constructs an AbstractValue using T's default constructor, if available. More... | |
template<typename T > | |
static std::unique_ptr< AbstractValue > | Make (const T &value) |
Returns an AbstractValue containing the given value . More... | |
Value | ( | ) |
Constructs a Value<T> using T's default constructor, if available.
This is only available for T's that support default construction.
|
explicit |
Constructs a Value<T> by copying or cloning the given value v
.
|
explicit |
Constructs a Value<T> by forwarding the given args
to T's constructor, if available.
This is only available for non-primitive T's that are constructible from args
.
|
explicit |
Constructs a Value<T> by copying or moving the given value v
.
|
override |
|
overridevirtual |
Returns a copy of this AbstractValue.
Implements AbstractValue.
T& get_mutable_value | ( | ) |
Returns a mutable reference to the stored value.
The reference remains valid only until this object is set or destroyed.
const T& get_value | ( | ) | const |
Returns a const reference to the stored value.
The reference remains valid only until this object is set or destroyed.
std::string GetNiceTypeName |
Returns a human-readable name for the underlying type T.
This may be slow but is useful for error messages. If T is polymorphic, this returns the typeid of the most-derived type of the contained object.
void set_value | ( | const T & | v | ) |
Replaces the stored value with a new one.
|
overridevirtual |
Copies the value in other
to this value.
If other is not compatible with this object, a std::logic_error will be thrown with a helpful error message.
Implements AbstractValue.
|
finalvirtual |
Returns typeid(T) for this Value<T> object.
If T is polymorphic, this does NOT reflect the typeid of the most-derived type of the contained object; the result is always the base type T.
Implements AbstractValue.
virtual const std::type_info& static_type_info |
Returns typeid(T) for this Value<T> object.
If T is polymorphic, this does NOT reflect the typeid of the most-derived type of the contained object; the result is always the base type T.
|
finalvirtual |
Returns typeid of the contained object of type T.
If T is polymorphic, this returns the typeid of the most-derived type of the contained object.
Implements AbstractValue.