X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FLimit.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FLimit.cpp;h=3a861bf80d332e16b220cc7ed59b902c23b38243;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/Limit.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/Limit.cpp new file mode 100644 index 000000000..3a861bf80 --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/Limit.cpp @@ -0,0 +1,214 @@ +#include "Limit.h" + +#include "Constants.h" +#include + +#ifdef max +#undef max +#endif +#ifdef min +#undef min +#endif + +#include + +namespace Databoard { + + Limit::Limit(bool isLower) + { + this->isLower = isLower; + isInclusive = false; + } + + Limit::~Limit() + { + } + + void Limit::setValue(std::string value) + { + this->value = value; + } + + std::string Limit::getValue() + { + return value; + } + + double Limit::getDouble(double value) + { + if(this->value.size() > 0) + { + double c; + + std::istringstream iss(this->value); + + iss >> c; + + if(isLower == true) + { + c = std::max(value, c); + } + else + { + c = std::min(value, c); + } + + return c; + } + else + { + return value; + } + } + + float Limit::getFloat(float value) + { + if(this->value.size() > 0) + { + float c; + + std::istringstream iss(this->value); + + iss >> c; + + if(isLower == true) + { + c = std::max(value, c); + } + else + { + c = std::min(value, c); + } + + return c; + } + else + { + return value; + } + } + + int Limit::getInteger(int value) + { + if(this->value.size() > 0) + { + int c; + + std::istringstream iss(this->value); + + iss >> c; + + if(isLower == true) + { + c = std::max(value, c); + } + else + { + c = std::min(value, c); + } + + return c; + } + else + { + return value; + } + } + + long Limit::getLong(long value) + { + if(this->value.size() > 0) + { + long c; + + std::istringstream iss(this->value); + + iss >> c; + + if(isLower == true) + { + c = std::max(value, c); + } + else + { + c = std::min(value, c); + } + + return c; + } + else + { + return value; + } + } + + char Limit::getByte(char value) + { + if(this->value.size() > 0) + { + char c; + + std::istringstream iss(this->value); + + iss >> c; + + if(isLower == true) + { + c = std::max(value, c); + } + else + { + c = std::min(value, c); + } + + return c; + } + else + { + return value; + } + } + + void Limit::setInclusive() + { + isInclusive = true; + } + + bool Limit::getInclusive() + { + return isInclusive; + } + + std::string Limit::writeOut() + { + std::string s; + + if(isLower == true) + { + if(isInclusive == true) + { + s += "["; + } + else + { + s += "("; + } + } + + s += value; + + if(isLower == false) + { + if(isInclusive == true) + { + s += "]"; + } + else + { + s += ")"; + } + } + + return s; + } +}