1
0
forked from fsfw/fsfw
This commit is contained in:
2020-08-11 16:21:59 +02:00
parent 3905b72b08
commit 8c722feafb
5 changed files with 54 additions and 64 deletions

View File

@ -1,5 +1,5 @@
#ifndef FIXEDMAP_H_
#define FIXEDMAP_H_
#ifndef FRAMEWORK_CONTAINER_FIXEDMAP_H_
#define FRAMEWORK_CONTAINER_FIXEDMAP_H_
#include <framework/container/ArrayList.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
@ -7,6 +7,10 @@
/**
* \ingroup container
*
*
* \warning Iterators return a non-const key_t in the pair.
* \warning A User is not allowed to change the key, otherwise the map is corrupted.
*/
template<typename key_t, typename T>
class FixedMap: public SerializeIF {
@ -47,15 +51,6 @@ public:
Iterator(std::pair<key_t, T> *pair) :
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair) {
}
T operator*() {
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
}
T *operator->() {
return &ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
}
};
Iterator begin() const {
@ -70,7 +65,7 @@ public:
return _size;
}
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) {
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) {
if (exists(key) == HasReturnvaluesIF::RETURN_OK) {
return KEY_ALREADY_EXISTS;
}
@ -79,7 +74,7 @@ public:
}
theMap[_size].first = key;
theMap[_size].second = value;
if (storedValue != NULL) {
if (storedValue != nullptr) {
*storedValue = Iterator(&theMap[_size]);
}
++_size;
@ -87,7 +82,7 @@ public:
}
ReturnValue_t insert(std::pair<key_t, T> pair) {
return insert(pair.fist, pair.second);
return insert(pair.first, pair.second);
}
ReturnValue_t exists(key_t key) const {