Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
SpecsCpp::SpecVariableCollection Class Reference

#include <SpecVariableCollection.h>

Inheritance diagram for SpecsCpp::SpecVariableCollection:
SpecsCpp::ISpecVariableCollection

Public Member Functions

 SpecVariableCollection (ISpecGroup *group=nullptr)
 
 ~SpecVariableCollection () override
 
void set (const char *name, IVoidPointer *variable, bool destructable=true) override
 
bool exists (const char *name) const override
 
IVoidPointer * get (const char *name) const override
 
bool is_destructable (const char *name) const override
 
void set_destructable (const char *name, bool destructable=true) override
 
void foreach_variable (ForEachVariableFn *fn) const override
 
void clear () override
 
void unset (const char *name) override
 
- Public Member Functions inherited from SpecsCpp::ISpecVariableCollection
virtual ~ISpecVariableCollection ()=default
 
virtual void set (const char *name, IVoidPointer *, bool destructable=true)=0
 
virtual void unset (const char *name)=0
 
virtual bool is_destructable (const char *name) const =0
 
virtual void set_destructable (const char *name, bool destructable=true)=0
 
virtual bool exists (const char *name) const =0
 
virtual IVoidPointer * get (const char *name) const =0
 
virtual void foreach_variable (ForEachVariableFn *) const =0
 
virtual void clear ()=0
 
void foreach (std::function< void(IVoidPointer *)> fn) const
 

Additional Inherited Members

- Public Types inherited from SpecsCpp::ISpecVariableCollection
using ForEachVariableFn = IFunctionPointer< void(IVoidPointer *)>
 

Detailed Description

Definition at line 8 of file SpecVariableCollection.h.

Constructor & Destructor Documentation

◆ SpecVariableCollection()

SpecsCpp::SpecVariableCollection::SpecVariableCollection ( ISpecGroup group = nullptr)
inline

Definition at line 14 of file SpecVariableCollection.h.

14: _parent(group) {}

◆ ~SpecVariableCollection()

SpecsCpp::SpecVariableCollection::~SpecVariableCollection ( )
inlineoverride

Definition at line 16 of file SpecVariableCollection.h.

Member Function Documentation

◆ clear()

void SpecsCpp::SpecVariableCollection::clear ( )
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 50 of file SpecVariableCollection.h.

50 {
51 for (const auto& [name, variable] : _variables) delete variable;
52 _variables.clear();
53 }

Referenced by ~SpecVariableCollection().

◆ exists()

bool SpecsCpp::SpecVariableCollection::exists ( const char *  name) const
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 23 of file SpecVariableCollection.h.

23 {
24 if (_variables.find(name) != _variables.end()) return true;
25 if (_parent != nullptr) return _parent->has_var(name);
26 return false;
27 }
bool has_var(const char *name) const
Definition API.h:227

◆ foreach_variable()

void SpecsCpp::SpecVariableCollection::foreach_variable ( ForEachVariableFn fn) const
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 46 of file SpecVariableCollection.h.

46 {
47 for (const auto& [name, variable] : _variables) fn->invoke(variable);
48 }

◆ get()

IVoidPointer * SpecsCpp::SpecVariableCollection::get ( const char *  name) const
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 29 of file SpecVariableCollection.h.

29 {
30 auto found = _variables.find(name);
31 if (found != _variables.end()) return found->second;
32 if (_parent != nullptr) return _parent->var(name);
33 return nullptr;
34 }
IVoidPointer * var(const char *name) const
Definition API.h:229

Referenced by is_destructable(), and set_destructable().

◆ is_destructable()

bool SpecsCpp::SpecVariableCollection::is_destructable ( const char *  name) const
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 36 of file SpecVariableCollection.h.

36 {
37 if (auto* voidPtr = get(name)) return voidPtr->delete_rule()->destruct_on_delete();
38 return false;
39 }
IVoidPointer * get(const char *name) const override

◆ set()

void SpecsCpp::SpecVariableCollection::set ( const char *  name,
IVoidPointer *  variable,
bool  destructable = true 
)
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 18 of file SpecVariableCollection.h.

18 {
19 variable->delete_rule()->set_destruct_on_delete(destructable);
20 _variables[name] = variable;
21 }

◆ set_destructable()

void SpecsCpp::SpecVariableCollection::set_destructable ( const char *  name,
bool  destructable = true 
)
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 41 of file SpecVariableCollection.h.

41 {
42 if (auto* voidPtr = get(name))
43 voidPtr->delete_rule()->set_destruct_on_delete(destructable);
44 }

◆ unset()

void SpecsCpp::SpecVariableCollection::unset ( const char *  name)
inlineoverridevirtual

Implements SpecsCpp::ISpecVariableCollection.

Definition at line 55 of file SpecVariableCollection.h.

55 {
56 auto found = _variables.find(name);
57 if (found != _variables.end()) {
58 delete found->second;
59 _variables.erase(found);
60 }
61 }

The documentation for this class was generated from the following file: