Merge branch 'master' into mueller/sharedRingBufferFIFO
This commit is contained in:
commit
67dd153511
@ -1,5 +1,6 @@
|
||||
#include "ActionHelper.h"
|
||||
#include "HasActionsIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
|
||||
ActionHelper::ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue) :
|
||||
|
@ -1,15 +1,15 @@
|
||||
#ifndef ARRAYLIST_H_
|
||||
#define ARRAYLIST_H_
|
||||
#ifndef FSFW_CONTAINER_ARRAYLIST_H_
|
||||
#define FSFW_CONTAINER_ARRAYLIST_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../serialize/SerializeAdapter.h"
|
||||
#include "../serialize/SerializeIF.h"
|
||||
|
||||
/**
|
||||
* A List that stores its values in an array.
|
||||
*
|
||||
* The backend is an array that can be allocated by the class itself or supplied via ctor.
|
||||
*
|
||||
* @brief A List that stores its values in an array.
|
||||
* @details
|
||||
* The underlying storage is an array that can be allocated by the class
|
||||
* itself or supplied via ctor.
|
||||
*
|
||||
* @ingroup container
|
||||
*/
|
||||
@ -20,6 +20,53 @@ 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.
|
||||
* It allocates an array of the specified size.
|
||||
* @param maxSize
|
||||
*/
|
||||
ArrayList(count_t maxSize) :
|
||||
size(0), maxSize_(maxSize), allocated(true) {
|
||||
entries = new T[maxSize];
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the non-allocating constructor
|
||||
*
|
||||
* It expects a pointer to an array of a certain size and initializes
|
||||
* itself to it.
|
||||
*
|
||||
* @param storage the array to use as backend
|
||||
* @param maxSize size of storage
|
||||
* @param size size of data already present in storage
|
||||
*/
|
||||
ArrayList(T *storage, count_t maxSize, count_t size = 0) :
|
||||
size(size), entries(storage), maxSize_(maxSize), allocated(false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copying is forbiden by declaring copy ctor and copy assignment deleted
|
||||
* It is too ambigous in this case.
|
||||
* (Allocate a new backend? Use the same? What to do in an modifying call?)
|
||||
*/
|
||||
ArrayList(const ArrayList& other) = delete;
|
||||
const ArrayList& operator=(const ArrayList& other) = delete;
|
||||
|
||||
/**
|
||||
* Number of Elements stored in this List
|
||||
*/
|
||||
count_t size;
|
||||
|
||||
|
||||
/**
|
||||
* Destructor, if the allocating constructor was used, it deletes the array.
|
||||
*/
|
||||
virtual ~ArrayList() {
|
||||
if (allocated) {
|
||||
delete[] entries;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An Iterator to go trough an ArrayList
|
||||
*
|
||||
@ -31,10 +78,7 @@ public:
|
||||
/**
|
||||
* Empty ctor, points to NULL
|
||||
*/
|
||||
Iterator() :
|
||||
value(0) {
|
||||
|
||||
}
|
||||
Iterator(): value(0) {}
|
||||
|
||||
/**
|
||||
* Initializes the Iterator to point to an element
|
||||
@ -72,71 +116,31 @@ public:
|
||||
return tmp;
|
||||
}
|
||||
|
||||
T& operator*(){
|
||||
T& operator*() {
|
||||
return *value;
|
||||
}
|
||||
|
||||
const T& operator*() const{
|
||||
const T& operator*() const {
|
||||
return *value;
|
||||
}
|
||||
|
||||
T *operator->(){
|
||||
T *operator->() {
|
||||
return value;
|
||||
}
|
||||
|
||||
const T *operator->() const{
|
||||
const T *operator->() const {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
//SHOULDDO this should be implemented as non-member
|
||||
bool operator==(const typename ArrayList<T, count_t>::Iterator& other) const{
|
||||
return (value == other.value);
|
||||
}
|
||||
|
||||
//SHOULDDO this should be implemented as non-member
|
||||
bool operator!=(const typename ArrayList<T, count_t>::Iterator& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
* Number of Elements stored in this List
|
||||
*/
|
||||
count_t size;
|
||||
|
||||
/**
|
||||
* This is the allocating constructor;
|
||||
*
|
||||
* It allocates an array of the specified size.
|
||||
*
|
||||
* @param maxSize
|
||||
*/
|
||||
ArrayList(count_t maxSize) :
|
||||
size(0), maxSize_(maxSize), allocated(true) {
|
||||
entries = new T[maxSize];
|
||||
friend bool operator==(const ArrayList::Iterator& lhs,
|
||||
const ArrayList::Iterator& rhs) {
|
||||
return (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the non-allocating constructor
|
||||
*
|
||||
* It expects a pointer to an array of a certain size and initializes itself to it.
|
||||
*
|
||||
* @param storage the array to use as backend
|
||||
* @param maxSize size of storage
|
||||
* @param size size of data already present in storage
|
||||
*/
|
||||
ArrayList(T *storage, count_t maxSize, count_t size = 0) :
|
||||
size(size), entries(storage), maxSize_(maxSize), allocated(false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor, if the allocating constructor was used, it deletes the array.
|
||||
*/
|
||||
virtual ~ArrayList() {
|
||||
if (allocated) {
|
||||
delete[] entries;
|
||||
}
|
||||
friend bool operator!=(const ArrayList::Iterator& lhs,
|
||||
const ArrayList::Iterator& rhs) {
|
||||
return not (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,7 +196,7 @@ public:
|
||||
*
|
||||
* @return maximum number of elements
|
||||
*/
|
||||
uint32_t maxSize() const {
|
||||
size_t maxSize() const {
|
||||
return this->maxSize_;
|
||||
}
|
||||
|
||||
@ -227,19 +231,7 @@ public:
|
||||
count_t remaining() {
|
||||
return (maxSize_ - size);
|
||||
}
|
||||
private:
|
||||
/**
|
||||
* This is the copy constructor
|
||||
*
|
||||
* It is private, as copying is too ambigous in this case. (Allocate a new backend? Use the same?
|
||||
* What to do in an modifying call?)
|
||||
*
|
||||
* @param other
|
||||
*/
|
||||
ArrayList(const ArrayList& other) :
|
||||
size(other.size), entries(other.entries), maxSize_(other.maxSize_), allocated(
|
||||
false) {
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* pointer to the array in which the entries are stored
|
||||
@ -248,12 +240,14 @@ protected:
|
||||
/**
|
||||
* remembering the maximum size
|
||||
*/
|
||||
uint32_t maxSize_;
|
||||
size_t maxSize_;
|
||||
|
||||
/**
|
||||
* true if the array was allocated and needs to be deleted in the destructor.
|
||||
*/
|
||||
bool allocated;
|
||||
|
||||
};
|
||||
#endif /* ARRAYLIST_H_ */
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_CONTAINER_ARRAYLIST_H_ */
|
||||
|
@ -19,32 +19,46 @@ public:
|
||||
/**
|
||||
* Insert value into FIFO
|
||||
* @param value
|
||||
* @return
|
||||
* @return RETURN_OK on success, FULL if full
|
||||
*/
|
||||
ReturnValue_t insert(T value);
|
||||
/**
|
||||
* Retrieve item from FIFO. This removes the item from the FIFO.
|
||||
* @param value
|
||||
* @return
|
||||
* @param value Must point to a valid T
|
||||
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
||||
*/
|
||||
ReturnValue_t retrieve(T *value);
|
||||
/**
|
||||
* Retrieve item from FIFO without removing it from FIFO.
|
||||
* @param value
|
||||
* @return
|
||||
* @param value Must point to a valid T
|
||||
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
||||
*/
|
||||
ReturnValue_t peek(T * value);
|
||||
/**
|
||||
* Remove item from FIFO.
|
||||
* @return
|
||||
* @return RETURN_OK on success, EMPTY if empty
|
||||
*/
|
||||
ReturnValue_t pop();
|
||||
|
||||
/***
|
||||
* Check if FIFO is empty
|
||||
* @return True if empty, False if not
|
||||
*/
|
||||
bool empty();
|
||||
/***
|
||||
* Check if FIFO is Full
|
||||
* @return True if full, False if not
|
||||
*/
|
||||
bool full();
|
||||
/***
|
||||
* Current used size (elements) used
|
||||
* @return size_t in elements
|
||||
*/
|
||||
size_t size();
|
||||
|
||||
|
||||
/***
|
||||
* Get maximal capacity of fifo
|
||||
* @return size_t with max capacity of this fifo
|
||||
*/
|
||||
size_t getMaxCapacity() const;
|
||||
|
||||
protected:
|
||||
|
@ -26,6 +26,9 @@ inline ReturnValue_t FIFOBase<T>::retrieve(T* value) {
|
||||
if (empty()) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
if (value == nullptr){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*value = values[readIndex];
|
||||
readIndex = next(readIndex);
|
||||
--currentSize;
|
||||
@ -38,6 +41,9 @@ inline ReturnValue_t FIFOBase<T>::peek(T* value) {
|
||||
if(empty()) {
|
||||
return EMPTY;
|
||||
} else {
|
||||
if (value == nullptr){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
*value = values[readIndex];
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -2,11 +2,13 @@
|
||||
#define FIXEDARRAYLIST_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include <cmath>
|
||||
/**
|
||||
* \ingroup container
|
||||
*/
|
||||
template<typename T, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
||||
template<typename T, size_t MAX_SIZE, typename count_t = uint8_t>
|
||||
class FixedArrayList: public ArrayList<T, count_t> {
|
||||
static_assert(MAX_SIZE <= (pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE");
|
||||
private:
|
||||
T data[MAX_SIZE];
|
||||
public:
|
||||
@ -18,11 +20,13 @@ public:
|
||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||
memcpy(this->data, other.data, sizeof(this->data));
|
||||
this->entries = data;
|
||||
this->size = other.size;
|
||||
}
|
||||
|
||||
FixedArrayList& operator=(FixedArrayList other) {
|
||||
memcpy(this->data, other.data, sizeof(this->data));
|
||||
this->entries = data;
|
||||
this->size = other.size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -7,14 +7,21 @@
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
* @brief Map implementation for maps with a pre-defined size.
|
||||
* @details
|
||||
* Can be initialized with desired maximum size.
|
||||
* Iterator is used to access <key,value> pair and iterate through map entries.
|
||||
* Complexity O(n).
|
||||
* @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.
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename key_t, typename T>
|
||||
class FixedMap: public SerializeIF {
|
||||
static_assert (std::is_trivially_copyable<T>::value or std::is_base_of<SerializeIF, T>::value,
|
||||
"Types used in FixedMap must either be trivial copy-able or a derived Class from SerializeIF to be serialize-able");
|
||||
static_assert (std::is_trivially_copyable<T>::value or
|
||||
std::is_base_of<SerializeIF, T>::value,
|
||||
"Types used in FixedMap must either be trivial copy-able or a "
|
||||
"derived class from SerializeIF to be serialize-able");
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP;
|
||||
static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01);
|
||||
@ -54,6 +61,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
friend bool operator==(const typename FixedMap::Iterator& lhs,
|
||||
const typename FixedMap::Iterator& rhs) {
|
||||
return (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
friend bool operator!=(const typename FixedMap::Iterator& lhs,
|
||||
const typename FixedMap::Iterator& rhs) {
|
||||
return not (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
Iterator begin() const {
|
||||
return Iterator(&theMap[0]);
|
||||
}
|
||||
@ -136,6 +153,24 @@ public:
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
if(_size == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool full() {
|
||||
if(_size >= theMap.maxSize()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_size = 0;
|
||||
}
|
||||
|
@ -1,166 +1,206 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_H_
|
||||
#define FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_H_
|
||||
#ifndef FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_
|
||||
#define FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
|
||||
/**
|
||||
* @brief An associative container which allows multiple entries of the same key.
|
||||
* @details
|
||||
* Same keys are ordered by KEY_COMPARE function which is std::less<key_t> > by default.
|
||||
*
|
||||
* It uses the ArrayList, so technically this is not a real map, it is an array of pairs
|
||||
* of type key_t, T. It is ordered by key_t as FixedMap but allows same keys. Thus it has a linear
|
||||
* complexity O(n). As long as the number of entries remains low, this
|
||||
* should not be an issue.
|
||||
* The number of insertion and deletion operation should be minimized
|
||||
* as those incur extensive memory move operations (the underlying container
|
||||
* is not node based).
|
||||
*
|
||||
* Its of fixed size so no allocations are performed after the construction.
|
||||
*
|
||||
* The maximum size is given as first parameter of the constructor.
|
||||
*
|
||||
* It provides an iterator to do list iterations.
|
||||
*
|
||||
* The type T must have a copy constructor if it is not trivial copy-able.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* \ingroup container
|
||||
*/
|
||||
template<typename key_t, typename T, typename KEY_COMPARE = std::less<key_t>>
|
||||
class FixedOrderedMultimap {
|
||||
public:
|
||||
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);
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MULTIMAP;
|
||||
static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x01);
|
||||
static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x02);
|
||||
|
||||
private:
|
||||
typedef KEY_COMPARE compare;
|
||||
compare myComp;
|
||||
ArrayList<std::pair<key_t, T>, uint32_t> theMap;
|
||||
uint32_t _size;
|
||||
/***
|
||||
* Constructor which needs a size_t for the maximum allowed size
|
||||
*
|
||||
* Can not be resized during runtime
|
||||
*
|
||||
* Allocates memory at construction
|
||||
* @param maxSize size_t of Maximum allowed size
|
||||
*/
|
||||
FixedOrderedMultimap(size_t maxSize):theMap(maxSize), _size(0){
|
||||
}
|
||||
|
||||
uint32_t findFirstIndex(key_t key, uint32_t startAt = 0) const {
|
||||
if (startAt >= _size) {
|
||||
return startAt + 1;
|
||||
}
|
||||
uint32_t i = startAt;
|
||||
for (i = startAt; i < _size; ++i) {
|
||||
if (theMap[i].first == key) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
uint32_t findNicePlace(key_t key) const {
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < _size; ++i) {
|
||||
if (myComp(key, theMap[i].first)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void removeFromPosition(uint32_t position) {
|
||||
if (_size <= position) {
|
||||
return;
|
||||
}
|
||||
memmove(static_cast<void*>(&theMap[position]), static_cast<void*>(&theMap[position + 1]),
|
||||
(_size - position - 1) * sizeof(std::pair<key_t,T>));
|
||||
--_size;
|
||||
}
|
||||
public:
|
||||
FixedOrderedMultimap(uint32_t maxSize) :
|
||||
theMap(maxSize), _size(0) {
|
||||
}
|
||||
/***
|
||||
* Virtual destructor frees Memory by deleting its member
|
||||
*/
|
||||
virtual ~FixedOrderedMultimap() {
|
||||
}
|
||||
|
||||
class Iterator: public ArrayList<std::pair<key_t, T>, uint32_t>::Iterator {
|
||||
/***
|
||||
* Special iterator for FixedOrderedMultimap
|
||||
*/
|
||||
class Iterator: public ArrayList<std::pair<key_t, T>, size_t>::Iterator {
|
||||
public:
|
||||
Iterator() :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator() {
|
||||
ArrayList<std::pair<key_t, T>, size_t>::Iterator() {
|
||||
}
|
||||
|
||||
Iterator(std::pair<key_t, T> *pair) :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair) {
|
||||
ArrayList<std::pair<key_t, T>, size_t>::Iterator(pair) {
|
||||
}
|
||||
};
|
||||
|
||||
/***
|
||||
* Returns an iterator pointing to the first element
|
||||
* @return Iterator pointing to first element
|
||||
*/
|
||||
Iterator begin() const {
|
||||
return Iterator(&theMap[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator pointing to one element past the end
|
||||
* @return Iterator pointing to one element past the end
|
||||
*/
|
||||
Iterator end() const {
|
||||
return Iterator(&theMap[_size]);
|
||||
}
|
||||
|
||||
uint32_t size() const {
|
||||
/***
|
||||
* Returns the current size of the map (not maximum size!)
|
||||
* @return Current size
|
||||
*/
|
||||
size_t size() const{
|
||||
return _size;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) {
|
||||
if (_size == theMap.maxSize()) {
|
||||
return MAP_FULL;
|
||||
}
|
||||
uint32_t position = findNicePlace(key);
|
||||
memmove(static_cast<void*>(&theMap[position + 1]),static_cast<void*>(&theMap[position]),
|
||||
(_size - position) * sizeof(std::pair<key_t,T>));
|
||||
theMap[position].first = key;
|
||||
theMap[position].second = value;
|
||||
++_size;
|
||||
if (storedValue != nullptr) {
|
||||
*storedValue = Iterator(&theMap[position]);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
/**
|
||||
* Clears the map, does not deallocate any memory
|
||||
*/
|
||||
void clear(){
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(std::pair<key_t, T> pair) {
|
||||
return insert(pair.fist, pair.second);
|
||||
/**
|
||||
* Returns the maximum size of the map
|
||||
* @return Maximum size of the map
|
||||
*/
|
||||
size_t maxSize() const{
|
||||
return theMap.maxSize();
|
||||
}
|
||||
|
||||
ReturnValue_t exists(key_t key) const {
|
||||
ReturnValue_t result = KEY_DOES_NOT_EXIST;
|
||||
if (findFirstIndex(key) < _size) {
|
||||
result = HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/***
|
||||
* Used to insert a key and value separately.
|
||||
*
|
||||
* @param[in] key Key of the new element
|
||||
* @param[in] value Value of the new element
|
||||
* @param[in/out] (optional) storedValue On success this points to the new value, otherwise a nullptr
|
||||
* @return RETURN_OK if insert was successful, MAP_FULL if no space is available
|
||||
*/
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr);
|
||||
|
||||
ReturnValue_t erase(Iterator *iter) {
|
||||
uint32_t i;
|
||||
if ((i = findFirstIndex((*iter).value->first)) >= _size) {
|
||||
return KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
removeFromPosition(i);
|
||||
if (*iter != begin()) {
|
||||
(*iter)--;
|
||||
} else {
|
||||
*iter = begin();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
/***
|
||||
* Used to insert new pair instead of single values
|
||||
*
|
||||
* @param pair Pair to be inserted
|
||||
* @return RETURN_OK if insert was successful, MAP_FULL if no space is available
|
||||
*/
|
||||
ReturnValue_t insert(std::pair<key_t, T> pair);
|
||||
|
||||
ReturnValue_t erase(key_t key) {
|
||||
uint32_t i;
|
||||
if ((i = findFirstIndex(key)) >= _size) {
|
||||
return KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
do {
|
||||
removeFromPosition(i);
|
||||
i = findFirstIndex(key, i);
|
||||
} while (i < _size);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
/***
|
||||
* Can be used to check if a certain key is in the map
|
||||
* @param key Key to be checked
|
||||
* @return RETURN_OK if the key exists KEY_DOES_NOT_EXIST otherwise
|
||||
*/
|
||||
ReturnValue_t exists(key_t key) const;
|
||||
|
||||
Iterator find(key_t key) const {
|
||||
/***
|
||||
* Used to delete the element in the iterator
|
||||
*
|
||||
* The iterator will point to the element before or begin(),
|
||||
* but never to one element in front of the map.
|
||||
*
|
||||
* @warning The iterator needs to be valid and dereferenceable
|
||||
* @param[in/out] iter Pointer to iterator to the element that needs to be ereased
|
||||
* @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this
|
||||
*/
|
||||
ReturnValue_t erase(Iterator *iter);
|
||||
|
||||
/***
|
||||
* Used to erase by key
|
||||
* @param key Key to be erased
|
||||
* @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this
|
||||
*/
|
||||
ReturnValue_t erase(key_t key);
|
||||
|
||||
/***
|
||||
* Find returns the first appearance of the key
|
||||
*
|
||||
* If the key does not exist, it points to end()
|
||||
*
|
||||
* @param key Key to search for
|
||||
* @return Iterator pointing to the first entry of key
|
||||
*/
|
||||
Iterator find(key_t key) const{
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return end();
|
||||
}
|
||||
return Iterator(&theMap[findFirstIndex(key)]);
|
||||
};
|
||||
|
||||
/***
|
||||
* Finds first entry of the given key and returns a
|
||||
* pointer to the value
|
||||
*
|
||||
* @param key Key to search for
|
||||
* @param value Found value
|
||||
* @return RETURN_OK if it points to the value,
|
||||
* KEY_DOES_NOT_EXIST if the key is not in the map
|
||||
*/
|
||||
ReturnValue_t find(key_t key, T **value) const;
|
||||
|
||||
friend bool operator==(const typename FixedOrderedMultimap::Iterator& lhs,
|
||||
const typename FixedOrderedMultimap::Iterator& rhs) {
|
||||
return (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
ReturnValue_t find(key_t key, T **value) const {
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
*value = &theMap[findFirstIndex(key)].second;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
friend bool operator!=(const typename FixedOrderedMultimap::Iterator& lhs,
|
||||
const typename FixedOrderedMultimap::Iterator& rhs) {
|
||||
return not (lhs.value == rhs.value);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_size = 0;
|
||||
}
|
||||
private:
|
||||
typedef KEY_COMPARE compare;
|
||||
compare myComp;
|
||||
ArrayList<std::pair<key_t, T>, size_t> theMap;
|
||||
size_t _size;
|
||||
|
||||
uint32_t maxSize() const {
|
||||
return theMap.maxSize();
|
||||
}
|
||||
size_t findFirstIndex(key_t key, size_t startAt = 0) const;
|
||||
|
||||
size_t findNicePlace(key_t key) const;
|
||||
|
||||
void removeFromPosition(size_t position);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_H_ */
|
||||
#include "FixedOrderedMultimap.tpp"
|
||||
|
||||
#endif /* FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_ */
|
||||
|
109
container/FixedOrderedMultimap.tpp
Normal file
109
container/FixedOrderedMultimap.tpp
Normal file
@ -0,0 +1,109 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_TPP_
|
||||
#define FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_TPP_
|
||||
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline ReturnValue_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::insert(key_t key, T value, Iterator *storedValue) {
|
||||
if (_size == theMap.maxSize()) {
|
||||
return MAP_FULL;
|
||||
}
|
||||
size_t position = findNicePlace(key);
|
||||
memmove(static_cast<void*>(&theMap[position + 1]),static_cast<void*>(&theMap[position]),
|
||||
(_size - position) * sizeof(std::pair<key_t,T>));
|
||||
theMap[position].first = key;
|
||||
theMap[position].second = value;
|
||||
++_size;
|
||||
if (storedValue != nullptr) {
|
||||
*storedValue = Iterator(&theMap[position]);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline ReturnValue_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::insert(std::pair<key_t, T> pair) {
|
||||
return insert(pair.first, pair.second);
|
||||
}
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline ReturnValue_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::exists(key_t key) const {
|
||||
ReturnValue_t result = KEY_DOES_NOT_EXIST;
|
||||
if (findFirstIndex(key) < _size) {
|
||||
result = HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline ReturnValue_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::erase(Iterator *iter) {
|
||||
size_t i;
|
||||
if ((i = findFirstIndex((*iter).value->first)) >= _size) {
|
||||
return KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
removeFromPosition(i);
|
||||
if (*iter != begin()) {
|
||||
(*iter)--;
|
||||
} else {
|
||||
*iter = begin();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline ReturnValue_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::erase(key_t key) {
|
||||
size_t i;
|
||||
if ((i = findFirstIndex(key)) >= _size) {
|
||||
return KEY_DOES_NOT_EXIST;
|
||||
}
|
||||
do {
|
||||
removeFromPosition(i);
|
||||
i = findFirstIndex(key, i);
|
||||
} while (i < _size);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline ReturnValue_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::find(key_t key, T **value) const {
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
*value = &theMap[findFirstIndex(key)].second;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline size_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::findFirstIndex(key_t key, size_t startAt) const {
|
||||
if (startAt >= _size) {
|
||||
return startAt + 1;
|
||||
}
|
||||
size_t i = startAt;
|
||||
for (i = startAt; i < _size; ++i) {
|
||||
if (theMap[i].first == key) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline size_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::findNicePlace(key_t key) const {
|
||||
size_t i = 0;
|
||||
for (i = 0; i < _size; ++i) {
|
||||
if (myComp(key, theMap[i].first)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
template<typename key_t, typename T, typename KEY_COMPARE>
|
||||
inline void FixedOrderedMultimap<key_t, T, KEY_COMPARE>::removeFromPosition(size_t position) {
|
||||
if (_size <= position) {
|
||||
return;
|
||||
}
|
||||
memmove(static_cast<void*>(&theMap[position]), static_cast<void*>(&theMap[position + 1]),
|
||||
(_size - position - 1) * sizeof(std::pair<key_t,T>));
|
||||
--_size;
|
||||
}
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_TPP_ */
|
@ -3,26 +3,62 @@
|
||||
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include <utility>
|
||||
|
||||
/**
|
||||
* The Placement Factory is used to create objects at runtime in a specific pool.
|
||||
* In general, this should be avoided and it should only be used if you know what you are doing.
|
||||
* You are not allowed to use this container with a type that allocates memory internally like ArrayList.
|
||||
*
|
||||
* Also, you have to check the returned pointer in generate against nullptr!
|
||||
*
|
||||
* A backend of Type StorageManagerIF must be given as a place to store the new objects.
|
||||
* Therefore ThreadSafety is only provided by your StorageManager Implementation.
|
||||
*
|
||||
* Objects must be destroyed by the user with "destroy"! Otherwise the pool will not be cleared.
|
||||
*
|
||||
* The concept is based on the placement new operator.
|
||||
*
|
||||
* @warning Do not use with any Type that allocates memory internally!
|
||||
* @ingroup container
|
||||
*/
|
||||
class PlacementFactory {
|
||||
public:
|
||||
PlacementFactory(StorageManagerIF* backend) :
|
||||
dataBackend(backend) {
|
||||
}
|
||||
|
||||
/***
|
||||
* Generates an object of type T in the backend storage.
|
||||
*
|
||||
* @warning Do not use with any Type that allocates memory internally!
|
||||
*
|
||||
* @tparam T Type of Object
|
||||
* @param args Constructor Arguments to be passed
|
||||
* @return A pointer to the new object or a nullptr in case of failure
|
||||
*/
|
||||
template<typename T, typename ... Args>
|
||||
T* generate(Args&&... args) {
|
||||
store_address_t tempId;
|
||||
uint8_t* pData = NULL;
|
||||
uint8_t* pData = nullptr;
|
||||
ReturnValue_t result = dataBackend->getFreeElement(&tempId, sizeof(T),
|
||||
&pData);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
T* temp = new (pData) T(std::forward<Args>(args)...);
|
||||
return temp;
|
||||
}
|
||||
/***
|
||||
* Function to destroy the object allocated with generate and free space in backend.
|
||||
* This must be called by the user.
|
||||
*
|
||||
* @param thisElement Element to be destroyed
|
||||
* @return RETURN_OK if the element was destroyed, different errors on failure
|
||||
*/
|
||||
template<typename T>
|
||||
ReturnValue_t destroy(T* thisElement) {
|
||||
if (thisElement == nullptr){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
//Need to call destructor first, in case something was allocated by the object (shouldn't do that, however).
|
||||
thisElement->~T();
|
||||
uint8_t* pointer = (uint8_t*) (thisElement);
|
||||
|
@ -1,79 +0,0 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "SimpleRingBuffer.h"
|
||||
|
||||
|
||||
int main() {
|
||||
using namespace std;
|
||||
SimpleRingBuffer buffer(64, false);
|
||||
uint8_t data[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
|
||||
ReturnValue_t result = buffer.writeData(data, 8);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "writeData failed." << endl;
|
||||
}
|
||||
result = buffer.writeData(data, 8);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "writeData failed." << endl;
|
||||
}
|
||||
uint8_t buffer2[47] = {0};
|
||||
for (uint8_t count = 0; count<sizeof(buffer2); count++) {
|
||||
buffer2[count] = count;
|
||||
}
|
||||
result = buffer.writeData(buffer2, sizeof(buffer2));
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "writeData failed." << endl;
|
||||
}
|
||||
result = buffer.writeData(buffer2, sizeof(buffer2));
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "writeData failed." << endl;
|
||||
}
|
||||
uint8_t readBuffer[64] = {0};
|
||||
uint32_t writtenData = 0;
|
||||
result = buffer.readData(readBuffer, 12, true, &writtenData);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "readData failed." << endl;
|
||||
} else {
|
||||
cout << "Read data: " << writtenData << endl;
|
||||
for (uint32_t count = 0; count < writtenData; count++) {
|
||||
cout << hex << (uint16_t)readBuffer[count] << " ";
|
||||
}
|
||||
cout << dec << endl;
|
||||
}
|
||||
|
||||
result = buffer.readData(readBuffer, 60, true, &writtenData);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "readData failed." << endl;
|
||||
} else {
|
||||
cout << "Read data: " << writtenData << endl;
|
||||
for (uint32_t count = 0; count < writtenData; count++) {
|
||||
cout << hex << (uint16_t)readBuffer[count] << " ";
|
||||
}
|
||||
cout << dec << endl;
|
||||
}
|
||||
result = buffer.writeData(data, sizeof(data));
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "writeData failed." << endl;
|
||||
}
|
||||
result = buffer.readData(readBuffer, 60, true, &writtenData);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "readData failed." << endl;
|
||||
} else {
|
||||
cout << "Read data: " << writtenData << endl;
|
||||
for (uint32_t count = 0; count < writtenData; count++) {
|
||||
cout << hex << (uint16_t)readBuffer[count] << " ";
|
||||
}
|
||||
cout << dec << endl;
|
||||
}
|
||||
result = buffer.writeData(readBuffer, sizeof(readBuffer));
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "writeData failed." << endl;
|
||||
}
|
||||
result = buffer.writeData(readBuffer, sizeof(readBuffer)-1);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
cout << "writeData failed." << endl;
|
||||
} else {
|
||||
cout << "write done." << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,365 +0,0 @@
|
||||
#include "FixedArrayList.h"
|
||||
#include "SinglyLinkedList.h"
|
||||
#include "HybridIterator.h"
|
||||
|
||||
#include "FixedMap.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
|
||||
class Packet: public SinglyLinkedList {
|
||||
public:
|
||||
SinglyLinkedList::Element<uint32_t> element1;
|
||||
SinglyLinkedList::Element<uint32_t> element2;
|
||||
|
||||
Packet() {
|
||||
this->start = &element1;
|
||||
element1.next = &element2;
|
||||
}
|
||||
};
|
||||
|
||||
class Packet2: public SinglyLinkedList {
|
||||
public:
|
||||
SinglyLinkedList::Element<uint32_t> element1;
|
||||
SinglyLinkedList::Element<FixedArrayList<FixedArrayList<uint8_t, 5>, 2>> element2;
|
||||
SinglyLinkedList::Element<uint32_t> element3;
|
||||
|
||||
Packet2() {
|
||||
this->start = &element1;
|
||||
element1.next = &element2;
|
||||
element2.next = &element3;
|
||||
}
|
||||
};
|
||||
|
||||
class Packet3: public SinglyLinkedList {
|
||||
public:
|
||||
SinglyLinkedList::TypedElement<uint32_t> element1;
|
||||
SinglyLinkedList::TypedElement<uint32_t> element2;
|
||||
|
||||
Packet3() {
|
||||
this->start = &element1;
|
||||
element1.next = &element2;
|
||||
}
|
||||
};
|
||||
|
||||
void arrayList() {
|
||||
puts("** Array List **");
|
||||
FixedArrayList<uint32_t, 10, uint32_t> list;
|
||||
FixedArrayList<uint32_t, 10, uint32_t> list2;
|
||||
|
||||
list.size = 2;
|
||||
|
||||
list[0] = 0xcafecafe;
|
||||
|
||||
list[1] = 0x12345678;
|
||||
|
||||
uint8_t buffer[100];
|
||||
uint8_t *pointer = buffer;
|
||||
uint32_t size = 0;
|
||||
uint32_t maxSize = 100;
|
||||
uint32_t i;
|
||||
int32_t size2;
|
||||
|
||||
printf("printsize: %i\n", list.getPrintSize());
|
||||
|
||||
list.print(&pointer, &size, 100, true);
|
||||
|
||||
printf("buffer(%i):", size);
|
||||
for (i = 0; i < size; ++i) {
|
||||
printf("%02x", buffer[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
pointer = buffer;
|
||||
|
||||
size2 = size;
|
||||
|
||||
printf("list2 read: %x\n", list2.read(&pointer, &size2, true));
|
||||
|
||||
printf("list2(%i):", list2.size);
|
||||
for (ArrayList<uint32_t, uint32_t>::Iterator iter = list2.begin();
|
||||
iter != list2.end(); iter++) {
|
||||
printf("0x%04x ", *iter);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
HybridIterator<uint32_t, uint32_t> hiter(list.begin(),list.end());
|
||||
|
||||
printf("hybrid1: 0x%04x\n", *(hiter++));
|
||||
printf("hybrid2: 0x%04x\n", *hiter);
|
||||
|
||||
}
|
||||
|
||||
void allocatingList() {
|
||||
puts("** Allocating List **");
|
||||
ArrayList<uint8_t> myList(3), myList2(2);
|
||||
myList[0] = 0xab;
|
||||
myList[1] = 0xcd;
|
||||
myList.size = 2;
|
||||
|
||||
uint8_t buffer[100];
|
||||
uint8_t *pointer = buffer;
|
||||
uint32_t size = 0;
|
||||
uint32_t maxSize = 100;
|
||||
uint32_t i;
|
||||
int32_t size2;
|
||||
|
||||
myList.print(&pointer, &size, 100, true);
|
||||
|
||||
pointer = buffer;
|
||||
size2 = size;
|
||||
|
||||
printf("Read %x\n", myList2.read(&pointer, &size2, true));
|
||||
|
||||
printf("%x,%x\n", myList2[0], myList2[1]);
|
||||
|
||||
}
|
||||
|
||||
void linkedList() {
|
||||
puts("** Linked List **");
|
||||
uint8_t buffer[100];
|
||||
uint8_t *pointer = buffer;
|
||||
uint32_t size = 0;
|
||||
uint32_t maxSize = 100;
|
||||
uint32_t i;
|
||||
int32_t size2;
|
||||
|
||||
Packet myPacket;
|
||||
myPacket.element1.entry = 0x12345678;
|
||||
myPacket.element2.entry = 0x9abcdef0;
|
||||
|
||||
pointer = buffer;
|
||||
size = 0;
|
||||
ReturnValue_t result = myPacket.print(&pointer, &size, 100, true);
|
||||
|
||||
printf("result %02x\n", result);
|
||||
|
||||
printf("printsize: %i\n", myPacket.getPrintSize());
|
||||
|
||||
printf("buffer(%i):", size);
|
||||
for (i = 0; i < size; ++i) {
|
||||
printf("%02x", buffer[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
Packet3 myPacket3;
|
||||
|
||||
myPacket3.element1.entry = 0x12345678;
|
||||
myPacket3.element2.entry = 0xabcdeff;
|
||||
|
||||
SinglyLinkedList::TypedIterator<uint32_t> titer(&myPacket3.element1);
|
||||
|
||||
printf("0x%04x\n", *titer);
|
||||
|
||||
HybridIterator<uint32_t, uint32_t> hiter(&myPacket3.element1);
|
||||
|
||||
printf("hybrid1: 0x%04x\n", *hiter);
|
||||
hiter++;
|
||||
printf("hybrid2: 0x%04x\n", *hiter);
|
||||
}
|
||||
|
||||
void complex() {
|
||||
puts("** complex **");
|
||||
uint8_t buffer[100];
|
||||
uint8_t *pointer = buffer;
|
||||
uint32_t size = 0;
|
||||
uint32_t maxSize = 100;
|
||||
uint32_t i;
|
||||
int32_t size2 = size;
|
||||
|
||||
Packet myPacket2;
|
||||
|
||||
size2 = size;
|
||||
pointer = buffer;
|
||||
|
||||
myPacket2.read(&pointer, &size2, true);
|
||||
|
||||
printf("packet: 0x%04x, 0x%04x\n", myPacket2.element1.entry,
|
||||
myPacket2.element2.entry);
|
||||
|
||||
buffer[0] = 0x12;
|
||||
buffer[1] = 0x34;
|
||||
buffer[2] = 0x56;
|
||||
buffer[3] = 0x78;
|
||||
buffer[4] = 0x2;
|
||||
buffer[5] = 0x3;
|
||||
buffer[6] = 0xab;
|
||||
buffer[7] = 0xcd;
|
||||
buffer[8] = 0xef;
|
||||
buffer[9] = 0x2;
|
||||
buffer[10] = 0x11;
|
||||
buffer[11] = 0x22;
|
||||
buffer[12] = 0xca;
|
||||
buffer[13] = 0xfe;
|
||||
buffer[14] = 0x5a;
|
||||
buffer[15] = 0xfe;
|
||||
|
||||
pointer = buffer;
|
||||
size2 = 23;
|
||||
|
||||
Packet2 p2;
|
||||
|
||||
ReturnValue_t result = p2.read(&pointer, &size2, true);
|
||||
printf("result is %02x\n", result);
|
||||
|
||||
printf("%04x; %i: %i: %x %x %x; %i: %x %x;; %04x\n", p2.element1.entry,
|
||||
p2.element2.entry.size, p2.element2.entry[0].size,
|
||||
p2.element2.entry[0][0], p2.element2.entry[0][1],
|
||||
p2.element2.entry[0][2], p2.element2.entry[1].size,
|
||||
p2.element2.entry[1][0], p2.element2.entry[1][1],
|
||||
p2.element3.entry);
|
||||
|
||||
}
|
||||
*/
|
||||
struct Test {
|
||||
uint32_t a;
|
||||
uint32_t b;
|
||||
};
|
||||
|
||||
template<typename key_t, typename T>
|
||||
void printMap(FixedMap<key_t, T> *map) {
|
||||
typename FixedMap<key_t, T>::Iterator iter;
|
||||
printf("Map (%i): ", map->getSize());
|
||||
for (iter = map->begin(); iter != map->end(); ++iter) {
|
||||
printf("%x:%08x,%08x ", iter.value->first, (*iter).a, (*iter).b);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void map() {
|
||||
puts("** Map **");
|
||||
typename FixedMap<T, Test>::Iterator iter;
|
||||
ReturnValue_t result;
|
||||
FixedMap<T, Test> myMap(5);
|
||||
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
Test a;
|
||||
a.a = 0x01234567;
|
||||
a.b = 0xabcdef89;
|
||||
|
||||
myMap.insert(1, a);
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
a.a = 0;
|
||||
|
||||
myMap.insert(2, a);
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
printf("2 exists: %x\n", myMap.exists(0x02));
|
||||
|
||||
printf("ff exists: %x\n", myMap.exists(0xff));
|
||||
|
||||
a.a = 1;
|
||||
printf("insert 0x2: %x\n", myMap.insert(2, a));
|
||||
|
||||
result = myMap.insert(0xff, a);
|
||||
a.a = 0x44;
|
||||
result = myMap.insert(0xab, a);
|
||||
result = myMap.insert(0xa, a);
|
||||
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
printf("insert 0x5: %x\n", myMap.insert(5, a));
|
||||
|
||||
printf("erase 0xfe: %x\n", myMap.erase(0xfe));
|
||||
|
||||
printf("erase 0x2: %x\n", myMap.erase(0x2));
|
||||
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
printf("erase 0xab: %x\n", myMap.erase(0xab));
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
printf("insert 0x5: %x\n", myMap.insert(5, a));
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
iter = myMap.begin();
|
||||
++iter;
|
||||
++iter;
|
||||
++iter;
|
||||
|
||||
printf("iter: %i: %x,%x\n",iter.value->first, iter->a, iter->b);
|
||||
|
||||
myMap.erase(&iter);
|
||||
|
||||
printf("iter: %i: %x,%x\n",iter.value->first, iter->a, iter->b);
|
||||
printMap<T, Test>(&myMap);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void mapPrint() {
|
||||
puts("** Map Print **");
|
||||
FixedMap<uint16_t, Packet2> myMap(5);
|
||||
Packet2 myPacket;
|
||||
myPacket.element1.entry = 0x12345678;
|
||||
|
||||
myPacket.element2.entry[0][0] = 0xab;
|
||||
myPacket.element2.entry[0][1] = 0xcd;
|
||||
myPacket.element2.entry[0].size = 2;
|
||||
myPacket.element2.entry.size = 1;
|
||||
|
||||
myPacket.element3.entry = 0xabcdef90;
|
||||
|
||||
myMap.insert(0x1234, myPacket);
|
||||
|
||||
uint8_t buffer[100];
|
||||
uint32_t size = 0, i;
|
||||
uint8_t *pointer = buffer;
|
||||
|
||||
printf("printsize: %i\n", myMap.getPrintSize());
|
||||
|
||||
SerializeAdapter<FixedMap<uint16_t, Packet2>>::print(&myMap, &pointer,
|
||||
&size, 100, false);
|
||||
|
||||
printf("buffer(%i):", size);
|
||||
for (i = 0; i < size; ++i) {
|
||||
printf("%02x", buffer[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
int32_t size2 = size;
|
||||
pointer = buffer;
|
||||
|
||||
FixedMap<uint16_t, Packet2> myMap2(5);
|
||||
|
||||
ReturnValue_t result = SerializeAdapter<FixedMap<uint16_t, Packet2>>::read(
|
||||
&myMap2, &pointer, &size2, false);
|
||||
|
||||
Packet2 *myPacket2 = myMap2.find(0x1234);
|
||||
|
||||
printf("Map (%i): Packet2: %x, Array (%i): Array (%i): %x, %x; %x\n",
|
||||
myMap2.getSize(), myPacket2->element1.entry,
|
||||
myPacket2->element2.entry.size, myPacket2->element2.entry[0].size,
|
||||
myPacket2->element2.entry[0][0], myPacket2->element2.entry[0][1],
|
||||
myPacket2->element3.entry);
|
||||
|
||||
}
|
||||
|
||||
void empty() {
|
||||
puts("** Empty **");
|
||||
ArrayList<uint32_t> list(0);
|
||||
printf("%p %p\n", list.front(), list.back());
|
||||
}
|
||||
*/
|
||||
|
||||
int main(void) {
|
||||
|
||||
// arrayList();
|
||||
// linkedList();
|
||||
// allocatingList();
|
||||
// complex();
|
||||
|
||||
map<uint32_t>();
|
||||
//
|
||||
// mapPrint();
|
||||
|
||||
// empty();
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
@ -18,7 +18,7 @@ MapPacketExtraction::MapPacketExtraction(uint8_t setMapId,
|
||||
object_id_t setPacketDestination) :
|
||||
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0), bufferPosition(
|
||||
packetBuffer), packetDestination(setPacketDestination), packetStore(
|
||||
NULL), tcQueueId(MessageQueueSenderIF::NO_QUEUE) {
|
||||
NULL), tcQueueId(MessageQueueIF::NO_QUEUE) {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
}
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @file PollingSlot.cpp
|
||||
* @brief This file defines the PollingSlot class.
|
||||
* @date 19.12.2012
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "FixedSequenceSlot.h"
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask) :
|
||||
handler(NULL), pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
handler = objectManager->get<ExecutableObjectIF>(handlerId);
|
||||
handler->setTaskIF(executingTask);
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
@ -5,7 +5,7 @@ HealthDevice::HealthDevice(object_id_t setObjectId,
|
||||
MessageQueueId_t parentQueue) :
|
||||
SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(
|
||||
parentQueue), commandQueue(), healthHelper(this, setObjectId) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(3, CommandMessage::COMMAND_MESSAGE_SIZE);
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(3);
|
||||
}
|
||||
|
||||
HealthDevice::~HealthDevice() {
|
||||
|
@ -19,6 +19,7 @@ enum {
|
||||
SYSTEM_MANAGER_1 = 75,
|
||||
SYSTEM_1 = 79,
|
||||
PUS_SERVICE_1 = 80,
|
||||
PUS_SERVICE_9 = 89,
|
||||
PUS_SERVICE_17 = 97,
|
||||
FW_SUBSYSTEM_ID_RANGE
|
||||
};
|
||||
|
@ -1,124 +1,96 @@
|
||||
/**
|
||||
* @file CommandMessage.cpp
|
||||
* @brief This file defines the CommandMessage class.
|
||||
* @date 20.06.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "../devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "../health/HealthMessage.h"
|
||||
#include "CommandMessage.h"
|
||||
#include "../memory/MemoryMessage.h"
|
||||
#include "../modes/ModeMessage.h"
|
||||
#include "../monitoring/MonitoringMessage.h"
|
||||
#include "../subsystem/modes/ModeSequenceMessage.h"
|
||||
#include "../tmstorage/TmStoreMessage.h"
|
||||
#include "../parameters/ParameterMessage.h"
|
||||
|
||||
namespace messagetypes {
|
||||
void clearMissionMessage(CommandMessage* message);
|
||||
}
|
||||
|
||||
#include "CommandMessageCleaner.h"
|
||||
#include <cstring>
|
||||
|
||||
CommandMessage::CommandMessage() {
|
||||
this->messageSize = COMMAND_MESSAGE_SIZE;
|
||||
setCommand(CMD_NONE);
|
||||
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
||||
setCommand(CMD_NONE);
|
||||
}
|
||||
|
||||
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
|
||||
uint32_t parameter2) {
|
||||
this->messageSize = COMMAND_MESSAGE_SIZE;
|
||||
setCommand(command);
|
||||
setParameter(parameter1);
|
||||
setParameter2(parameter2);
|
||||
uint32_t parameter2) {
|
||||
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
||||
setCommand(command);
|
||||
setParameter(parameter1);
|
||||
setParameter2(parameter2);
|
||||
}
|
||||
|
||||
Command_t CommandMessage::getCommand() const {
|
||||
Command_t command;
|
||||
memcpy(&command, getData(), sizeof(Command_t));
|
||||
return command;
|
||||
Command_t command;
|
||||
std::memcpy(&command, MessageQueueMessage::getData(), sizeof(Command_t));
|
||||
return command;
|
||||
}
|
||||
|
||||
void CommandMessage::setCommand(Command_t command) {
|
||||