*Core: fixed ValueMap[0] issue

git-svn-id: svn://ultimatepp.org/upp/trunk@5609 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-12-01 13:04:56 +00:00
parent 1c23564b48
commit e4e283fccd
2 changed files with 83 additions and 43 deletions

View file

@ -285,7 +285,7 @@ class ValueMap : ValueType<ValueMap, VALUEMAP_V, Moveable<ValueMap> >{
friend class Value;
public:
ValueMap() { Init0(); }
ValueMap() { Init0(); }
ValueMap(const ValueMap& v);
ValueMap(pick_ Index<Value>& k, pick_ Vector<Value>& v);
ValueMap(const Index<Value>& k, const Vector<Value>& v, int deep);
@ -296,61 +296,62 @@ public:
operator Value() const;
ValueMap(const Value& src);
ValueMap(const Nuller&) { Init0(); }
bool IsNullInstance() const { return IsEmpty(); }
ValueMap(const Nuller&) { Init0(); }
bool IsNullInstance() const { return IsEmpty(); }
void Clear();
int GetCount() const { return data->value.GetCount(); }
bool IsEmpty() const { return data->value.IsEmpty(); }
const Value& GetKey(int i) const { return data->key[i]; }
const Value& GetValue(int i) const { return data->value[i]; }
int GetCount() const { return data->value.GetCount(); }
bool IsEmpty() const { return data->value.IsEmpty(); }
const Value& GetKey(int i) const { return data->key[i]; }
const Value& GetValue(int i) const { return data->value[i]; }
void Add(const Value& key, const Value& value);
void Add(const String& s, const Value& value) { Add(Value(s), value); }
void Add(const char *s, const Value& value) { Add(Value(s), value); }
void Add(int q, const Value& value) { Add(Value(q), value); }
void Add(Id id, const Value& value) { Add(Value(id.ToString()), value); }
void Add(const String& key, const Value& value) { Add(Value(key), value); }
void Add(const char *key, const Value& value) { Add(Value(key), value); }
void Add(int key, const Value& value) { Add(Value(key), value); }
void Add(Id key, const Value& value) { Add(Value(key.ToString()), value); }
void Set(const Value& key, const Value& value);
void Set(const String& s, const Value& value) { Set(Value(s), value); }
void Set(const char *s, const Value& value) { Set(Value(s), value); }
void Set(int q, const Value& value) { Set(Value(q), value); }
void Set(Id id, const Value& value) { Set(Value(id.ToString()), value); }
void Set(const String& key, const Value& value) { Set(Value(key), value); }
void Set(const char *key, const Value& value) { Set(Value(key), value); }
void Set(int key, const Value& value) { Set(Value(key), value); }
void Set(Id key, const Value& value) { Set(Value(key.ToString()), value); }
void SetAt(int i, const Value& v);
void SetKey(int i, const Value& k);
void SetKey(int i, const String& s) { SetKey(i, Value(s)); }
void SetKey(int i, const char* s) { SetKey(i, Value(s)); }
void SetKey(int i, int q) { SetKey(i, Value(q)); }
void SetKey(int i, Id id) { SetKey(i, Value(id.ToString())); }
void SetKey(int i, const Value& key);
void SetKey(int i, const String& key) { SetKey(i, Value(key)); }
void SetKey(int i, const char* key) { SetKey(i, Value(key)); }
void SetKey(int i, int key) { SetKey(i, Value(key)); }
void SetKey(int i, Id key) { SetKey(i, Value(key.ToString())); }
void Remove(int i);
const Index<Value>& GetKeys() const { return data->key; }
ValueArray GetValues() const { return data->value; }
const Index<Value>& GetKeys() const { return data->key; }
ValueArray GetValues() const { return data->value; }
operator ValueArray() const { return GetValues(); }
operator ValueArray() const { return GetValues(); }
const Value& operator[](const Value& k) const;
const Value& operator[](const String& s) const{ return operator[](Value(s)); }
const Value& operator[](const char *s) const { return operator[](Value(s)); }
const Value& operator[](const Id& k) const { return operator[](Value(k.ToString())); }
const Value& operator[](const Value& key) const;
const Value& operator[](const String& key) const { return operator[](Value(key)); }
const Value& operator[](const char *key) const { return operator[](Value(key)); }
const Value& operator[](const int key) const { return operator[](Value(key)); }
const Value& operator[](const Id& key) const { return operator[](Value(key.ToString())); }
Value GetAndClear(const Value& key);
unsigned GetHashValue() const { return data->GetHashValue(); }
unsigned GetHashValue() const { return data->GetHashValue(); }
void Serialize(Stream& s);
void Jsonize(JsonIO& jio);
void Xmlize(XmlIO& xio);
String ToString() const { return data->AsString(); }
String ToString() const { return data->AsString(); }
bool operator==(const ValueMap& v) const;
bool operator!=(const ValueMap& v) const { return !operator==(v); }
bool operator!=(const ValueMap& v) const { return !operator==(v); }
};
class ValueGen {
public:
virtual Value Get() = 0;
Value operator++() { return Get(); }
Value operator++() { return Get(); }
virtual ~ValueGen() {}
};

