9 #include "drake/drakeSystemFramework_export.h" 28 virtual std::unique_ptr<AbstractValue> Clone()
const = 0;
36 return DownCastOrMaybeThrow<T>()->get_value();
47 return DownCastMutableOrMaybeThrow<T>()->get_mutable_value();
57 DownCastMutableOrMaybeThrow<T>()->set_value(value_to_set);
64 Value<T>* DownCastMutableOrMaybeThrow() {
68 return const_cast<Value<T>*
>(DownCastOrMaybeThrow<T>());
75 const Value<T>* DownCastOrMaybeThrow()
const {
77 if (value ==
nullptr) {
78 throw std::logic_error(
79 "AbstractValue::DownCastOrMaybeThrow(): Can't downcast to type " +
80 NiceTypeName::Get<T>() +
".");
93 explicit Value(
const T& v) : value_(v) {}
101 std::unique_ptr<AbstractValue>
Clone()
const override {
102 return std::make_unique<Value<T>>(*this);
void SetValue(const T &value_to_set)
Sets the value wrapped in this AbstractValue, which must be of exactly type T.
Definition: value.h:56
std::unique_ptr< AbstractValue > Clone() const override
Returns a copy of this AbstractValue.
Definition: value.h:101
Definition: constants.h:3
Value(const T &v)
Definition: value.h:93
virtual ~AbstractValue()
Definition: value.h:25
const T & GetValue() const
Returns the value wrapped in this AbstractValue, which must be of exactly type T. ...
Definition: value.h:35
AbstractValue()
Definition: value.h:24
T * get_mutable_value()
Returns a mutable pointer to the stored value (never null).
Definition: value.h:109
T * GetMutableValue()
Returns the value wrapped in this AbstractValue, which must be of exactly type T. ...
Definition: value.h:46
void set_value(const T &v)
Replaces the stored value with a new one.
Definition: value.h:112
A fully type-erased container class.
Definition: value.h:22
A container class for an arbitrary type T.
Definition: value.h:15
const T & get_value() const
Returns a const reference to the stored value.
Definition: value.h:106