maliput
Value< T > Class Template Reference

Detailed Description

template<typename T>
class maliput::drake::Value< T >

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:

void print_string(const AbstractValue& arg) {
const std::string& message = arg.get_value<std::string>();
std::cerr << message;
}
void meow() {
const Value<std::string> value("meow");
print_string(value);
}

(Advanced.) User-defined classes with additional features may subclass Value, but should take care to override Clone().

Template Parameters
TMust be copy-constructible or cloneable. Must not be a pointer, array, nor have const, volatile, or reference qualifiers.

#include <src/maliput/drake/common/value.h>

Public Member Functions

template<typename T1 = T, typename = typename std::enable_if_t<std::is_default_constructible_v<T1>>>
 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 Arg1 , typename... Args, typename = typename internal::ValueForwardingCtorEnabled<true, T, Arg1, Args...>>
 Value (Arg1 &&arg1, Args &&... args)
 Constructs a Value<T> by forwarding the given args to T's constructor, if available. More...
 
template<typename Arg1 , typename... Args, typename = void, typename = typename internal::ValueForwardingCtorEnabled<false, T, Arg1, Args...>>
 Value (Arg1 &&arg1, Args &&... args)
 
 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< AbstractValueClone () const override
 
void SetFrom (const AbstractValue &other) override
 
const std::type_info & type_info () const final
 
const std::type_info & static_type_info () const final
 
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...
 

Constructor & Destructor Documentation

◆ Value() [1/5]

Constructs a Value<T> using T's default constructor, if available.

This is only available for T's that support default construction.

◆ Value() [2/5]

Value ( const T &  v)
explicit

Constructs a Value<T> by copying or cloning the given value v.

◆ Value() [3/5]

Value ( Arg1 &&  arg1,
Args &&...  args 
)
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.

◆ Value() [4/5]

Value ( Arg1 &&  arg1,
Args &&...  args 
)
explicit

◆ Value() [5/5]

Value ( std::unique_ptr< T >  v)
explicit

Constructs a Value<T> by copying or moving the given value v.

Precondition
v is non-null.

◆ ~Value()

~Value ( )
override

Member Function Documentation

◆ Clone()

std::unique_ptr< AbstractValue > Clone
override

◆ get_mutable_value()

T & get_mutable_value

Returns a mutable reference to the stored value.

The reference remains valid only until this object is set or destroyed.

◆ get_value()

const T & get_value

Returns a const reference to the stored value.

The reference remains valid only until this object is set or destroyed.

◆ GetNiceTypeName()

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.

◆ set_value()

void set_value ( const T &  v)

Replaces the stored value with a new one.

◆ SetFrom()

void SetFrom ( const AbstractValue< T > &  other)
override

◆ static_type_info() [1/2]

const std::type_info & static_type_info
final

◆ static_type_info() [2/2]

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.

◆ type_info()

const std::type_info & type_info
final

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