X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FArrayValue.cpp;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FArrayValue.cpp;h=c8b9c496d30f5e899de6c8f80ab80adc26d04844;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=2fc0e5df53b0b5a4b50cd5347ebfefbc3c28d32c;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/ArrayValue.cpp b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/ArrayValue.cpp index 2fc0e5df5..c8b9c496d 100644 --- a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/ArrayValue.cpp +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/ArrayValue.cpp @@ -1,141 +1,141 @@ -#include "ArrayValue.h" - -#include "ArrayType.h" -#include "Range.h" -#include "Limit.h" - -#include "Constants.h" - -namespace Databoard { - namespace Value { - ArrayValue::ArrayValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) - { - } - - ArrayValue::~ArrayValue() - { - clear(); - } - - void ArrayValue::add(Value* value) - { - values.push_back(value); - } - - //void insert(Value* value, int index); - int ArrayValue::count() - { - return (int)values.size(); - } - - void ArrayValue::remove(int index, int count) - { - if(index >= 0 && (index+count) <= (int)values.size()) - { - for(int i = index; i < count; ++i) - { - delete values.at(i); - } - - values.erase(values.begin(), values.begin() + count); - } - } - - void ArrayValue::clear() - { - remove(0, count()); - } - - Value* ArrayValue::get(int index) - { - return values.at(index); - } - - std::vector ArrayValue::getAll() - { - std::vector v; - - for(int i = 0; i < (int)values.size(); ++i) - { - v.push_back(values.at(i)); - } - - return v; - } - - - std::string ArrayValue::writeOut(int /*indent*/) - { - std::string s; - - s += "["; - - for(int i = 0; i < (int)values.size(); ++i) - { - s += values.at(i)->writeOut(); - - if(i != ((int)values.size()-1)) - { - s += ","; - } - } - - s += "]"; - - return s; - } - - bool ArrayValue::equals(const Value* other) - { - ArrayValue* o = (ArrayValue*)other; - - if(this->count() < o->count()) - { - return true; - } - else if(this->count() > o->count()) - { - return false; - } - - //for(int i = 0; i <(int)this->count(); ++i) - //{ - // if(this->getField(i) < o->getField(i)) - // { - // return true; - // } - //} - - return true;//(this->value < o->value); - - } - - std::string ArrayValue::isValid() - { - Databoard::Type::ArrayType* arrayType = dynamic_cast(dataBoard); - - if(arrayType == NULL) - { - return "ArrayValue: type is not an array."; - } - - Range* r = arrayType->getLength(); - - int countMin = r->getLower()->getInteger(INT_MIN); - int countMax = r->getUpper()->getInteger(INT_MAX); - - int count = (int)values.size(); - - if(count < countMin) - { - return "ArrayValue: too few."; - } - else if(count > countMax) - { - return "ArrayValue: too many."; - } - - return STR_EMPTY; - } - } -} +#include "ArrayValue.h" + +#include "ArrayType.h" +#include "Range.h" +#include "Limit.h" + +#include "Constants.h" + +namespace Databoard { + namespace Value { + ArrayValue::ArrayValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard) + { + } + + ArrayValue::~ArrayValue() + { + clear(); + } + + void ArrayValue::add(Value* value) + { + values.push_back(value); + } + + //void insert(Value* value, int index); + int ArrayValue::count() + { + return (int)values.size(); + } + + void ArrayValue::remove(int index, int count) + { + if(index >= 0 && (index+count) <= (int)values.size()) + { + for(int i = index; i < count; ++i) + { + delete values.at(i); + } + + values.erase(values.begin(), values.begin() + count); + } + } + + void ArrayValue::clear() + { + remove(0, count()); + } + + Value* ArrayValue::get(int index) + { + return values.at(index); + } + + std::vector ArrayValue::getAll() + { + std::vector v; + + for(int i = 0; i < (int)values.size(); ++i) + { + v.push_back(values.at(i)); + } + + return v; + } + + + std::string ArrayValue::writeOut(int /*indent*/) + { + std::string s; + + s += "["; + + for(int i = 0; i < (int)values.size(); ++i) + { + s += values.at(i)->writeOut(); + + if(i != ((int)values.size()-1)) + { + s += ","; + } + } + + s += "]"; + + return s; + } + + bool ArrayValue::equals(const Value* other) + { + ArrayValue* o = (ArrayValue*)other; + + if(this->count() < o->count()) + { + return true; + } + else if(this->count() > o->count()) + { + return false; + } + + //for(int i = 0; i <(int)this->count(); ++i) + //{ + // if(this->getField(i) < o->getField(i)) + // { + // return true; + // } + //} + + return true;//(this->value < o->value); + + } + + std::string ArrayValue::isValid() + { + Databoard::Type::ArrayType* arrayType = dynamic_cast(dataBoard); + + if(arrayType == NULL) + { + return "ArrayValue: type is not an array."; + } + + Range* r = arrayType->getLength(); + + int countMin = r->getLower()->getInteger(INT_MIN); + int countMax = r->getUpper()->getInteger(INT_MAX); + + int count = (int)values.size(); + + if(count < countMin) + { + return "ArrayValue: too few."; + } + else if(count > countMax) + { + return "ArrayValue: too many."; + } + + return STR_EMPTY; + } + } +}