]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringValue.cpp
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / StringValue.cpp
1 #include "StringValue.h"
2
3 #include "Constants.h"
4 #include "StringType.h"
5
6 //#define SLRE_REGEXP
7 #ifdef SLRE_REGEXP
8 #include "..\slre\slre.h"
9 #endif
10
11 namespace Databoard {
12         namespace Value {
13                 StringValue::StringValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)
14                 {
15                 }
16
17                 StringValue::~StringValue()
18                 {
19                 }
20
21                 void StringValue::setValue(std::string value)
22                 {
23                         this->value = value;
24                 }
25
26                 std::string StringValue::getValue()
27                 {
28                         return value;
29                 }
30
31                 std::string StringValue::writeOut(int /*indent*/)
32                 {
33                         std::string s;
34
35                         s += value;
36
37                         return s;
38                 }
39
40                 std::string StringValue::isValid()
41                 {
42                         std::string retValue = STR_EMPTY;
43
44 #ifdef SLRE_REGEXP
45                         Databoard::Type::StringType* stringType = (Databoard::Type::StringType*)dataBoard;
46
47                         std::string p = stringType->getPattern();
48
49                         if(p.length() > 0)
50                         {
51                                 struct slre        slre;
52                                 struct cap         captures[4 + 1];
53
54                                 if (!slre_compile(&slre, p.c_str()))
55                                 {
56                                         retValue = "StringValue: pattern error."; // slre internal error
57                                 }
58                                 // todo: this is not working completely
59                                 else if (!slre_match(&slre, value.c_str(), value.length(), captures))
60                                 {
61                                         retValue = "StringValue: value error.";
62                                 }
63                                 else
64                                 {
65                                         retValue = STR_EMPTY;
66                                 }
67                         }
68                         else
69                         {
70                                 retValue = STR_EMPTY;
71                         }
72 #endif
73
74                         return retValue;
75                 }
76
77                 bool StringValue::equals(const Value* other)
78                 {
79                         StringValue* o = (StringValue*)other;
80
81                         return (this->value < o->value);
82
83                 }
84         }
85 }