]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LongValue.cpp
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / LongValue.cpp
1 #include "LongValue.h"
2
3 #include "LongType.h"
4 #include "Constants.h"
5 #include "Range.h"
6 #include "Limit.h"
7
8 #include <sstream>
9
10 namespace Databoard {
11         namespace Value {
12                 LongValue::LongValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)
13                 {
14                 }
15
16                 LongValue::~LongValue()
17                 {
18                 }
19
20                 void LongValue::setValue(long value)
21                 {
22                         Databoard::Type::LongType* longType = dynamic_cast<Databoard::Type::LongType*>(dataBoard);
23
24                         if(longType != NULL)
25                         {
26                                 this->value = value;
27                         }
28                 }
29
30                 long LongValue::getValue()
31                 {
32                         return value;
33                 }
34
35                 std::string LongValue::writeOut(int /*indent*/)
36                 {
37                         std::string s;
38
39                         std::stringstream oss;
40
41                         oss << value;
42
43                         oss >> s;
44
45                         //if(unit.size() != 0)
46                         //{
47                         //      s += "(Unit=\"" + unit + "\")";
48                         //}
49
50                         return s;
51                 }
52
53                 bool LongValue::equals(const Value* other)
54                 {
55                         LongValue* o = (LongValue*)other;
56
57                         return (this->value < o->value);
58
59                 }
60
61                 std::string LongValue::isValid()
62                 {
63                         if(dataBoard == NULL)
64                         {
65                                 return "LongValue: There is no datatype.";
66                         }
67
68                         Databoard::Type::LongType* longType = (Databoard::Type::LongType*)dataBoard;
69
70                         if(longType->getRange() == NULL)
71                         {
72                                 return STR_EMPTY;
73                         }
74
75                         int minValue = longType->minValue();
76                         int maxValue = longType->maxValue();
77
78                         if(longType->getRange()->getLower()->getInclusive() == true)
79                         {
80                                 if(value < minValue)
81                                 {
82                                         return std::string("LongValue: ") + STR_ERROR_VALUE_SMALL;
83                                 }
84                         }
85                         else //if(longType->getRange()->getLower()->getInclusive() == false)
86                         {
87                                 if(value <= minValue)
88                                 {
89                                         return std::string("LongValue: ") + STR_ERROR_VALUE_SMALL;
90                                 }
91                         }
92
93                         if(longType->getRange()->getUpper()->getInclusive() == true)
94                         {
95                                 if(value > maxValue)
96                                 {
97                                         return std::string("LongValue: ") + STR_ERROR_VALUE_LARGE;
98                                 }
99                         }
100                         else //if(longType->getRange()->getUpper()->getInclusive() == false)
101                         {
102                                 if(value >= maxValue)
103                                 {
104                                         return std::string("LongValue: ") + STR_ERROR_VALUE_LARGE;
105                                 }
106                         }
107
108                         return STR_EMPTY;
109                 }
110         }
111 }