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