6#ifndef MATERIALX_VALUE_H
7#define MATERIALX_VALUE_H
17MATERIALX_NAMESPACE_BEGIN
40 using Exception::Exception;
50 FloatFormatDefault = 0,
52 FloatFormatScientific = 2
64 return std::make_shared<TypedValue<T>>(data);
68 static ValuePtr createValue(
const char* data)
70 return createValue(data ?
string(data) : EMPTY_STRING);
85 template <
class T>
bool isA()
const;
90 template <
class T>
const T&
asA()
const;
103 _floatFormat = format;
109 _floatPrecision = precision;
121 return _floatPrecision;
125 template <
class T>
friend class ValueRegistry;
127 using CreatorFunction =
ValuePtr (*)(
const string&);
128 using CreatorMap = std::unordered_map<string, CreatorFunction>;
131 static CreatorMap _creatorMap;
132 static FloatFormat _floatFormat;
133 static int _floatPrecision;
153 return Value::createValue<T>(_data);
190 static const string TYPE;
243MATERIALX_NAMESPACE_END
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:31
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:29
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
MX_CORE_API const string & getTypeString()
Return the type string associated with the given data type.
The base class for exceptions that are propagated from the MaterialX library to the client applicatio...
Definition: Exception.h:22
An exception that is thrown when a type mismatch is encountered.
Definition: Value.h:38
The class template for typed subclasses of Value.
Definition: Value.h:138
const T & getData() const
Return stored data object.
Definition: Value.h:169
void setData(const TypedValue< T > &value)
Set stored data object.
Definition: Value.h:163
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:151
void setData(const T &value)
Set stored data object.
Definition: Value.h:157
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:45
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:101
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:113
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:49
static void setFloatPrecision(int precision)
Set float precision for converting values to strings.
Definition: Value.h:107
static ValuePtr createValue(const T &data)
Create a new value from an object of any valid MaterialX type.
Definition: Value.h:62
static int getFloatPrecision()
Return the current float precision.
Definition: Value.h:119
static ValuePtr createValueFromStrings(const string &value, const string &type)
Create a new value instance from value and type strings.