mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-04 15:15:56 +01:00
Add Dictionary.merge()
(cherry picked from commit a0915e6dee4e54563a98ca6adb8968dbdcea1af1)
This commit is contained in:
parent
22beba680e
commit
202fb33685
@ -197,6 +197,14 @@ void Dictionary::clear() {
|
|||||||
_p->variant_map.clear();
|
_p->variant_map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dictionary::merge(const Dictionary &p_dictionary, bool p_overwrite) {
|
||||||
|
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = p_dictionary._p->variant_map.front(); E; E = E.next()) {
|
||||||
|
if (p_overwrite || !has(E.key())) {
|
||||||
|
this->operator[](E.key()) = E.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Dictionary::_unref() const {
|
void Dictionary::_unref() const {
|
||||||
ERR_FAIL_COND(!_p);
|
ERR_FAIL_COND(!_p);
|
||||||
if (_p->refcount.unref()) {
|
if (_p->refcount.unref()) {
|
||||||
|
@ -61,6 +61,7 @@ public:
|
|||||||
int size() const;
|
int size() const;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
void clear();
|
void clear();
|
||||||
|
void merge(const Dictionary &p_dictionary, bool p_overwrite = false);
|
||||||
|
|
||||||
bool has(const Variant &p_key) const;
|
bool has(const Variant &p_key) const;
|
||||||
bool has_all(const Array &p_keys) const;
|
bool has_all(const Array &p_keys) const;
|
||||||
|
@ -612,6 +612,7 @@ struct _VariantCall {
|
|||||||
VCALL_LOCALMEM0R(Dictionary, size);
|
VCALL_LOCALMEM0R(Dictionary, size);
|
||||||
VCALL_LOCALMEM0R(Dictionary, empty);
|
VCALL_LOCALMEM0R(Dictionary, empty);
|
||||||
VCALL_LOCALMEM0(Dictionary, clear);
|
VCALL_LOCALMEM0(Dictionary, clear);
|
||||||
|
VCALL_LOCALMEM2(Dictionary, merge);
|
||||||
VCALL_LOCALMEM1R(Dictionary, has);
|
VCALL_LOCALMEM1R(Dictionary, has);
|
||||||
VCALL_LOCALMEM1R(Dictionary, has_all);
|
VCALL_LOCALMEM1R(Dictionary, has_all);
|
||||||
VCALL_LOCALMEM1R(Dictionary, erase);
|
VCALL_LOCALMEM1R(Dictionary, erase);
|
||||||
@ -2240,6 +2241,7 @@ void register_variant_methods() {
|
|||||||
ADDFUNC0R(DICTIONARY, INT, Dictionary, size, varray());
|
ADDFUNC0R(DICTIONARY, INT, Dictionary, size, varray());
|
||||||
ADDFUNC0R(DICTIONARY, BOOL, Dictionary, empty, varray());
|
ADDFUNC0R(DICTIONARY, BOOL, Dictionary, empty, varray());
|
||||||
ADDFUNC0NC(DICTIONARY, NIL, Dictionary, clear, varray());
|
ADDFUNC0NC(DICTIONARY, NIL, Dictionary, clear, varray());
|
||||||
|
ADDFUNC2NC(DICTIONARY, NIL, Dictionary, merge, DICTIONARY, "dictionary", BOOL, "overwrite", varray(false));
|
||||||
ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has, NIL, "key", varray());
|
ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has, NIL, "key", varray());
|
||||||
ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has_all, ARRAY, "keys", varray());
|
ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has_all, ARRAY, "keys", varray());
|
||||||
ADDFUNC1RNC(DICTIONARY, BOOL, Dictionary, erase, NIL, "key", varray());
|
ADDFUNC1RNC(DICTIONARY, BOOL, Dictionary, erase, NIL, "key", varray());
|
||||||
|
@ -164,6 +164,13 @@
|
|||||||
Returns the list of keys in the [Dictionary].
|
Returns the list of keys in the [Dictionary].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="merge">
|
||||||
|
<argument index="0" name="dictionary" type="Dictionary" />
|
||||||
|
<argument index="1" name="overwrite" type="bool" default="false" />
|
||||||
|
<description>
|
||||||
|
Adds elements from [code]dictionary[/code] to this [Dictionary]. By default, duplicate keys will not be copied over, unless [code]overwrite[/code] is [code]true[/code].
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="size">
|
<method name="size">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<description>
|
<description>
|
||||||
|
Loading…
Reference in New Issue
Block a user