30 #include "../enum/Enums.h"
84 void* value =
const_cast<void*
>(valueCopy);
99 if(!m_type || !dataType)
109 sp =
static_cast<std::string*
>(value);
119 sp =
static_cast<std::string*
>(value);
128 dValue =
static_cast<double*
>(value);
137 fValue =
static_cast<float*
>(value);
146 lValue =
static_cast<long*
>(value);
156 iValue =
static_cast<int*
>(value);
165 bValue =
static_cast<bool*
>(value);
179 m_colorValue = *colorValue;
186 fontValue =
static_cast<Font*
>(value);
190 m_fontValue = *fontValue;
197 sp =
static_cast<std::string*
>(value);
205 catch (std::exception
const& e)
207 std::string s_type = m_type->getName();
208 std::cerr << e.what() <<
"Failed - te::layout::Variant: convert to " << s_type << std::endl;
236 m_sValue = tree.data();
241 m_dValue = std::atof(tree.data().c_str());
246 m_iValue = std::atoi(tree.data().c_str());
251 m_lValue = std::atol(tree.data().c_str());
256 m_fValue = (float)std::atof(tree.data().c_str());
261 m_bValue = toBool(tree.data());
266 std::string color = tree.data();
268 std::vector<std::string> strings;
269 std::istringstream f(color);
271 while (std::getline(f, s,
','))
273 strings.push_back(s);
276 if(strings.empty() || strings.size() > 4)
279 int r = std::atoi(strings[0].c_str());
280 int g = std::atoi(strings[1].c_str());
281 int b = std::atoi(strings[2].c_str());
282 int a = std::atoi(strings[3].c_str());
284 m_colorValue.setColor(r,g,b,a);
291 std::string font = tree.data();
292 m_fontValue.fromString(font);
298 m_sValue = tree.data();
302 catch (std::exception
const& e)
304 std::string s_type = type->
getName();
305 std::cerr << e.what() <<
"Failed - te::layout::Variant: convert to " << s_type << std::endl;
358 m_sValue =
"unknown";
370 std::stringstream ss;
371 std::string s_convert;
383 s_convert = m_sValue;
388 s_convert = ss.str();
393 s_convert = ss.str();
398 s_convert = ss.str();
403 s_convert = ss.str();
407 s_convert = toString(m_colorValue.getRed());
408 s_convert +=
"," + toString(m_colorValue.getGreen());
409 s_convert +=
"," + toString(m_colorValue.getBlue());
410 s_convert +=
"," + toString(m_colorValue.getAlpha());
414 s_convert = m_fontValue.toString();
418 s_convert = m_bValue ?
"true" :
"false";
431 str.erase( str.find_last_not_of(
" \f\n\r\t\v" ) + 1 );
434 std::istringstream ss( str );
440 throw std::runtime_error(
"Failed: convert string to double.");
453 str.erase( str.find_last_not_of(
" \f\n\r\t\v" ) + 1 );
456 std::istringstream ss( str );
462 throw std::runtime_error(
"Failed: convert string to int.");
475 str.erase( str.find_last_not_of(
" \f\n\r\t\v" ) + 1 );
478 std::istringstream ss( str );
484 throw std::runtime_error(
"Failed: convert string to float.");
497 str.erase( str.find_last_not_of(
" \f\n\r\t\v" ) + 1 );
500 std::istringstream ss( str );
506 throw std::runtime_error(
"Failed: convert string to long.");
519 std::stringstream ss;
527 if(str.compare(
"true") == 0)
EnumType * getType()
Returns data type of this object.
virtual EnumDataType * getEnumDataType()
Returns data type enumeration.
std::string getName()
Returns name.
virtual EnumType * getDataTypeBool() const
Returns value that represents type bool belonging to enumeration.
virtual std::string convertToString()
Converts the value to a string.
virtual EnumType * getDataTypeDouble() const
Returns value that represents type double belonging to enumeration.
virtual EnumType * getDataTypeInt() const
Returns value that represents type integer belonging to enumeration.
virtual EnumType * getDataTypeNone() const
Returns value that represents type none belonging to enumeration.
virtual bool isComplex()
Return true if value is not of common C++ data type, false otherwise.
Class acts like a union for some C++/TerraLib5 data types. Responsible for storing the value...
float toFloat()
Returns the value of float type. (The setValue method received a float)
virtual ~Variant()
Destructor.
virtual void convertValue(const void *valueCopy)
Discovers the type of the value and sets for the corresponding attribute (storage). Any type of data, not included in this class, it will be by default "std::string".
Font toFont()
Returns the value of te::layout::Font type. (The setValue method received a te::layout::Font). Complex type.
EnumType * m_type
data type of this object
virtual void fromPtree(boost::property_tree::ptree tree, EnumType *type)
static Enums & getInstance()
It returns a reference to the singleton instance.
virtual float string2Float(std::string str)
Convert a string representation of a number into a float value.
virtual EnumType * getDataTypeFloat() const
Returns value that represents type float belonging to enumeration.
Class to represent a data type enumeration. Ex.: int, double, bool, te::color::RGBAColor (color)...
virtual void clear()
Reset state of object. Null state.
bool isNull()
Returns true if no value has been set, false otherwise.
virtual double string2Double(std::string str)
Convert a string representation of a number into a double value.
virtual EnumType * getDataTypeColor() const
Returns value that represents type te::color::RGBAColor** (color) belonging to enumeration.
virtual int string2Int(std::string str)
Convert a string representation of a number into a int value.
double toDouble()
Returns the value of double type. (The setValue method received a double)
virtual EnumType * getDataTypeLong() const
Returns value that represents type long belonging to enumeration.
Class that represents the value of an enumeration. An enumeration is made of "1..n" objects EnumType...
virtual EnumType * getDataTypeFont() const
Returns value that represents type Font belonging to enumeration.
virtual EnumType * getDataTypeStringList() const
Returns value that represents type StringList (string) belonging to enumeration.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
virtual long string2Long(std::string str)
Convert a string representation of a number into a long value.
std::string toString()
Returns the value of string type. (The setValue method received a string)
te::color::RGBAColor toColor()
Returns the value of te::color::RGBAColor type. (The setValue method received a te::color::RGBAColor)...
long toLong()
Returns the value of long type. (The setValue method received a long)
virtual EnumType * getDataTypeString() const
Returns value that represents type string belonging to enumeration.
int toInt()
Returns the value of int type. (The setValue method received a int)
bool toBool()
Returns the value of boolean type. (The setValue method received a boolean)