Module: remove unused kernel pointer, shrink every Module instance by 4 bytes
[clinton/Smoothieware.git] / src / libs / ConfigCache.h
CommitLineData
c295905f
AW
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.
df27a6a3 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
c295905f
AW
6*/
7
8#ifndef CONFIGCACHE_H
9#define CONFIGCACHE_H
10
11using namespace std;
12#include <vector>
13
14#include "ConfigValue.h"
15
16class ConfigCache : public std::vector<ConfigValue*> {
17 public:
18 ConfigCache(){}
19
df27a6a3 20 // If we find an existing value, replace it, otherwise, push it at the back of the list
c295905f
AW
21 void replace_or_push_back(ConfigValue* new_value){
22
df27a6a3
MM
23 bool value_exists = false;
24 // For each already existing element
1163f813 25 for( unsigned int i=1; i<this->size(); i++){
df27a6a3 26 // If this configvalue matches the checksum
c295905f 27 bool match = true;
87b6a8d5 28 unsigned int counter = 0;
4f5435e8 29 while( counter < 3 && new_value->check_sums[counter] != 0x0000 ){
4464301d 30 if(this->at(i)->check_sums[counter] != new_value->check_sums[counter] ){
c295905f 31 match = false;
df27a6a3 32 break;
c295905f 33 }
4464301d
AW
34 counter++;
35 }
c295905f
AW
36 if( match == false ){ continue; }
37 value_exists = true;
4464301d 38
df27a6a3 39 // Replace with the provided value
8d857d2e 40 delete this->at(i);
c295905f
AW
41 this->at(i) = new_value;
42 break;
43 }
44
45 // Value does not already exists, add to the list
df27a6a3 46 if( value_exists == false ){
c295905f
AW
47 this->push_back(new_value);
48 }
49
50 }
51
52};
53
54
55
56#endif