]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/Limit.cpp
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / Limit.cpp
1 #include "Limit.h"
2
3 #include "Constants.h"
4 #include <sstream>
5
6 #ifdef max
7 #undef max
8 #endif
9 #ifdef min
10 #undef min
11 #endif
12
13 #include <algorithm>
14
15 namespace Databoard {
16
17         Limit::Limit(bool isLower)
18         {
19                 this->isLower = isLower;
20                 isInclusive = false;
21         }
22
23         Limit::~Limit()
24         {
25         }
26
27         void Limit::setValue(std::string value)
28         {
29                 this->value = value;
30         }
31
32         std::string Limit::getValue()
33         {
34                 return value;
35         }
36
37         double Limit::getDouble(double value)
38         {
39                 if(this->value.size() > 0)
40                 {
41                         double c;
42
43                         std::istringstream iss(this->value);
44
45                         iss >> c;
46
47                         if(isLower == true)
48                         {
49                                 c = std::max(value, c);
50                         }
51                         else
52                         {
53                                 c = std::min(value, c);
54                         }
55
56                         return c;
57                 }
58                 else
59                 {
60                         return value;
61                 }
62         }
63
64         float Limit::getFloat(float value)
65         {
66                 if(this->value.size() > 0)
67                 {
68                         float c;
69
70                         std::istringstream iss(this->value);
71
72                         iss >> c;
73
74                         if(isLower == true)
75                         {
76                                 c = std::max(value, c);
77                         }
78                         else
79                         {
80                                 c = std::min(value, c);
81                         }
82
83                         return c;
84                 }
85                 else
86                 {
87                         return value;
88                 }
89         }
90
91         int Limit::getInteger(int value)
92         {
93                 if(this->value.size() > 0)
94                 {
95                         int c;
96
97                         std::istringstream iss(this->value);
98
99                         iss >> c;
100
101                         if(isLower == true)
102                         {
103                                 c = std::max(value, c);
104                         }
105                         else
106                         {
107                                 c = std::min(value, c);
108                         }
109
110                         return c;
111                 }
112                 else
113                 {
114                         return value;
115                 }
116         }
117
118         long Limit::getLong(long value)
119         {
120                 if(this->value.size() > 0)
121                 {
122                         long c;
123
124                         std::istringstream iss(this->value);
125
126                         iss >> c;
127
128                         if(isLower == true)
129                         {
130                                 c = std::max(value, c);
131                         }
132                         else
133                         {
134                                 c = std::min(value, c);
135                         }
136
137                         return c;
138                 }
139                 else
140                 {
141                         return value;
142                 }
143         }
144
145         char Limit::getByte(char value)
146         {
147                 if(this->value.size() > 0)
148                 {
149                         char c;
150
151                         std::istringstream iss(this->value);
152
153                         iss >> c;
154
155                         if(isLower == true)
156                         {
157                                 c = std::max(value, c);
158                         }
159                         else
160                         {
161                                 c = std::min(value, c);
162                         }
163
164                         return c;
165                 }
166                 else
167                 {
168                         return value;
169                 }
170         }
171
172         void Limit::setInclusive()
173         {
174                 isInclusive = true;
175         }
176
177         bool Limit::getInclusive()
178         {
179                 return isInclusive;
180         }
181
182         std::string Limit::writeOut()
183         {
184                 std::string s;
185
186                 if(isLower == true)
187                 {
188                         if(isInclusive == true)
189                         {
190                                 s += "[";
191                         }
192                         else
193                         {
194                                 s += "(";
195                         }
196                 }
197
198                 s += value;
199
200                 if(isLower == false)
201                 {
202                         if(isInclusive == true)
203                         {
204                                 s += "]";
205                         }
206                         else
207                         {
208                                 s += ")";
209                         }
210                 }
211
212                 return s;
213         }
214 }