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