1 #include "ConfigCache.h"
2 #include "ConfigValue.h"
4 #include "libs/StreamOutput.h"
6 ConfigCache::ConfigCache()
10 ConfigCache::~ConfigCache()
15 void ConfigCache::clear()
17 for (auto &kv
: store
) {
21 storage_t().swap(store
); // makes sure the vector releases its memory
24 void ConfigCache::add(ConfigValue
*v
)
29 // If we find an existing value, replace it, otherwise, push it at the back of the list
30 void ConfigCache::replace_or_push_back(ConfigValue
*new_value
)
32 // For each already existing element
33 for(auto &cv
: store
) {
34 // If this configvalue matches the checksum
35 if(memcmp(new_value
->check_sums
, cv
->check_sums
, sizeof(cv
->check_sums
)) == 0) {
36 // Replace with the provided value
38 printf("WARNING: duplicate config line replaced\n");
43 // Value does not already exists, add to the list
44 store
.push_back(new_value
);
47 ConfigValue
*ConfigCache::lookup(const uint16_t *check_sums
) const
49 for( auto &cv
: store
) {
50 if(memcmp(check_sums
, cv
->check_sums
, sizeof(cv
->check_sums
)) == 0)
57 void ConfigCache::collect(uint16_t family
, uint16_t cs
, vector
<uint16_t> *list
)
59 for( auto &kv
: store
) {
60 if( kv
->check_sums
[2] == cs
&& kv
->check_sums
[0] == family
) {
61 // We found a module enable for this family, add it's number
62 list
->push_back(kv
->check_sums
[1]);
67 void ConfigCache::dump(StreamOutput
*stream
)
70 for( auto &kv
: store
) {
72 stream
->printf("%3d - %04X %04X %04X : '%s' - found: %d, default: %d, default-double: %f, default-int: %d\n",
73 l
++, v
->check_sums
[0], v
->check_sums
[1], v
->check_sums
[2], v
->value
.c_str(), v
->found
, v
->default_set
, v
->default_double
, v
->default_int
);