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;
104 _floatFormat = format;
110 _floatPrecision = precision;
122 return _floatPrecision;
126 template <
class T>
friend class ValueRegistry;
128 using CreatorFunction =
ValuePtr (*)(
const string&);
129 using CreatorMap = std::unordered_map<string, CreatorFunction>;
132 static CreatorMap _creatorMap;
133 static FloatFormat _floatFormat;
134 static int _floatPrecision;
138template <
class T>
class MX_CORE_API TypedValue :
public Value
145 explicit TypedValue(
const T& value) :
149 virtual ~TypedValue() { }
191 static const string TYPE;
198class MX_CORE_API AggregateValue :
public Value
201 AggregateValue(
const string& typeName) :
205 virtual ~AggregateValue() { }
211 for (
const auto& val : _data)
213 result->appendValue(val->copy());
221 _data.emplace_back(valuePtr);
224 const vector<ConstValuePtr>& getMembers()
const
248 return std::make_shared<AggregateValue>(typeName);
254 const string _typeName;
256 vector<ConstValuePtr> _data;
261class MX_CORE_API ScopedFloatFormatting
265 ~ScopedFloatFormatting();
311MATERIALX_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:60
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:199
ConstValuePtr getMemberValue(size_t index) const
Query an indexed member value from the aggregate.
Definition Value.h:230
void appendValue(ConstValuePtr valuePtr)
Append a member value to the aggregate.
Definition Value.h:219
ValuePtr copy() const override
Create a deep copy of the value.
Definition Value.h:208
static AggregateValuePtr createAggregateValue(const string &typeName)
Create a new value from an object of any valid MaterialX type.
Definition Value.h:246
string getValueString() const override
Return value string.
const string & getTypeString() const override
Return type string.
Definition Value.h:236
A type definition element within a Document.
Definition Definition.h:312
The class template for typed subclasses of Value.
Definition Value.h:139
const T & getData() const
Return stored data object.
Definition Value.h:170
void setData(const TypedValue< T > &value)
Set stored data object.
Definition Value.h:164
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:152
void setData(const T &value)
Set stored data object.
Definition Value.h:158
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.
Definition Value.h:102
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.
Definition Value.h:114
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.
Definition Value.h:108
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.
Definition Value.h:120