mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-31 09:57:14 +01:00
Add retrieval with fall-back.
This commit is contained in:
parent
812cbcf332
commit
9e0071567e
@ -23,6 +23,7 @@ void Register_Dictionary(HSQUIRRELVM vm, Table & ns)
|
|||||||
// Member Methods
|
// Member Methods
|
||||||
.Func(_SC("Get"), &SqDictionary::Get)
|
.Func(_SC("Get"), &SqDictionary::Get)
|
||||||
.Func(_SC("Set"), &SqDictionary::Set)
|
.Func(_SC("Set"), &SqDictionary::Set)
|
||||||
|
.Func(_SC("GetOr"), &SqDictionary::GetOr)
|
||||||
.Func(_SC("Clear"), &SqDictionary::Clear)
|
.Func(_SC("Clear"), &SqDictionary::Clear)
|
||||||
.Func(_SC("Erase"), &SqDictionary::Erase)
|
.Func(_SC("Erase"), &SqDictionary::Erase)
|
||||||
.Func(_SC("Contains"), &SqDictionary::Contains)
|
.Func(_SC("Contains"), &SqDictionary::Contains)
|
||||||
|
@ -150,6 +150,19 @@ struct SqDictionary
|
|||||||
SQ_UNREACHABLE
|
SQ_UNREACHABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Retrieve a value from the container or a fall-back if it doesn't exist.
|
||||||
|
*/
|
||||||
|
SQMOD_NODISCARD LightObj & GetOr(SqKeyHash k, LightObj & v)
|
||||||
|
{
|
||||||
|
for (auto & e : mC)
|
||||||
|
{
|
||||||
|
if (e.first == k.mH) return e.second;
|
||||||
|
}
|
||||||
|
// Use fall-back
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Modify a value from the container.
|
* Modify a value from the container.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user