Merge branch 'master' into mueller/repairedHostOsal
This commit is contained in:
commit
296f6a928f
@ -19,32 +19,46 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Insert value into FIFO
|
* Insert value into FIFO
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return RETURN_OK on success, FULL if full
|
||||||
*/
|
*/
|
||||||
ReturnValue_t insert(T value);
|
ReturnValue_t insert(T value);
|
||||||
/**
|
/**
|
||||||
* Retrieve item from FIFO. This removes the item from the FIFO.
|
* Retrieve item from FIFO. This removes the item from the FIFO.
|
||||||
* @param value
|
* @param value Must point to a valid T
|
||||||
* @return
|
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
||||||
*/
|
*/
|
||||||
ReturnValue_t retrieve(T *value);
|
ReturnValue_t retrieve(T *value);
|
||||||
/**
|
/**
|
||||||
* Retrieve item from FIFO without removing it from FIFO.
|
* Retrieve item from FIFO without removing it from FIFO.
|
||||||
* @param value
|
* @param value Must point to a valid T
|
||||||
* @return
|
* @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed
|
||||||
*/
|
*/
|
||||||
ReturnValue_t peek(T * value);
|
ReturnValue_t peek(T * value);
|
||||||
/**
|
/**
|
||||||
* Remove item from FIFO.
|
* Remove item from FIFO.
|
||||||
* @return
|
* @return RETURN_OK on success, EMPTY if empty
|
||||||
*/
|
*/
|
||||||
ReturnValue_t pop();
|
ReturnValue_t pop();
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Check if FIFO is empty
|
||||||
|
* @return True if empty, False if not
|
||||||
|
*/
|
||||||
bool empty();
|
bool empty();
|
||||||
|
/***
|
||||||
|
* Check if FIFO is Full
|
||||||
|
* @return True if full, False if not
|
||||||
|
*/
|
||||||
bool full();
|
bool full();
|
||||||
|
/***
|
||||||
|
* Current used size (elements) used
|
||||||
|
* @return size_t in elements
|
||||||
|
*/
|
||||||
size_t size();
|
size_t size();
|
||||||
|
/***
|
||||||
|
* Get maximal capacity of fifo
|
||||||
|
* @return size_t with max capacity of this fifo
|
||||||
|
*/
|
||||||
size_t getMaxCapacity() const;
|
size_t getMaxCapacity() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -26,6 +26,9 @@ inline ReturnValue_t FIFOBase<T>::retrieve(T* value) {
|
|||||||
if (empty()) {
|
if (empty()) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
} else {
|
} else {
|
||||||
|
if (value == nullptr){
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
*value = values[readIndex];
|
*value = values[readIndex];
|
||||||
readIndex = next(readIndex);
|
readIndex = next(readIndex);
|
||||||
--currentSize;
|
--currentSize;
|
||||||
@ -38,6 +41,9 @@ inline ReturnValue_t FIFOBase<T>::peek(T* value) {
|
|||||||
if(empty()) {
|
if(empty()) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
} else {
|
} else {
|
||||||
|
if (value == nullptr){
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
*value = values[readIndex];
|
*value = values[readIndex];
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,13 @@
|
|||||||
#define FIXEDARRAYLIST_H_
|
#define FIXEDARRAYLIST_H_
|
||||||
|
|
||||||
#include "ArrayList.h"
|
#include "ArrayList.h"
|
||||||
|
#include <cmath>
|
||||||
/**
|
/**
|
||||||
* \ingroup container
|
* \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> {
|
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:
|
private:
|
||||||
T data[MAX_SIZE];
|
T data[MAX_SIZE];
|
||||||
public:
|
public:
|
||||||
@ -18,11 +20,13 @@ public:
|
|||||||
ArrayList<T, count_t>(data, MAX_SIZE) {
|
ArrayList<T, count_t>(data, MAX_SIZE) {
|
||||||
memcpy(this->data, other.data, sizeof(this->data));
|
memcpy(this->data, other.data, sizeof(this->data));
|
||||||
this->entries = data;
|
this->entries = data;
|
||||||
|
this->size = other.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedArrayList& operator=(FixedArrayList other) {
|
FixedArrayList& operator=(FixedArrayList other) {
|
||||||
memcpy(this->data, other.data, sizeof(this->data));
|
memcpy(this->data, other.data, sizeof(this->data));
|
||||||
this->entries = data;
|
this->entries = data;
|
||||||
|
this->size = other.size;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,26 +3,62 @@
|
|||||||
|
|
||||||
#include "../storagemanager/StorageManagerIF.h"
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
#include <utility>
|
#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 {
|
class PlacementFactory {
|
||||||
public:
|
public:
|
||||||
PlacementFactory(StorageManagerIF* backend) :
|
PlacementFactory(StorageManagerIF* backend) :
|
||||||
dataBackend(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>
|
template<typename T, typename ... Args>
|
||||||
T* generate(Args&&... args) {
|
T* generate(Args&&... args) {
|
||||||
store_address_t tempId;
|
store_address_t tempId;
|
||||||
uint8_t* pData = NULL;
|
uint8_t* pData = nullptr;
|
||||||
ReturnValue_t result = dataBackend->getFreeElement(&tempId, sizeof(T),
|
ReturnValue_t result = dataBackend->getFreeElement(&tempId, sizeof(T),
|
||||||
&pData);
|
&pData);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
T* temp = new (pData) T(std::forward<Args>(args)...);
|
T* temp = new (pData) T(std::forward<Args>(args)...);
|
||||||
return temp;
|
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>
|
template<typename T>
|
||||||
ReturnValue_t destroy(T* thisElement) {
|
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).
|
//Need to call destructor first, in case something was allocated by the object (shouldn't do that, however).
|
||||||
thisElement->~T();
|
thisElement->~T();
|
||||||
uint8_t* pointer = (uint8_t*) (thisElement);
|
uint8_t* pointer = (uint8_t*) (thisElement);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user