6#ifndef MATERIALX_VALUE_H
7#define MATERIALX_VALUE_H
17MATERIALX_NAMESPACE_BEGIN
45class MX_CORE_API Value
51 FloatFormatDefault = 0,
53 FloatFormatScientific = 2
65 return std::make_shared<TypedValue<T>>(data);
69 static ValuePtr createValue(
const char* data)
71 return createValue(data ?
string(data) : EMPTY_STRING);
86 template <
class T>
bool isA()
const;
91 template <
class T>
const T&
asA()
const;
117 template <
class T>
friend class ValueRegistry;
119 using CreatorFunction =
ValuePtr (*)(
const string&);
120 using CreatorMap = std::unordered_map<string, CreatorFunction>;
123 static CreatorMap _creatorMap;
127template <
class T>
class MX_CORE_API TypedValue :
public Value
134 explicit TypedValue(
const T& value) :
138 virtual ~TypedValue() { }
173 if (!other || !other->isA<T>())
177 return _data == other->asA<T>();
190 static const string TYPE;
197class MX_CORE_API AggregateValue :
public Value
200 AggregateValue(
const string& typeName) :
204 virtual ~AggregateValue() { }
210 for (
const auto& val : _data)
212 result->appendValue(val->copy());
220 _data.emplace_back(valuePtr);
223 const vector<ConstValuePtr>& getMembers()
const
250 return std::make_shared<AggregateValue>(typeName);
256 const string _typeName;
258 vector<ConstValuePtr> _data;
263class MX_CORE_API ScopedFloatFormatting
267 ~ScopedFloatFormatting();
313MATERIALX_NAMESPACE_END
shared_ptr< const TypeDef > ConstTypeDefPtr
A shared pointer to a const TypeDef.
Definition Definition.h:44
vector< string > StringVec
A vector of strings.
Definition Library.h:61
MX_CORE_API StringVec parseStructValueString(const string &value)
Tokenize the string representation of a struct value i.e, "{1;2;3}" into a vector of substrings.
shared_ptr< AggregateValue > AggregateValuePtr
A shared pointer to an Aggregate Value.
Definition Value.h:35
vector< bool > BoolVec
A vector of booleans.
Definition Value.h:22
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition Value.h:32
MX_CORE_API T fromValueString(const string &value)
Convert the given value string to a data value of the given type.
vector< int > IntVec
A vector of integers.
Definition Value.h:20
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition Value.h:30
MX_CORE_API string toValueString(const T &data)
Convert the given data value to a value string.
vector< float > FloatVec
A vector of floats.
Definition Value.h:24
shared_ptr< const AggregateValue > ConstAggregateValuePtr
A shared pointer to a const Aggregate Value.
Definition Value.h:37
MX_CORE_API const string & getTypeString()
Return the type string associated with the given data type.
A subclass for aggregate values with multiple members.
Definition Value.h:198
ConstValuePtr getMemberValue(size_t index) const
Query an indexed member value from the aggregate.
Definition Value.h:229
void appendValue(ConstValuePtr valuePtr)
Append a member value to the aggregate.
Definition Value.h:218
ValuePtr copy() const override
Create a deep copy of the value.
Definition Value.h:207
static AggregateValuePtr createAggregateValue(const string &typeName)
Create a new value from an object of any valid MaterialX type.
Definition Value.h:248
string getValueString() const override
Return value string.
const string & getTypeString() const override
Return type string.
Definition Value.h:235
A type definition element within a Document.
Definition Definition.h:312
The class template for typed subclasses of Value.
Definition Value.h:128
const T & getData() const
Return stored data object.
Definition Value.h:159
void setData(const TypedValue< T > &value)
Set stored data object.
Definition Value.h:153
static ValuePtr createFromString(const string &value)
Create a new value of this type from a value string.
ValuePtr copy() const override
Create a deep copy of the value.
Definition Value.h:141
void setData(const T &value)
Set stored data object.
Definition Value.h:147
string getValueString() const override
Return value string.
const string & getTypeString() const override
Return type string.
A generic, discriminated value, whose type may be queried dynamically.
Definition Value.h:46
static ValuePtr createValueFromStrings(const string &value, const string &type, ConstTypeDefPtr typeDef=nullptr)
Create a new value instance from value and type strings.
virtual const string & getTypeString() const =0
Return the type string for this value.
static void setFloatFormat(FloatFormat format)
Set float formatting for converting values to strings.
virtual string getValueString() const =0
Return the value string for this value.
bool isA() const
Return true if this value is of the given type.
static FloatFormat getFloatFormat()
Return the current float format.
const T & asA() const
Return our underlying data as an object of the given type.
virtual ValuePtr copy() const =0
Create a deep copy of the value.
FloatFormat
Float formats to use when converting values to strings.
Definition Value.h:50
static void setFloatPrecision(int precision)
Set float precision for converting values to strings.
static ValuePtr createValue(const T &data)
Create a new value from an object of any valid MaterialX type.
Definition Value.h:63
static int getFloatPrecision()
Return the current float precision.