smoothie port to mbed online compiler (smoothieware.org)
For documentation, license, ..., please check http://smoothieware.org/
This version has been tested with a 3 axis machine
libs/ConfigCache.h@0:31e91bb0ef3c, 2012-07-31 (annotated)
- Committer:
- scachat
- Date:
- Tue Jul 31 21:11:18 2012 +0000
- Revision:
- 0:31e91bb0ef3c
smoothie port to mbed online compiler
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scachat | 0:31e91bb0ef3c | 1 | /* |
scachat | 0:31e91bb0ef3c | 2 | This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). |
scachat | 0:31e91bb0ef3c | 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. |
scachat | 0:31e91bb0ef3c | 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. |
scachat | 0:31e91bb0ef3c | 5 | You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. |
scachat | 0:31e91bb0ef3c | 6 | */ |
scachat | 0:31e91bb0ef3c | 7 | |
scachat | 0:31e91bb0ef3c | 8 | #ifndef CONFIGCACHE_H |
scachat | 0:31e91bb0ef3c | 9 | #define CONFIGCACHE_H |
scachat | 0:31e91bb0ef3c | 10 | |
scachat | 0:31e91bb0ef3c | 11 | using namespace std; |
scachat | 0:31e91bb0ef3c | 12 | #include <vector> |
scachat | 0:31e91bb0ef3c | 13 | |
scachat | 0:31e91bb0ef3c | 14 | #include "ConfigValue.h" |
scachat | 0:31e91bb0ef3c | 15 | |
scachat | 0:31e91bb0ef3c | 16 | class ConfigCache : public std::vector<ConfigValue*> { |
scachat | 0:31e91bb0ef3c | 17 | public: |
scachat | 0:31e91bb0ef3c | 18 | ConfigCache(){} |
scachat | 0:31e91bb0ef3c | 19 | |
scachat | 0:31e91bb0ef3c | 20 | // If we find an existing value, replace it, otherwise, push it at the back of the list |
scachat | 0:31e91bb0ef3c | 21 | void replace_or_push_back(ConfigValue* new_value){ |
scachat | 0:31e91bb0ef3c | 22 | |
scachat | 0:31e91bb0ef3c | 23 | bool value_exists = false; |
scachat | 0:31e91bb0ef3c | 24 | // For each already existing element |
scachat | 0:31e91bb0ef3c | 25 | for( int i=1; i<this->size(); i++){ |
scachat | 0:31e91bb0ef3c | 26 | // If this configvalue matches the checksum |
scachat | 0:31e91bb0ef3c | 27 | bool match = true; |
scachat | 0:31e91bb0ef3c | 28 | for( unsigned int j = 0; j < new_value->check_sums.size(); j++ ){ |
scachat | 0:31e91bb0ef3c | 29 | uint16_t checksum_node = new_value->check_sums[j]; |
scachat | 0:31e91bb0ef3c | 30 | if(this->at(i)->check_sums[j] != checksum_node ){ |
scachat | 0:31e91bb0ef3c | 31 | match = false; |
scachat | 0:31e91bb0ef3c | 32 | break; |
scachat | 0:31e91bb0ef3c | 33 | } |
scachat | 0:31e91bb0ef3c | 34 | } |
scachat | 0:31e91bb0ef3c | 35 | if( match == false ){ continue; } |
scachat | 0:31e91bb0ef3c | 36 | value_exists = true; |
scachat | 0:31e91bb0ef3c | 37 | // Replace with the provided value |
scachat | 0:31e91bb0ef3c | 38 | delete this->at(i); |
scachat | 0:31e91bb0ef3c | 39 | this->at(i) = new_value; |
scachat | 0:31e91bb0ef3c | 40 | break; |
scachat | 0:31e91bb0ef3c | 41 | } |
scachat | 0:31e91bb0ef3c | 42 | |
scachat | 0:31e91bb0ef3c | 43 | // Value does not already exists, add to the list |
scachat | 0:31e91bb0ef3c | 44 | if( value_exists == false ){ |
scachat | 0:31e91bb0ef3c | 45 | this->push_back(new_value); |
scachat | 0:31e91bb0ef3c | 46 | } |
scachat | 0:31e91bb0ef3c | 47 | |
scachat | 0:31e91bb0ef3c | 48 | } |
scachat | 0:31e91bb0ef3c | 49 | |
scachat | 0:31e91bb0ef3c | 50 | }; |
scachat | 0:31e91bb0ef3c | 51 | |
scachat | 0:31e91bb0ef3c | 52 | |
scachat | 0:31e91bb0ef3c | 53 | |
scachat | 0:31e91bb0ef3c | 54 | #endif |