Stéphane Cachat
/
Smoothie
smoothie port to mbed online compiler (smoothieware.org)
Embed:
(wiki syntax)
Show/hide line numbers
ConfigCache.h
00001 /* 00002 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). 00003 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. 00004 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. 00005 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 00006 */ 00007 00008 #ifndef CONFIGCACHE_H 00009 #define CONFIGCACHE_H 00010 00011 using namespace std; 00012 #include <vector> 00013 00014 #include "ConfigValue.h" 00015 00016 class ConfigCache : public std::vector<ConfigValue*> { 00017 public: 00018 ConfigCache(){} 00019 00020 // If we find an existing value, replace it, otherwise, push it at the back of the list 00021 void replace_or_push_back(ConfigValue* new_value){ 00022 00023 bool value_exists = false; 00024 // For each already existing element 00025 for( int i=1; i<this->size(); i++){ 00026 // If this configvalue matches the checksum 00027 bool match = true; 00028 for( unsigned int j = 0; j < new_value->check_sums.size(); j++ ){ 00029 uint16_t checksum_node = new_value->check_sums[j]; 00030 if(this->at(i)->check_sums[j] != checksum_node ){ 00031 match = false; 00032 break; 00033 } 00034 } 00035 if( match == false ){ continue; } 00036 value_exists = true; 00037 // Replace with the provided value 00038 delete this->at(i); 00039 this->at(i) = new_value; 00040 break; 00041 } 00042 00043 // Value does not already exists, add to the list 00044 if( value_exists == false ){ 00045 this->push_back(new_value); 00046 } 00047 00048 } 00049 00050 }; 00051 00052 00053 00054 #endif
Generated on Tue Jul 12 2022 14:14:39 by 1.7.2