6#ifndef MATERIALX_VALUE_H
7#define MATERIALX_VALUE_H
41 using Exception::Exception;
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);
77 static ValuePtr createValueFromStrings(
const string& value,
const string& type);
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;
154 return Value::createValue<T>(_data);
188 static ValuePtr createFromString(
const string& value);
191 static const string TYPE;
211template<
class T> MX_CORE_API
const string& getTypeString();
214template <
class T> MX_CORE_API
string toValueString(
const T& data);
218template <
class T> MX_CORE_API T fromValueString(
const string& value);
vector< bool > BoolVec
A vector of booleans.
Definition: Value.h:23
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:32
vector< int > IntVec
A vector of integers.
Definition: Value.h:21
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition: Value.h:30
vector< float > FloatVec
A vector of floats.
Definition: Value.h:25
The base class for exceptions that are propagated from the MaterialX library to the client applicatio...
Definition: Exception.h:23
An exception that is thrown when a type mismatch is encountered.
Definition: Value.h:39
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
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
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.
static FloatFormat getFloatFormat()
Return the current float format.
Definition: Value.h:114
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