dedicated header file for container retvals

This commit is contained in:
Robin Müller 2022-11-10 15:12:18 +01:00
parent 0e8f5ddd26
commit 530a261e14
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
3 changed files with 24 additions and 16 deletions

View File

@ -5,6 +5,8 @@
#include "../serialize/SerializeAdapter.h" #include "../serialize/SerializeAdapter.h"
#include "../serialize/SerializeIF.h" #include "../serialize/SerializeIF.h"
#include "definitions.h"
/** /**
* @brief A List that stores its values in an array. * @brief A List that stores its values in an array.
* @details * @details
@ -19,8 +21,6 @@ class ArrayList {
friend class SerialArrayListAdapter; friend class SerialArrayListAdapter;
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST;
static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01);
/** /**
* This is the allocating constructor. * This is the allocating constructor.
@ -187,7 +187,7 @@ class ArrayList {
*/ */
ReturnValue_t insert(T entry) { ReturnValue_t insert(T entry) {
if (size >= maxSize_) { if (size >= maxSize_) {
return FULL; return containers::LIST_FULL;
} }
entries[size] = entry; entries[size] = entry;
++size; ++size;

View File

@ -4,16 +4,9 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
#include "../returnvalues/returnvalue.h" #include "definitions.h"
#include "ArrayList.h" #include "ArrayList.h"
namespace mapdefs {
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP;
static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01);
static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x02);
static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03);
} // namespace mapdefs
/** /**
* @brief Map implementation for maps with a pre-defined size. * @brief Map implementation for maps with a pre-defined size.
* @details * @details
@ -78,10 +71,10 @@ class FixedMap : public SerializeIF {
ReturnValue_t insert(key_t key, T value, Iterator* storedValue = nullptr) { ReturnValue_t insert(key_t key, T value, Iterator* storedValue = nullptr) {
if (exists(key) == returnvalue::OK) { if (exists(key) == returnvalue::OK) {
return mapdefs::KEY_ALREADY_EXISTS; return containers::KEY_ALREADY_EXISTS;
} }
if (_size == theMap.maxSize()) { if (_size == theMap.maxSize()) {
return mapdefs::MAP_FULL; return containers::MAP_FULL;
} }
theMap[_size].first = key; theMap[_size].first = key;
theMap[_size].second = value; theMap[_size].second = value;
@ -95,7 +88,7 @@ class FixedMap : public SerializeIF {
ReturnValue_t insert(std::pair<key_t, T> pair) { return insert(pair.first, pair.second); } ReturnValue_t insert(std::pair<key_t, T> pair) { return insert(pair.first, pair.second); }
ReturnValue_t exists(key_t key) const { ReturnValue_t exists(key_t key) const {
ReturnValue_t result = mapdefs::KEY_DOES_NOT_EXIST; ReturnValue_t result = containers::KEY_DOES_NOT_EXIST;
if (findIndex(key) < _size) { if (findIndex(key) < _size) {
result = returnvalue::OK; result = returnvalue::OK;
} }
@ -105,7 +98,7 @@ class FixedMap : public SerializeIF {
ReturnValue_t erase(Iterator* iter) { ReturnValue_t erase(Iterator* iter) {
uint32_t i; uint32_t i;
if ((i = findIndex((*iter).value->first)) >= _size) { if ((i = findIndex((*iter).value->first)) >= _size) {
return mapdefs::KEY_DOES_NOT_EXIST; return containers::KEY_DOES_NOT_EXIST;
} }
theMap[i] = theMap[_size - 1]; theMap[i] = theMap[_size - 1];
--_size; --_size;
@ -116,7 +109,7 @@ class FixedMap : public SerializeIF {
ReturnValue_t erase(key_t key) { ReturnValue_t erase(key_t key) {
uint32_t i; uint32_t i;
if ((i = findIndex(key)) >= _size) { if ((i = findIndex(key)) >= _size) {
return mapdefs::KEY_DOES_NOT_EXIST; return containers::KEY_DOES_NOT_EXIST;
} }
theMap[i] = theMap[_size - 1]; theMap[i] = theMap[_size - 1];
--_size; --_size;

View File

@ -0,0 +1,15 @@
#ifndef FSFW_CONTAINER_DEFINITIONS_H_
#define FSFW_CONTAINER_DEFINITIONS_H_
#include "fsfw/retval.h"
using namespace returnvalue;
namespace containers {
static const ReturnValue_t KEY_ALREADY_EXISTS = makeCode(CLASS_ID::FIXED_MAP, 0x01);
static const ReturnValue_t MAP_FULL = makeCode(CLASS_ID::FIXED_MAP, 0x02);
static const ReturnValue_t KEY_DOES_NOT_EXIST = makeCode(CLASS_ID::FIXED_MAP, 0x03);
static const ReturnValue_t LIST_FULL = makeCode(CLASS_ID::ARRAY_LIST, 0x01);
} // namespace containers
#endif /* FSFW_CONTAINER_DEFINITIONS_H_ */