Implements Drake policy for taking a concrete value object and storing it in a Drake abstract object (for example, an abstract-valued port) as a type-erased AbstractValue.
We call this "AbstractPolicy" to distinguish it from the "VectorPolicy" implemented by ValueToVectorValue.
Usage
This class can be used in conjunction with ValueToVectorValue to store an arbitrary value object into a Drake abstract or vector object, using the appropriate policy. Here is an example:
std::unique_ptr<AbstractValue> abstract_value =
is_vector_port
: internal::ValueToAbstractValue::
ToAbstract(__func__, value);
Note that for this to work both ToAbstract() methods must compile successfully. Thus where one policy is more restrictive than the other, it must issue runtime (not compile time) errors for values that are unacceptable.
- See also
- ValueToVectorValue
AbstractPolicy
- Any given AbstractValue object is simply cloned.
- A
char *
type is copied into a Value<std::string>.
- Eigen objects and expressions are not accepted directly under AbstractPolicy as they are under VectorPolicy. The caller must instead provide the storage type explicitly via Value<EigenType>.
- For any other type V
- if V is copy-constructible it is copied into a
Value<V>
;
- if V has an accessible Clone() method that returns
unique_ptr<V>
it is cloned into a Value<V>
;
- if V has an accessible
Clone()
method that returns unique_ptr<B>
, where B is a base class of V, then V is cloned into a Value<B>
;
- otherwise, compilation fails with a
static_assert
message.
- Warning
- Eigen expressions typically don't have simple Vector or Matrix types. That doesn't matter under the VectorPolicy (as long as the size and shape are acceptable). However, under the AbstractPolicy you must specify the storage type explicitly by suppling a Value<EigenType>(your_expression) object.
|
static std::unique_ptr< AbstractValue > | ToAbstract (const char *api_name, const AbstractValue &value) |
|
static std::unique_ptr< AbstractValue > | ToAbstract (const char *api_name, const char *c_string) |
|
template<typename ValueType , typename = std::enable_if_t<is_eigen_refable<ValueType>()>> |
static std::unique_ptr< AbstractValue > | ToAbstract (const char *api_name, const ValueType &eigen_value,...) |
|
template<typename ValueType > |
static constexpr bool | has_accessible_clone () |
|
template<typename ValueType , typename = std::enable_if_t<!(std::is_base_of_v<AbstractValue, ValueType> || is_eigen_refable<ValueType>())>> |
static std::unique_ptr< AbstractValue > | ToAbstract (const char *api_name, const ValueType &value) |
|