X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FStringValue.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FStringValue.cpp;h=a80c306673641cc91e92f2fad4094797bdb7a8bc;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 index 000000000..a80c30667 --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringValue.cpp @@ -0,0 +1,85 @@ +#include "StringValue.h" + +#include "Constants.h" +#include "StringType.h" + +//#define SLRE_REGEXP +#ifdef SLRE_REGEXP +#include "..\slre\slre.h" +#endif + +namespace Databoard { + namespace Value { + StringValue::StringValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) + { + } + + StringValue::~StringValue() + { + } + + void StringValue::setValue(std::string value) + { + this->value = value; + } + + std::string StringValue::getValue() + { + return value; + } + + std::string StringValue::writeOut(int /*indent*/) + { + std::string s; + + s += value; + + return s; + } + + std::string StringValue::isValid() + { + std::string retValue = STR_EMPTY; + +#ifdef SLRE_REGEXP + Databoard::Type::StringType* stringType = (Databoard::Type::StringType*)dataBoard; + + std::string p = stringType->getPattern(); + + if(p.length() > 0) + { + struct slre slre; + struct cap captures[4 + 1]; + + if (!slre_compile(&slre, p.c_str())) + { + retValue = "StringValue: pattern error."; // slre internal error + } + // todo: this is not working completely + else if (!slre_match(&slre, value.c_str(), value.length(), captures)) + { + retValue = "StringValue: value error."; + } + else + { + retValue = STR_EMPTY; + } + } + else + { + retValue = STR_EMPTY; + } +#endif + + return retValue; + } + + bool StringValue::equals(const Value* other) + { + StringValue* o = (StringValue*)other; + + return (this->value < o->value); + + } + } +}