1 #ifndef SimTK_SimTKCOMMON_VALUE_H_ 2 #define SimTK_SimTKCOMMON_VALUE_H_ 39 template<
typename T>
class Value;
115 explicit Value(
const T& value) : m_thing(value) {}
120 explicit Value(
const T&& value) : m_thing(
std::move(value)) {}
135 { m_thing = value.m_thing;
return *
this; }
142 { m_thing = std::move(value.m_thing);
return *
this; }
147 { m_thing = value;
return *
this; }
152 { m_thing = std::move(value);
return *
this; }
157 const T&
get()
const {
return m_thing;}
162 T&
upd() {
return m_thing;}
166 void set(
const T& value) {m_thing = value;}
170 void set(
const T&& value) {m_thing = std::move(value);}
175 operator const T&()
const {
return get();}
180 operator T&() {
return upd();}
191 {
return isA(value); }
214 {
return dynamic_cast<const Value*
>(&value) !=
nullptr; }
220 {
return SimTK_DYNAMIC_CAST_DEBUG<const Value&>(value); }
226 {
return SimTK_DYNAMIC_CAST_DEBUG<Value&>(value); }
239 #endif // SimTK_SimTKCOMMON_VALUE_H_ Value * clone() const override
Covariant implementation of the AbstractValue::clone() method.
Definition: Value.h:185
static const Value & downcast(const AbstractValue &value)
Downcast a const reference to an AbstractValue to a const reference to this type Value<T>.
Definition: Value.h:219
static Value & updDowncast(AbstractValue &value)
Downcast a writable reference to an AbstractValue to a writable reference to this type Value<T>...
Definition: Value.h:225
Value()
Creates a Value<T> whose contained object of type T has been default constructed. ...
Definition: Value.h:111
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
Value(const T &&value)
Creates a Value<T> whose contained object is move constructed from the given value.
Definition: Value.h:120
std::ostream & operator<<(std::ostream &o, const AbstractValue &v)
Write a human-readable representation of an AbstractValue to an output stream, using the getValueAsSt...
Definition: Value.h:96
T & updValue()
Retrieve the original (type-erased)thing as read-write.
Definition: Value.h:86
bool isCompatible(const AbstractValue &value) const override
Test whether a given AbstractValue is assignment-compatible with this Value object.
Definition: Value.h:190
virtual String getValueAsString() const =0
Return a human-readable representation of the value stored in this AbstractValue object.
static const std::string & namestr()
The default implementation of namestr() attempts to return a nicely demangled and canonicalized type ...
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:867
Value(const T &value)
Creates a Value<T> whose contained object is copy constructed from the given value.
Definition: Value.h:115
T & upd()
Return a writable reference to the object of type T that is contained in this Value object...
Definition: Value.h:162
AbstractValue & operator=(const AbstractValue &v)
Invokes the compatibleAssign() method which will perform the assignment if the source object is compa...
Definition: Value.h:73
Value(const Value &&value)
Move constructor invokes the type T move constructor, if available, to move the given value into this...
Definition: Value.h:130
Value & operator=(const T &&value)
Assign a new value to the contained object, using the type T move assignment operator, if available.
Definition: Value.h:151
Value & operator=(const Value &&value)
The move assignment here invokes type T move assignment on the contained object, it does not invoke A...
Definition: Value.h:141
Value & operator=(const T &value)
Assign a new value to the contained object, using the type T copy assignment operator.
Definition: Value.h:146
Value & operator=(const Value &value)
The copy assignment here invokes type T copy assignment on the contained object, it does not invoke A...
Definition: Value.h:134
#define SimTK_THROW2(exc, a1, a2)
Definition: Exception.h:318
virtual String getTypeName() const =0
Return a human-readable form of the object type that is stored in the concrete derived class underlyi...
const T & getValue() const
Retrieve the original (type-erased)thing as read-only.
Definition: Value.h:79
void compatibleAssign(const AbstractValue &value) override
If the given AbstractValue is assignment-compatible, perform the assignment.
Definition: Value.h:195
String getTypeName() const override
Use NiceTypeName to produce a human-friendly representation of the type T.
Definition: Value.h:204
String getValueAsString() const override
(Not implemented yet) Produce a human-friendly representation of the contained value of type T...
Definition: Value.h:208
static bool isA(const AbstractValue &value)
Return true if the given AbstractValue is an object of this type Value<T>.
Definition: Value.h:213
Definition: Exception.h:261
const T & get() const
Return a const reference to the object of type T that is contained in this Value<T> object...
Definition: Value.h:157
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
static Value & downcast(AbstractValue &value)
Deprecated – use updDowncast() instead.
Definition: Value.h:229
Abstract base class representing an arbitrary value of unknown type.
Definition: Value.h:49
Mandatory first inclusion for any Simbody source or header file.
virtual AbstractValue * clone() const =0
Create a deep copy of this object.
Value(const Value &value)
Copy constructor invokes the type T copy constructor to copy the contained value. ...
Definition: Value.h:126
virtual bool isCompatible(const AbstractValue &other) const =0
Check whether the other object contains a value that is assignment- compatible with this one...
virtual void compatibleAssign(const AbstractValue &source)=0
If the source contains a compatible value, assign a copy of that value into this object.
virtual ~AbstractValue()
Definition: Value.h:90
Concrete templatized class derived from AbstractValue, adding generic value type-specific functionali...
Definition: Value.h:39