X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FStringType.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FStringType.cpp;h=5d6e2aa3441e6138d1ccd8c6641735e6f5875f84;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringType.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringType.cpp new file mode 100644 index 000000000..5d6e2aa34 --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/StringType.cpp @@ -0,0 +1,120 @@ +#include "StringType.h" + +#include "Range.h" +#include "Limit.h" + +#include + +namespace Databoard { + namespace Type { + + StringType::StringType() + { + this->length = NULL; + } + + StringType::StringType(std::string pattern) + { + this->pattern = pattern; + this->length = NULL; + } + + StringType::StringType(std::string pattern, std::string mimeType, Range* length) + { + this->pattern = pattern; + this->mimeType = mimeType; + this->length = length; + } + + StringType::~StringType() + { + if(length != NULL) + { + delete length; + } + } + + std::string StringType::getPattern() + { + return pattern; + } + + void StringType::setPattern(std::string pattern) + { + this->pattern = pattern; + } + + std::string StringType::getMimeType() + { + return mimeType; + } + + void StringType::setMimeType(std::string mimeType) + { + this->mimeType = mimeType; + } + + Range* StringType::getLength() + { + return length; + } + + void StringType::setLength(Range* length) + { + this->length = length; + } + + int StringType::minLength() + { + if(length == NULL) return 0; + + return length->getLower()->getInteger(INT_MAX); + } + + int StringType::maxLength() + { + if(length == NULL) return INT_MAX; + + return length->getUpper()->getInteger(INT_MIN); + } + + std::string StringType::writeOut(int /*indent*/) + { + std::string s; + + s.append("String"); + + bool parenthesis = false; + + if(mimeType.size() > 0) + { + s += "(mimeType=\"" + mimeType + "\""; + + parenthesis = true; + } + + if(pattern.size() > 0) + { + if(parenthesis == false) + { + s += "("; + } + else + { + s += ", "; + } + + s += "pattern=\"" + pattern + "\""; + + parenthesis = true; + } + + if(parenthesis == true) + { + s += ")"; + } + + return s; + } + } +}