1 #include "ArrayValue.h"
11 ArrayValue::ArrayValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)
15 ArrayValue::~ArrayValue()
20 void ArrayValue::add(Value* value)
22 values.push_back(value);
25 //void insert(Value* value, int index);
26 int ArrayValue::count()
28 return (int)values.size();
31 void ArrayValue::remove(int index, int count)
33 if(index >= 0 && (index+count) <= (int)values.size())
35 for(int i = index; i < count; ++i)
40 values.erase(values.begin(), values.begin() + count);
44 void ArrayValue::clear()
49 Value* ArrayValue::get(int index)
51 return values.at(index);
54 std::vector<Value*> ArrayValue::getAll()
56 std::vector<Value*> v;
58 for(int i = 0; i < (int)values.size(); ++i)
60 v.push_back(values.at(i));
67 std::string ArrayValue::writeOut(int /*indent*/)
73 for(int i = 0; i < (int)values.size(); ++i)
75 s += values.at(i)->writeOut();
77 if(i != ((int)values.size()-1))
88 bool ArrayValue::equals(const Value* other)
90 ArrayValue* o = (ArrayValue*)other;
92 if(this->count() < o->count())
96 else if(this->count() > o->count())
101 //for(int i = 0; i <(int)this->count(); ++i)
103 // if(this->getField(i) < o->getField(i))
109 return true;//(this->value < o->value);
113 std::string ArrayValue::isValid()
115 Databoard::Type::ArrayType* arrayType = dynamic_cast<Databoard::Type::ArrayType*>(dataBoard);
117 if(arrayType == NULL)
119 return "ArrayValue: type is not an array.";
122 Range* r = arrayType->getLength();
124 int countMin = r->getLower()->getInteger(INT_MIN);
125 int countMax = r->getUpper()->getInteger(INT_MAX);
127 int count = (int)values.size();
131 return "ArrayValue: too few.";
133 else if(count > countMax)
135 return "ArrayValue: too many.";