-#include "ArrayValue.h"\r
-\r
-#include "ArrayType.h"\r
-#include "Range.h"\r
-#include "Limit.h"\r
-\r
-#include "Constants.h"\r
-\r
-namespace Databoard {\r
- namespace Value {\r
- ArrayValue::ArrayValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)\r
- {\r
- }\r
-\r
- ArrayValue::~ArrayValue()\r
- {\r
- clear();\r
- }\r
-\r
- void ArrayValue::add(Value* value)\r
- {\r
- values.push_back(value);\r
- }\r
-\r
- //void insert(Value* value, int index);\r
- int ArrayValue::count()\r
- {\r
- return (int)values.size();\r
- }\r
-\r
- void ArrayValue::remove(int index, int count)\r
- {\r
- if(index >= 0 && (index+count) <= (int)values.size())\r
- {\r
- for(int i = index; i < count; ++i)\r
- {\r
- delete values.at(i);\r
- }\r
-\r
- values.erase(values.begin(), values.begin() + count);\r
- }\r
- }\r
-\r
- void ArrayValue::clear()\r
- {\r
- remove(0, count());\r
- }\r
- \r
- Value* ArrayValue::get(int index)\r
- {\r
- return values.at(index);\r
- }\r
-\r
- std::vector<Value*> ArrayValue::getAll()\r
- {\r
- std::vector<Value*> v;\r
-\r
- for(int i = 0; i < (int)values.size(); ++i)\r
- {\r
- v.push_back(values.at(i));\r
- }\r
-\r
- return v;\r
- }\r
-\r
-\r
- std::string ArrayValue::writeOut(int /*indent*/)\r
- {\r
- std::string s;\r
-\r
- s += "[";\r
-\r
- for(int i = 0; i < (int)values.size(); ++i)\r
- {\r
- s += values.at(i)->writeOut();\r
-\r
- if(i != ((int)values.size()-1))\r
- {\r
- s += ",";\r
- }\r
- }\r
-\r
- s += "]";\r
-\r
- return s;\r
- }\r
-\r
- bool ArrayValue::equals(const Value* other)\r
- {\r
- ArrayValue* o = (ArrayValue*)other;\r
-\r
- if(this->count() < o->count())\r
- {\r
- return true;\r
- }\r
- else if(this->count() > o->count())\r
- {\r
- return false;\r
- }\r
-\r
- //for(int i = 0; i <(int)this->count(); ++i)\r
- //{\r
- // if(this->getField(i) < o->getField(i))\r
- // {\r
- // return true;\r
- // }\r
- //}\r
-\r
- return true;//(this->value < o->value);\r
-\r
- }\r
-\r
- std::string ArrayValue::isValid()\r
- {\r
- Databoard::Type::ArrayType* arrayType = dynamic_cast<Databoard::Type::ArrayType*>(dataBoard);\r
-\r
- if(arrayType == NULL)\r
- {\r
- return "ArrayValue: type is not an array.";\r
- }\r
-\r
- Range* r = arrayType->getLength();\r
-\r
- int countMin = r->getLower()->getInteger(INT_MIN);\r
- int countMax = r->getUpper()->getInteger(INT_MAX);\r
-\r
- int count = (int)values.size();\r
-\r
- if(count < countMin)\r
- {\r
- return "ArrayValue: too few.";\r
- }\r
- else if(count > countMax)\r
- {\r
- return "ArrayValue: too many.";\r
- }\r
-\r
- return STR_EMPTY;\r
- }\r
- }\r
-}\r
+#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<Value*> ArrayValue::getAll()
+ {
+ std::vector<Value*> 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::Type::ArrayType*>(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;
+ }
+ }
+}