diff --git a/uppsrc/Core/Value.cpp b/uppsrc/Core/Value.cpp index c88c7067c..bec37e77f 100644 --- a/uppsrc/Core/Value.cpp +++ b/uppsrc/Core/Value.cpp @@ -610,6 +610,26 @@ const Value& Value::operator[](int i) const return ErrorValue(); } +const Vector& Value::GetVA() const +{ + if(IsRef()) { + dword t = ptr()->GetType(); + if(t == VALUEARRAY_V) + return ((ValueArray::Data *)ptr())->data; + } + return ValueArray::VoidData; +} + +Value::ConstIterator Value::Begin() const +{ + return GetVA().Begin(); +} + +Value::ConstIterator Value::End() const +{ + return GetVA().End(); +} + Vector& Value::CloneArray() { ValueArray::Data *data = (ValueArray::Data *)ptr(); diff --git a/uppsrc/Core/Value.h b/uppsrc/Core/Value.h index 01deaf5e7..43383b139 100644 --- a/uppsrc/Core/Value.h +++ b/uppsrc/Core/Value.h @@ -177,6 +177,8 @@ protected: int PolyCompare(const Value& v) const; Vector& CloneArray(); + + const Vector& GetVA() const; #if defined(_DEBUG) && defined(COMPILER_GCC) uint32 magic[4]; @@ -274,6 +276,18 @@ public: const Void *GetVoidPtr() const { ASSERT(IsRef()); return ptr(); } friend void Swap(Value& a, Value& b) { Swap(a.data, b.data); } + + typedef Vector::ConstIterator ConstIterator; + ConstIterator Begin() const; + ConstIterator End() const; + + typedef Value value_type; + typedef ConstIterator const_iterator; + typedef const Value& const_reference; + typedef int size_type; + typedef int difference_type; + const_iterator begin() const { return Begin(); } + const_iterator end() const { return End(); } }; struct ValueTypeError : Exc { diff --git a/uppsrc/Core/Value.hpp b/uppsrc/Core/Value.hpp index c81fcbb89..ae6977d67 100644 --- a/uppsrc/Core/Value.hpp +++ b/uppsrc/Core/Value.hpp @@ -6,7 +6,7 @@ Value::Value(const Value& v) SetLarge(v); else data.SetSmall(v.data); - Magic(); + Magic(); } template<> @@ -266,7 +266,7 @@ inline bool Value::Is() const return IsVoid(); if(t == INT_V || t == INT64_V || t == DOUBLE_V || t == BOOL_V || t == DATE_V || t == TIME_V) - return Is((byte)t); + return Is((byte)t); return t < 255 && Is((byte)t) || IsRef() && ptr()->GetType() == t; } @@ -358,7 +358,7 @@ inline T& CreateRawValue(Value& v) { typedef RawValueRep R; R *r = new R; v = Value(r); - return r->Get(); + return r->Get(); } template diff --git a/uppsrc/Core/ValueUtil.cpp b/uppsrc/Core/ValueUtil.cpp index 7f6ed8fe4..3b36f547b 100644 --- a/uppsrc/Core/ValueUtil.cpp +++ b/uppsrc/Core/ValueUtil.cpp @@ -112,6 +112,8 @@ String ValueArray::Data::AsString() const return sAsString(data); } +Vector ValueArray::VoidData; + Vector& ValueArray::Create() { data = new Data; diff --git a/uppsrc/Core/ValueUtil.h b/uppsrc/Core/ValueUtil.h index fcc71f5bb..0b2f0ed4a 100644 --- a/uppsrc/Core/ValueUtil.h +++ b/uppsrc/Core/ValueUtil.h @@ -214,6 +214,8 @@ class ValueArray : public ValueType VoidData; Vector& Create(); Vector& Clone(); @@ -254,7 +256,7 @@ public: void Set(int i, const Value& v); const Value& Get(int i) const; Value GetAndClear(int i); - const Vector& Get() const { return data->data; } + const Vector& Get() const { return data ? data->data : VoidData; } Vector Pick(); void Remove(int i, int count = 1); @@ -280,6 +282,18 @@ public: bool operator>=(const ValueArray& x) const { return Compare(x) >= 0; } bool operator<(const ValueArray& x) const { return Compare(x) < 0; } bool operator>(const ValueArray& x) const { return Compare(x) > 0; } + + typedef Vector::ConstIterator ConstIterator; + ConstIterator Begin() const { return Get().Begin(); } + ConstIterator End() const { return Get().End(); } + + typedef Value value_type; + typedef ConstIterator const_iterator; + typedef const Value& const_reference; + typedef int size_type; + typedef int difference_type; + const_iterator begin() const { return Begin(); } + const_iterator end() const { return End(); } }; template<> diff --git a/uppsrc/Core/XML.h b/uppsrc/Core/XML.h index 4fd34eab5..9a2ec6501 100644 --- a/uppsrc/Core/XML.h +++ b/uppsrc/Core/XML.h @@ -230,8 +230,20 @@ public: rval_default(XmlNode); XmlNode(const XmlNode& n, int); + + XmlNode() { type = XML_DOC; } - XmlNode() { type = XML_DOC; } + typedef Array::ConstIterator ConstIterator; + ConstIterator Begin() const { return node.Begin(); } + ConstIterator End() const { return node.End(); } + + typedef XmlNode value_type; + typedef ConstIterator const_iterator; + typedef const XmlNode& const_reference; + typedef int size_type; + typedef int difference_type; + const_iterator begin() const { return Begin(); } + const_iterator end() const { return End(); } }; enum {