-#include "MapValue.h"\r
-\r
-#include <iostream>\r
-\r
-#include "IntegerValue.h"\r
-#include "Constants.h"\r
-\r
-namespace Databoard {\r
- namespace Value {\r
-\r
- MapValue::MapValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)\r
- {\r
- }\r
-\r
- MapValue::~MapValue()\r
- {\r
- for(MKVMap::iterator it = values.begin(); it != values.end(); ++it)\r
- {\r
- delete it->first;\r
- delete it->second;\r
- }\r
-\r
- values.clear();\r
- }\r
-\r
- bool MapValue::put(Value* key, Value* value)\r
- {\r
- if(containsKey(key) == false)\r
- {\r
- values[key] = value;\r
-\r
- return true;\r
- }\r
- else\r
- {\r
- MKVMap::iterator it = values.find(key);\r
-\r
- delete it->first;\r
- delete it->second;\r
-\r
- values.erase(it);\r
-\r
- values[key] = value;\r
-\r
- return false;\r
- }\r
- }\r
-\r
- int MapValue::count()\r
- {\r
- return (int)values.size();\r
- }\r
-\r
- Value* MapValue::get(Value* key)\r
- {\r
- if(containsKey(key) == true)\r
- {\r
- return values[key];\r
- }\r
- else\r
- {\r
- return false;\r
- }\r
- }\r
-\r
- bool MapValue::containsKey(Value* key)\r
- {\r
- return (values.find(key) != values.end());\r
- }\r
-\r
- Value* MapValue::remove(Value* key)\r
- {\r
- if(containsKey(key) == true)\r
- {\r
- Value* oldValue = values[key];\r
-\r
- values.erase(key);\r
-\r
- return oldValue;\r
- }\r
- else\r
- {\r
- return NULL;\r
- }\r
- }\r
-\r
- void MapValue::removeRange(Value* startKey, Value* endKey)\r
- {\r
- if(containsKey(startKey) && containsKey(endKey))\r
- {\r
- MKVMap::iterator iBegin = values.find(startKey);\r
- MKVMap::iterator iEnd = values.find(endKey);\r
-\r
- int indexBegin = -1;\r
- int indexEnd = -1;\r
-\r
- int i = 0;\r
-\r
- for(MKVMap::iterator it = values.begin(); it != values.end(); ++i, ++it)\r
- {\r
- if(it == iBegin)\r
- {\r
- indexBegin = i;\r
- }\r
-\r
- if(it == iEnd)\r
- {\r
- indexEnd = i;\r
- }\r
- }\r
-\r
- if(indexBegin == -1 || indexEnd == -1 ||\r
- (indexBegin > indexEnd))\r
- {\r
- return;\r
- }\r
-\r
- MKVMap::iterator it = values.begin();\r
-\r
- for(int j = 0; j < indexBegin; ++j)\r
- {\r
- ++it;\r
- }\r
-\r
- for(i = indexBegin; i < indexEnd; ++i)\r
- {\r
- delete it->first;\r
- delete it->second;\r
-\r
- ++it;\r
- }\r
-\r
- values.erase(iBegin, iEnd);\r
- }\r
- }\r
-\r
- void MapValue::clear()\r
- {\r
- values.clear();\r
- }\r
-\r
- std::string MapValue::writeOut(int /*indent*/)\r
- {\r
- std::string s;\r
-\r
- s += "map { ";\r
-\r
- // counter is inside the block\r
- for(MKVMap::iterator it = values.begin(); it != values.end(); )\r
- {\r
- s += it->first->writeOut();\r
- s += " = ";\r
- s += it->second->writeOut();\r
-\r
- if(++it != values.end())\r
- {\r
- s += ", ";\r
- }\r
- }\r
-\r
- s += " }";\r
-\r
- return s;\r
- }\r
-\r
- bool MapValue::equals(const Value* other)\r
- {\r
- MapValue* o = (MapValue*)other;\r
-\r
- return true;//(this->value < o->value);\r
-\r
- }\r
-\r
- std::string MapValue::isValid()\r
- {\r
- for(MKVMap::iterator it = values.begin(); it != values.end(); ++it)\r
- {\r
- std::string s;\r
- \r
- s = it->first->isValid();\r
-\r
- if(s.length() > 0)\r
- {\r
- return s;\r
- }\r
-\r
- s = it->second->isValid();\r
-\r
- if(s.length() > 0)\r
- {\r
- return s;\r
- }\r
- }\r
-\r
- return STR_EMPTY;\r
- }\r
-\r
- bool ValueComparison::operator()(Value* const &a, Value* const &b) const\r
- {\r
- return a->equals(b);\r
- }\r
- }\r
-}\r
+#include "MapValue.h"
+
+#include <iostream>
+
+#include "IntegerValue.h"
+#include "Constants.h"
+
+namespace Databoard {
+ namespace Value {
+
+ MapValue::MapValue(Databoard::Type::DataType* dataBoard) : Value(dataBoard)
+ {
+ }
+
+ MapValue::~MapValue()
+ {
+ for(MKVMap::iterator it = values.begin(); it != values.end(); ++it)
+ {
+ delete it->first;
+ delete it->second;
+ }
+
+ values.clear();
+ }
+
+ bool MapValue::put(Value* key, Value* value)
+ {
+ if(containsKey(key) == false)
+ {
+ values[key] = value;
+
+ return true;
+ }
+ else
+ {
+ MKVMap::iterator it = values.find(key);
+
+ delete it->first;
+ delete it->second;
+
+ values.erase(it);
+
+ values[key] = value;
+
+ return false;
+ }
+ }
+
+ int MapValue::count()
+ {
+ return (int)values.size();
+ }
+
+ Value* MapValue::get(Value* key)
+ {
+ if(containsKey(key) == true)
+ {
+ return values[key];
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ bool MapValue::containsKey(Value* key)
+ {
+ return (values.find(key) != values.end());
+ }
+
+ Value* MapValue::remove(Value* key)
+ {
+ if(containsKey(key) == true)
+ {
+ Value* oldValue = values[key];
+
+ values.erase(key);
+
+ return oldValue;
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+
+ void MapValue::removeRange(Value* startKey, Value* endKey)
+ {
+ if(containsKey(startKey) && containsKey(endKey))
+ {
+ MKVMap::iterator iBegin = values.find(startKey);
+ MKVMap::iterator iEnd = values.find(endKey);
+
+ int indexBegin = -1;
+ int indexEnd = -1;
+
+ int i = 0;
+
+ for(MKVMap::iterator it = values.begin(); it != values.end(); ++i, ++it)
+ {
+ if(it == iBegin)
+ {
+ indexBegin = i;
+ }
+
+ if(it == iEnd)
+ {
+ indexEnd = i;
+ }
+ }
+
+ if(indexBegin == -1 || indexEnd == -1 ||
+ (indexBegin > indexEnd))
+ {
+ return;
+ }
+
+ MKVMap::iterator it = values.begin();
+
+ for(int j = 0; j < indexBegin; ++j)
+ {
+ ++it;
+ }
+
+ for(i = indexBegin; i < indexEnd; ++i)
+ {
+ delete it->first;
+ delete it->second;
+
+ ++it;
+ }
+
+ values.erase(iBegin, iEnd);
+ }
+ }
+
+ void MapValue::clear()
+ {
+ values.clear();
+ }
+
+ std::string MapValue::writeOut(int /*indent*/)
+ {
+ std::string s;
+
+ s += "map { ";
+
+ // counter is inside the block
+ for(MKVMap::iterator it = values.begin(); it != values.end(); )
+ {
+ s += it->first->writeOut();
+ s += " = ";
+ s += it->second->writeOut();
+
+ if(++it != values.end())
+ {
+ s += ", ";
+ }
+ }
+
+ s += " }";
+
+ return s;
+ }
+
+ bool MapValue::equals(const Value* other)
+ {
+ MapValue* o = (MapValue*)other;
+
+ return true;//(this->value < o->value);
+
+ }
+
+ std::string MapValue::isValid()
+ {
+ for(MKVMap::iterator it = values.begin(); it != values.end(); ++it)
+ {
+ std::string s;
+
+ s = it->first->isValid();
+
+ if(s.length() > 0)
+ {
+ return s;
+ }
+
+ s = it->second->isValid();
+
+ if(s.length() > 0)
+ {
+ return s;
+ }
+ }
+
+ return STR_EMPTY;
+ }
+
+ bool ValueComparison::operator()(Value* const &a, Value* const &b) const
+ {
+ return a->equals(b);
+ }
+ }
+}