Specs
Beautiful C++ Test Framework
Loading...
Searching...
No Matches
SpecDataValueCollection.h
Go to the documentation of this file.
1#pragma once
2
3#include <Specs/API.h>
4#include <collections.h>
5
6#include <string>
7
8namespace SpecsCpp {
9
11 collections_map<std::string, ISpecDataValue*> _values;
12
13 void merge_foreach(ISpecDataValue* value) { add(value); }
14
15 FunctionPointer<void(ISpecDataValue*)> _merge_foreach =
16 function_pointer(this, &SpecDataValueCollection::merge_foreach);
17
18 public:
20 for (auto& [key, value] : _values) delete value;
21 }
22
23 void add(ISpecDataValue* value) override { _values.emplace(value->key(), value); }
24 ISpecDataValue* get(const char* key) const override {
25 auto found = _values.find(key);
26 return found == _values.end() ? nullptr : found->second;
27 }
28 bool has(const char* key) const override {
29 auto found = _values.find(key);
30 return found != _values.end();
31 }
32 void foreach_value(ForEachSpecDataFn* fn) const override {
33 for (auto& [key, value] : _values) fn->invoke(value);
34 }
35 void merge(ISpecDataValueCollection* other) override {
36 other->foreach_value(&_merge_foreach);
37 }
38 void clear() override { _values.clear(); }
39 };
40}
ISpecDataValue * get(const char *key) const override
void foreach_value(ForEachSpecDataFn *fn) const override
bool has(const char *key) const override
void merge(ISpecDataValueCollection *other) override
void add(ISpecDataValue *value) override
Definition API.h:3
IFunctionPointer< void(ISpecDataValue *)> ForEachSpecDataFn
Definition API.h:68
virtual void foreach_value(ForEachSpecDataFn *) const =0
virtual const char * key() const =0