]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringValue.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringValue.cpp
new file mode 100644 (file)
index 0000000..a80c306
--- /dev/null
@@ -0,0 +1,85 @@
+#include "StringValue.h"\r
+\r
+#include "Constants.h"\r
+#include "StringType.h"\r
+\r
+//#define SLRE_REGEXP\r
+#ifdef SLRE_REGEXP\r
+#include "..\slre\slre.h"\r
+#endif\r
+\r
+namespace Databoard {\r
+       namespace Value {\r
+               StringValue::StringValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)\r
+               {\r
+               }\r
+\r
+               StringValue::~StringValue()\r
+               {\r
+               }\r
+\r
+               void StringValue::setValue(std::string value)\r
+               {\r
+                       this->value = value;\r
+               }\r
+\r
+               std::string StringValue::getValue()\r
+               {\r
+                       return value;\r
+               }\r
+\r
+               std::string StringValue::writeOut(int /*indent*/)\r
+               {\r
+                       std::string s;\r
+\r
+                       s += value;\r
+\r
+                       return s;\r
+               }\r
+\r
+               std::string StringValue::isValid()\r
+               {\r
+                       std::string retValue = STR_EMPTY;\r
+\r
+#ifdef SLRE_REGEXP\r
+                       Databoard::Type::StringType* stringType = (Databoard::Type::StringType*)dataBoard;\r
+\r
+                       std::string p = stringType->getPattern();\r
+\r
+                       if(p.length() > 0)\r
+                       {\r
+                               struct slre        slre;\r
+                               struct cap         captures[4 + 1];\r
+\r
+                               if (!slre_compile(&slre, p.c_str()))\r
+                               {\r
+                                       retValue = "StringValue: pattern error."; // slre internal error\r
+                               }\r
+                               // todo: this is not working completely\r
+                               else if (!slre_match(&slre, value.c_str(), value.length(), captures))\r
+                               {\r
+                                       retValue = "StringValue: value error.";\r
+                               }\r
+                               else\r
+                               {\r
+                                       retValue = STR_EMPTY;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               retValue = STR_EMPTY;\r
+                       }\r
+#endif\r
+\r
+                       return retValue;\r
+               }\r
+\r
+               bool StringValue::equals(const Value* other)\r
+               {\r
+                       StringValue* o = (StringValue*)other;\r
+\r
+                       return (this->value < o->value);\r
+\r
+               }\r
+       }\r
+}\r