solved the block end problem, commiting mostly to save all those neat debug statement...
[clinton/Smoothieware.git] / src / libs / ConfigCache.h
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef CONFIGCACHE_H
9 #define CONFIGCACHE_H
10
11 using namespace std;
12 #include <vector>
13
14 #include "ConfigValue.h"
15
16 class ConfigCache : public std::vector<ConfigValue*> {
17 public:
18 ConfigCache(){}
19
20 // If we find an existing value, replace it, otherwise, push it at the back of the list
21 void replace_or_push_back(ConfigValue* new_value){
22
23 bool value_exists = false;
24 // For each already existing element
25 for( int i=1; i<this->size(); i++){
26 // If this configvalue matches the checksum
27 bool match = true;
28 char counter = 0;
29 while( new_value->check_sums[counter] != 0x0000 && counter < 3 ){
30 if(this->at(i)->check_sums[counter] != new_value->check_sums[counter] ){
31 match = false;
32 break;
33 }
34 counter++;
35 }
36 if( match == false ){ continue; }
37 value_exists = true;
38
39 // Replace with the provided value
40 delete this->at(i);
41 this->at(i) = new_value;
42 break;
43 }
44
45 // Value does not already exists, add to the list
46 if( value_exists == false ){
47 this->push_back(new_value);
48 }
49
50 }
51
52 };
53
54
55
56 #endif