--- /dev/null
+#include "DoubleValue.h"\r
+\r
+#include "DoubleType.h"\r
+#include "Constants.h"\r
+\r
+#include "Range.h"\r
+#include "Limit.h"\r
+\r
+#include <sstream>\r
+#include <iomanip>\r
+#include <iostream>\r
+#include <valarray>\r
+#include <cfloat>\r
+\r
+namespace Databoard {\r
+ namespace Value {\r
+ DoubleValue::DoubleValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)\r
+ {\r
+ }\r
+\r
+ DoubleValue::~DoubleValue()\r
+ {\r
+ }\r
+\r
+ void DoubleValue::setValue(double value)\r
+ {\r
+ Databoard::Type::DoubleType* doubleType = dynamic_cast<Databoard::Type::DoubleType*>(dataBoard);\r
+\r
+ if(doubleType != NULL)\r
+ {\r
+ this->value = value;\r
+ }\r
+ }\r
+\r
+ double DoubleValue::getValue()\r
+ {\r
+ return value;\r
+ }\r
+\r
+ std::string DoubleValue::writeOut(int /*indent*/)\r
+ {\r
+ std::string s;\r
+\r
+ std::stringstream oss;\r
+\r
+ //oss.setf(std::ios::fixed);\r
+\r
+ oss << value;\r
+\r
+ oss >> s;\r
+\r
+ return s;\r
+ }\r
+\r
+ bool DoubleValue::equals(const Value* other)\r
+ {\r
+ DoubleValue* o = (DoubleValue*)other;\r
+\r
+ return (this->value < o->value);\r
+ }\r
+\r
+ std::string DoubleValue::isValid()\r
+ {\r
+ if(dataBoard == NULL)\r
+ {\r
+ return "There is no datatype.";\r
+ }\r
+\r
+ Databoard::Type::DoubleType* doubleType = (Databoard::Type::DoubleType*)dataBoard;\r
+\r
+ if(doubleType->getRange() == NULL)\r
+ {\r
+ return STR_EMPTY;\r
+ }\r
+\r
+ double minValue = doubleType->minValue();\r
+ double maxValue = doubleType->maxValue();\r
+\r
+ if(doubleType->getRange()->getLower()->getInclusive() == true)\r
+ {\r
+ if(value < minValue)\r
+ {\r
+ return std::string("DoubleValue: ") + STR_ERROR_VALUE_SMALL;\r
+ }\r
+ }\r
+ else //if(integerType->getRange()->getLower()->getInclusive() == false)\r
+ {\r
+ if(value < minValue || (abs(value-minValue) < DBL_EPSILON))\r
+ {\r
+ return std::string("DoubleValue: ") + STR_ERROR_VALUE_SMALL;\r
+ }\r
+ }\r
+\r
+ if(doubleType->getRange()->getUpper()->getInclusive() == true)\r
+ {\r
+ if(value > maxValue)\r
+ {\r
+ return std::string("DoubleValue: ") + STR_ERROR_VALUE_LARGE;\r
+ }\r
+ }\r
+ else //if(integerType->getRange()->getUpper()->getInclusive() == false)\r
+ {\r
+ double d1 = abs(value-maxValue);\r
+ double d2 = DBL_EPSILON;\r
+\r
+ if(value > maxValue || (abs(value-maxValue) < DBL_EPSILON))\r
+ {\r
+ return std::string("DoubleValue: ") + STR_ERROR_VALUE_LARGE;\r
+ }\r
+ }\r
+\r
+ return STR_EMPTY;\r
+ }\r
+ }\r
+}\r