4#include <collections.h>
10 collections_map<std::string, IVoidPointer*> _variables;
11 collections_map<std::string, bool> _destructable;
18 void set(
const char* name, IVoidPointer* variable,
bool destructable =
true)
override {
19 variable->delete_rule()->set_destruct_on_delete(destructable);
20 _variables[name] = variable;
23 bool exists(
const char* name)
const override {
24 if (_variables.find(name) != _variables.end())
return true;
25 if (_parent !=
nullptr)
return _parent->
has_var(name);
29 IVoidPointer*
get(
const char* name)
const override {
30 auto found = _variables.find(name);
31 if (found != _variables.end())
return found->second;
32 if (_parent !=
nullptr)
return _parent->
var(name);
37 if (
auto* voidPtr =
get(name))
return voidPtr->delete_rule()->destruct_on_delete();
42 if (
auto* voidPtr =
get(name))
43 voidPtr->delete_rule()->set_destruct_on_delete(destructable);
47 for (
const auto& [name, variable] : _variables) fn->invoke(variable);
51 for (
const auto& [name, variable] : _variables)
delete variable;
55 void unset(
const char* name)
override {
56 auto found = _variables.find(name);
57 if (found != _variables.end()) {
59 _variables.erase(found);
bool exists(const char *name) const override
void foreach_variable(ForEachVariableFn *fn) const override
SpecVariableCollection(ISpecGroup *group=nullptr)
~SpecVariableCollection() override
void unset(const char *name) override
bool is_destructable(const char *name) const override
void set_destructable(const char *name, bool destructable=true) override
void set(const char *name, IVoidPointer *variable, bool destructable=true) override
IVoidPointer * get(const char *name) const override
IVoidPointer * var(const char *name) const
bool has_var(const char *name) const
IFunctionPointer< void(IVoidPointer *)> ForEachVariableFn