22 #ifndef _LUXRAYS_PROPERTIES_H
23 #define _LUXRAYS_PROPERTIES_H
32 #include <luxrays/utils/exportdefs.h>
40 CPP_EXPORT
class CPP_API
Blob {
43 Blob(
const char *data,
const size_t size);
44 Blob(
const std::string &base64Data);
47 const char *
GetData()
const {
return data; }
50 std::string ToString()
const;
59 CPP_EXPORT CPP_API std::ostream &
operator<<(std::ostream &os,
const Blob &blob);
108 template<
class T> T Get()
const;
110 DataType GetValueType()
const;
132 template<> CPP_API
bool PropertyValue::Get<bool>()
const;
133 template<> CPP_API
int PropertyValue::Get<int>()
const;
134 template<> CPP_API
unsigned int PropertyValue::Get<unsigned int>()
const;
135 template<> CPP_API
float PropertyValue::Get<float>()
const;
136 template<> CPP_API
double PropertyValue::Get<double>()
const;
137 template<> CPP_API
unsigned long long PropertyValue::Get<unsigned long long>()
const;
138 template<> CPP_API std::string PropertyValue::Get<std::string>()
const;
139 template<> CPP_API
const Blob &PropertyValue::Get<const Blob &>()
const;
170 Property(
const std::string &propName);
200 const std::string &
GetName()
const {
return name; }
210 newProp.
values.insert(newProp.
values.begin(), values.begin(), values.end());
223 newProp.
values.insert(newProp.
values.begin(), values.begin(), values.end());
232 unsigned int GetSize()
const {
return values.size(); }
249 template<
class T> T
Get(
const unsigned int index)
const {
250 if (index >= values.size())
251 throw std::runtime_error(
"Out of bound error for property: " + name);
253 return values[index].Get<T>();
265 if (index >= values.size())
266 throw std::runtime_error(
"Out of bound error for property: " + name);
268 return values[index].GetValueType();
289 template<
class T> T
Get()
const {
290 throw std::runtime_error(
"Unsupported data type in property: " + name);
302 template<
class T>
Property &
Set(
const unsigned int index,
const T &val) {
303 if (index >= values.size())
304 throw std::runtime_error(
"Out of bound error for property: " + name);
319 values.push_back(val);
327 std::string GetValuesString()
const;
331 void FromString(std::string &s);
338 std::string ToString()
const;
366 return Add(val0).
Add(val1);
381 template<
class T0,
class T1,
class T2>
Property &
operator()(
const T0 &val0,
const T1 &val1,
const T2 &val2) {
382 return Add(val0).
Add(val1).
Add(val2);
398 template<
class T0,
class T1,
class T2,
class T3>
Property &
operator()(
const T0 &val0,
const T1 &val1,
const T2 &val2,
const T3 &val3) {
399 return Add(val0).
Add(val1).
Add(val2).
Add(val3);
409 for (
size_t i = 0; i < vals.size(); ++i)
410 values.push_back(vals[i]);
429 values.push_back(std::string(val));
437 values.push_back(std::string(val));
441 return Add(std::string(val));
448 return Add(std::string(val));
456 return Add(std::string(val));
464 return Add(std::string(val));
467 static unsigned int CountFields(
const std::string &name);
468 static std::string ExtractField(
const std::string &name,
const unsigned int index);
469 static std::string ExtractPrefix(
const std::string &name,
const unsigned int count);
477 template<> CPP_API
bool Property::Get<bool>()
const;
478 template<> CPP_API
int Property::Get<int>()
const;
479 template<> CPP_API
unsigned int Property::Get<unsigned int>()
const;
480 template<> CPP_API
float Property::Get<float>()
const;
481 template<> CPP_API
double Property::Get<double>()
const;
482 template<> CPP_API
unsigned long long Property::Get<unsigned long long>()
const;
483 template<> CPP_API std::string Property::Get<std::string>()
const;
484 template<> CPP_API
const Blob &Property::Get<const Blob &>()
const;
518 unsigned int GetSize()
const;
569 Properties &SetFromStream(std::istream &stream);
577 Properties &SetFromFile(
const std::string &fileName);
585 Properties &SetFromString(
const std::string &propDefinitions);
599 const std::vector<std::string> &GetAllNames()
const;
609 std::vector<std::string> GetAllNames(
const std::string &prefix)
const;
618 std::vector<std::string> GetAllNamesRE(
const std::string ®ularExpression)
const;
635 std::vector<std::string> GetAllUniqueSubNames(
const std::string &prefix)
const;
643 bool HaveNames(
const std::string &prefix)
const;
651 bool HaveNamesRE(
const std::string ®ularExpression)
const;
660 Properties GetAllProperties(
const std::string &prefix)
const;
670 const Property &Get(
const std::string &propName)
const;
689 bool IsDefined(
const std::string &propName)
const;
696 void Delete(
const std::string &propName);
702 void DeleteAll(
const std::vector<std::string> &propNames);
709 std::string ToString()
const;
714 std::map<std::string, Property>
props;
const PropertyValue::DataType GetValueType(const unsigned int index) const
Returns the type of the value at the specified position.
const char * GetData() const
Property & operator()(const char *val)
Property & operator()(char *val)
Required to work around the problem of char* to bool conversion (instead of char* to string)...
Property Renamed(const std::string &newName) const
Return a new property with a new name.
A generic container for values.
Value that can be stored in a Property.
unsigned int GetSize() const
Returns the number of values associated to this property.
Property & operator=(char *val)
Required to work around the problem of char* to bool conversion (instead of char* to string)...
Property & Add(const char *val)
Required to work around the problem of char* to bool conversion (instead of char* to string)...
unsigned long long ulonglongVal
Property & operator()(const T0 &val0, const T1 &val1, const T2 &val2, const T3 &val3)
Adds a value to a property.
Property & Set(const unsigned int index, const T &val)
Sets the value at the specified position.
T Get(const unsigned int index) const
Returns the value at the specified position.
Property & Add(char *val)
Required to work around the problem of char* to bool conversion (instead of char* to string)...
Property & Add(const T &val)
Adds an item at the end of the list of values associated with the property.
std::string ToString() const
Returns a string with the name of the property followed by " = " and by all values associated to the ...
Property AddedNamePrefix(const std::string &prefix) const
Return a new property with a prefix added to the name.
Property & operator()(const T0 &val0)
Adds a value to a property.
A container for multiple Property.
std::string ToString() const
Converts all Properties in a string.
Property & operator=(const T &val)
Initializes a property with (only) the given value.
const std::string & GetName() const
Returns the name of a property.
Property & operator=(const char *val)
Required to work around the problem of char* to bool conversion (instead of char* to string)...
Property & operator()(const std::vector< T0 > &vals)
Adds a vector of values to a property.
T Get() const
Parses all values as a representation of the specified type.
Property & operator()(const T0 &val0, const T1 &val1, const T2 &val2)
Adds a value to a property.
CPP_EXPORT CPP_API std::ostream & operator<<(std::ostream &os, const Blob &blob)
std::vector< PropertyValue > PropertyValues
A vector of values that can be stored in a Property.
Property & operator()(const T0 &val0, const T1 &val1)
Adds a value to a property.
std::vector< std::string > names
std::map< std::string, Property > props