--- /dev/null
+#include "FloatValue.h"\r
+\r
+#include "FloatType.h"\r
+#include "Constants.h"\r
+#include "Range.h"\r
+#include "Limit.h"\r
+\r
+#include <sstream>\r
+#include <cfloat>\r
+#include <valarray>\r
+\r
+namespace Databoard {\r
+ namespace Value {\r
+ FloatValue::FloatValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)\r
+ {\r
+ }\r
+\r
+ FloatValue::~FloatValue()\r
+ {\r
+ }\r
+\r
+ void FloatValue::setValue(float value)\r
+ {\r
+ Databoard::Type::FloatType* floatType = dynamic_cast<Databoard::Type::FloatType*>(dataBoard);\r
+\r
+ if(floatType != NULL)\r
+ {\r
+ this->value = value;\r
+ }\r
+ }\r
+\r
+ float FloatValue::getValue()\r
+ {\r
+ return value;\r
+ }\r
+\r
+ std::string FloatValue::writeOut(int /*indent*/)\r
+ {\r
+ std::string s;\r
+\r
+ std::stringstream oss;\r
+\r
+ oss << value;\r
+\r
+ oss >> s;\r
+\r
+ //if(unit.size() != 0)\r
+ //{\r
+ // s += "(Unit=\"" + unit + "\")";\r
+ //}\r
+\r
+ return s;\r
+ }\r
+\r
+ bool FloatValue::equals(const Value* other)\r
+ {\r
+ FloatValue* o = (FloatValue*)other;\r
+\r
+ return (this->value < o->value);\r
+\r
+ }\r
+\r
+ std::string FloatValue::isValid()\r
+ {\r
+ if(dataBoard == NULL)\r
+ {\r
+ return "There is no datatype.";\r
+ }\r
+\r
+ Databoard::Type::FloatType* floatType = (Databoard::Type::FloatType*)dataBoard;\r
+\r
+ if(floatType->getRange() == NULL)\r
+ {\r
+ return STR_EMPTY;\r
+ }\r
+\r
+ double minValue = floatType->minValue();\r
+ double maxValue = floatType->maxValue();\r
+\r
+ if(floatType->getRange()->getLower()->getInclusive() == true)\r
+ {\r
+ if(value < minValue)\r
+ {\r
+ return std::string("FloatValue: ") + STR_ERROR_VALUE_SMALL;\r
+ }\r
+ }\r
+ else //if(integerType->getRange()->getLower()->getInclusive() == false)\r
+ {\r
+ if(value < minValue || (abs(value-minValue) < FLT_EPSILON))\r
+ {\r
+ return std::string("FloatValue: ") + STR_ERROR_VALUE_SMALL;\r
+ }\r
+ }\r
+\r
+ if(floatType->getRange()->getUpper()->getInclusive() == true)\r
+ {\r
+ if(value > maxValue)\r
+ {\r
+ return std::string("FloatValue: ") + STR_ERROR_VALUE_LARGE;\r
+ }\r
+ }\r
+ else //if(integerType->getRange()->getUpper()->getInclusive() == false)\r
+ {\r
+ if(value > maxValue || (abs(value-minValue) > FLT_EPSILON))\r
+ {\r
+ return std::string("FloatValue: ") + STR_ERROR_VALUE_LARGE;\r
+ }\r
+ }\r
+\r
+ return STR_EMPTY;\r
+ }\r
+ }\r
+}\r