View file

@ -114,17 +114,39 @@ etKey]([@(0.0.255) int]_[*@3 i])_[@(0.0.255) const]&]
[s5;:ValueMap`:`:Add`(const Value`&`,const Value`&`):%- [@(0.0.255) void]_[* Add]([@(0.0.255) c
onst]_[_^Value^ Value][@(0.0.255) `&]_[*@3 key], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[*@3 value])&]
[s5;:ValueMap`:`:Add`(const String`&`,const Value`&`):%- [@(0.0.255) void]_[* Add]([@(0.0.255) c
onst]_[_^String^ String][@(0.0.255) `&]_[*@3 key], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[*@3 value])&]
[s5;:ValueMap`:`:Add`(const char`*`,const Value`&`):%- [@(0.0.255) void]_[* Add]([@(0.0.255) c
onst]_[@(0.0.255) char]_`*[*@3 key], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 v
alue])&]
[s5;:ValueMap`:`:Add`(int`,const Value`&`):%- [@(0.0.255) void]_[* Add]([@(0.0.255) int]_[*@3 k
ey], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 value])&]
[s5;:ValueMap`:`:Add`(Id`,const Value`&`):%- [@(0.0.255) void]_[* Add]([_^Id^ Id]_[*@3 key],
[@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 value])&]
[s2;%- Adds a new key`-value pair to ValueMap. ValueMap can contain
multiple same keys.&]
[s3;%- &]
multiple same keys. Note: multiple overloads are required to make
Id and SqlId work with ValueMap.&]
[s3; &]
[s4;%- &]
[s5;:ValueMap`:`:Set`(const Value`&`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) c
onst]_[_^Value^ Value][@(0.0.255) `&]_[*@3 key], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[*@3 value])&]
[s2; If there is [%-*@3 key] in ValueMap, its associated Value is replaced
by [%-*@3 value]. If there is none such key, key`-value is added.
If there is more than single such key, only first one (the one
with lowest index) is replaced.&]
[s5;:ValueMap`:`:Set`(const String`&`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) c
onst]_[_^String^ String][@(0.0.255) `&]_[*@3 s], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[*@3 value])&]
[s5;:ValueMap`:`:Set`(const char`*`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) c
onst]_[@(0.0.255) char]_`*[*@3 s], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 va
lue])&]
[s5;:ValueMap`:`:Set`(int`,const Value`&`):%- [@(0.0.255) void]_[* Set]([@(0.0.255) int]_[*@3 q
], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 value])&]
[s5;:ValueMap`:`:Set`(Id`,const Value`&`):%- [@(0.0.255) void]_[* Set]([_^Id^ Id]_[*@3 id],
[@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 value])&]
[s2;%- [%% If there is ][*@3 key][%% in ValueMap, its associated Value
is replaced by ][*@3 value][%% . If there is none such key, key`-value
is added. If there is more than single such key, only first one
(the one with lowest index) is replaced. ]Note: multiple overloads
are required to make Id and SqlId work with ValueMap.&]
[s3; &]
[s4;%- &]
[s5;:ValueMap`:`:SetAt`(int`,const Value`&`):%- [@(0.0.255) void]_[* SetAt]([@(0.0.255) int
@ -134,7 +156,16 @@ with lowest index) is replaced.&]
[s4;%- &]
[s5;:ValueMap`:`:SetKey`(int`,const Value`&`):%- [@(0.0.255) void]_[* SetKey]([@(0.0.255) i
nt]_[*@3 i], [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&]_[*@3 key])&]
[s2; Replaces key at given index..&]
[s5;:ValueMap`:`:SetKey`(int`,const String`&`):%- [@(0.0.255) void]_[* SetKey]([@(0.0.255) i
nt]_[*@3 i], [@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 key])&]
[s5;:ValueMap`:`:SetKey`(int`,const char`*`):%- [@(0.0.255) void]_[* SetKey]([@(0.0.255) in
t]_[*@3 i], [@(0.0.255) const]_[@(0.0.255) char`*]_[*@3 key])&]
[s5;:ValueMap`:`:SetKey`(int`,int`):%- [@(0.0.255) void]_[* SetKey]([@(0.0.255) int]_[*@3 i],
[@(0.0.255) int]_[*@3 key])&]
[s5;:ValueMap`:`:SetKey`(int`,Id`):%- [@(0.0.255) void]_[* SetKey]([@(0.0.255) int]_[*@3 i],
[_^Id^ Id]_[*@3 key])&]
[s2;%- [%% Replaces key at given index. ]Note: multiple overloads are
required to make Id and SqlId work with ValueMap.&]
[s3; &]
[s4;%- &]
[s5;:ValueMap`:`:Remove`(int`):%- [@(0.0.255) void]_[* Remove]([@(0.0.255) int]_[*@3 i])&]
@ -163,16 +194,24 @@ nst]&]
e][@(0.0.255) `&]_[* operator`[`]]([@(0.0.255) const]_[_^String^ String][@(0.0.255) `&]_[*@3 s
])_[@(0.0.255) const]&]
[s5;:ValueMap`:`:operator`[`]`(const char`*`)const:%- [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[* operator`[`]]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 s])_[@(0.0.255) const]&]
]_[* operator`[`]]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 key])_[@(0.0.255) const]&]
[s5;:ValueMap`:`:operator`[`]`(const Id`&`)const:%- [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[* operator`[`]]([@(0.0.255) const]_[_^Id^ Id][@(0.0.255) `&]_[*@3 k])_[@(0.0.255) const]&]
[s2; Returns value for [%-*@3 key]. If [%-*@3 key] is not present, returns
void Value.&]
]_[* operator`[`]]([@(0.0.255) const]_[_^Id^ Id][@(0.0.255) `&]_[*@3 key])_[@(0.0.255) const]&]
[s5;:ValueMap`:`:operator`[`]`(const int`)const:%- [@(0.0.255) const]_[_^Value^ Value][@(0.0.255) `&
]_[* operator`[`]]([@(0.0.255) const]_[@(0.0.255) int]_[*@3 key])_[@(0.0.255) const]&]
[s2;%- [%% Returns value for ][*@3 key][%% . If ][*@3 key][%% is not present,
returns void Value. ]Note: multiple overloads are required to
make Id and SqlId work with ValueMap.&]
[s3; &]
[s4;%- &]
[s5;:ValueMap`:`:GetAndClear`(const Value`&`):%- [_^Value^ Value]_[* GetAndClear]([@(0.0.255) c
onst]_[_^Value^ Value][@(0.0.255) `&]_[*@3 key])&]
[s2; [%-*@3 key] .&]
[s2; If [%-*@3 key] is not present, returns void Value, otherwise returns
value for [%-*@3 key] and sets it to void Value. The purpose of
this processing is to optimize copying in situation when complex
value (e.g. ValueArray) is about to be changed after retrieval,
without clearing it in ValueMap the deep copy of complex structure
would have to be performed when changing it.&]
[s3; &]
[s4;%- &]
[s5;:ValueMap`:`:GetHashValue`(`)const:%- [@(0.0.255) unsigned]_[* GetHashValue]()_[@(0.0.255) c