Merge pull request #365 from wolfmanjm/fix/config-set
[clinton/Smoothieware.git] / src / libs / ConfigCache.cpp
CommitLineData
8d54c34c
JM
1#include "ConfigCache.h"
2#include "ConfigValue.h"
3
4// If we find an existing value, replace it, otherwise, push it at the back of the list
5void ConfigCache::replace_or_push_back(ConfigValue *new_value)
6{
7
8 bool value_exists = false;
9 // For each already existing element
10 for( unsigned int i = 1; i < this->size(); i++) {
11 // If this configvalue matches the checksum
12 bool match = true;
13 unsigned int counter = 0;
14 while( counter < 3 && new_value->check_sums[counter] != 0x0000 ) {
15 if(this->at(i)->check_sums[counter] != new_value->check_sums[counter] ) {
16 match = false;
17 break;
18 }
19 counter++;
20 }
21 if( match == false ) {
22 continue;
23 }
24 value_exists = true;
25
26 // Replace with the provided value
27 delete this->at(i);
28 this->at(i) = new_value;
29 break;
30 }
31
32 // Value does not already exists, add to the list
33 if( value_exists == false ) {
34 this->push_back(new_value);
35 }
36
37}