pool entry update

This commit is contained in:
Robin Müller 2021-01-13 12:02:23 +01:00
parent 5639273d9b
commit eb6a851935
2 changed files with 58 additions and 45 deletions

View File

@ -1,32 +1,24 @@
#include "PoolEntry.h" #include "PoolEntry.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../serviceinterface/ServiceInterface.h"
#include "../globalfunctions/arrayprinter.h" #include "../globalfunctions/arrayprinter.h"
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
template <typename T> template <typename T>
PoolEntry<T>::PoolEntry(std::initializer_list<T> initValue, uint8_t setLength, PoolEntry<T>::PoolEntry(std::initializer_list<T> initValue, bool setValid ):
bool setValid ) : length(setLength), valid(setValid) { length(initValue.size()), valid(setValid) {
this->address = new T[this->length]; this->address = new T[this->length];
if(initValue.size() == 0) { if(initValue.size() == 0) {
std::memset(this->address, 0, this->getByteSize()); std::memset(this->address, 0, this->getByteSize());
} }
else if (initValue.size() != setLength){
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "PoolEntry: setLength is not equal to initializer list"
"length! Performing zero initialization with given setLength"
<< std::endl;
#endif
std::memset(this->address, 0, this->getByteSize());
}
else { else {
std::copy(initValue.begin(), initValue.end(), this->address); std::copy(initValue.begin(), initValue.end(), this->address);
} }
} }
template <typename T> template <typename T>
PoolEntry<T>::PoolEntry( T* initValue, uint8_t setLength, bool setValid ) : PoolEntry<T>::PoolEntry(T* initValue, uint8_t setLength, bool setValid):
length(setLength), valid(setValid) { length(setLength), valid(setValid) {
this->address = new T[this->length]; this->address = new T[this->length];
if (initValue != nullptr) { if (initValue != nullptr) {
@ -70,14 +62,26 @@ bool PoolEntry<T>::getValid() {
template <typename T> template <typename T>
void PoolEntry<T>::print() { void PoolEntry<T>::print() {
const char* validString = nullptr;
if(valid) {
validString = "Valid";
}
else {
validString = "Invalid";
}
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Pool Entry Validity: " << sif::info << "PoolEntry information." << std::endl;
(this->valid? " (valid) " : " (invalid) ") << std::endl; sif::info << "PoolEntry validity: " << validString << std::endl;
#endif #else
arrayprinter::print(reinterpret_cast<uint8_t*>(address), length); sif::printInfo("PoolEntry information.\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1 sif::printInfo("PoolEntry validity: %s\n", validString);
sif::debug << std::dec << std::endl;
#endif #endif
arrayprinter::print(reinterpret_cast<uint8_t*>(address), getByteSize());
}
template<typename T>
inline T* PoolEntry<T>::getDataPtr() {
return this->address;
} }
template<typename T> template<typename T>
@ -88,8 +92,10 @@ Type PoolEntry<T>::getType() {
template class PoolEntry<uint8_t>; template class PoolEntry<uint8_t>;
template class PoolEntry<uint16_t>; template class PoolEntry<uint16_t>;
template class PoolEntry<uint32_t>; template class PoolEntry<uint32_t>;
template class PoolEntry<uint64_t>;
template class PoolEntry<int8_t>; template class PoolEntry<int8_t>;
template class PoolEntry<int16_t>; template class PoolEntry<int16_t>;
template class PoolEntry<int32_t>; template class PoolEntry<int32_t>;
template class PoolEntry<int64_t>;
template class PoolEntry<float>; template class PoolEntry<float>;
template class PoolEntry<double>; template class PoolEntry<double>;

View File

@ -35,24 +35,22 @@ public:
"uint8_t"); "uint8_t");
/** /**
* @brief In the classe's constructor, space is allocated on the heap and * @brief In the classe's constructor, space is allocated on the heap and
* potential init values are copied to that space. * potential initialization values are copied to that space.
* @details * @details
* Not passing any arguments will initialize an non-array pool entry * Not passing any arguments will initialize an non-array pool entry
* (setLength = 1) with an initial invalid state. * with an initial invalid state and the value 0.
* Please note that if an initializer list is passed, the correct * Please note that if an initializer list is passed, the length of the
* corresponding length should be passed too, otherwise a zero * initializer list needs to be correct for vector entries because
* initialization will be performed with the given setLength. * required allocated space will be deduced from the initializer list length
* and the pool entry type.
* @param initValue * @param initValue
* Initializer list with values to initialize with, for example {0,0} to * Initializer list with values to initialize with, for example {0, 0} to
* initialize the two entries to zero. * initialize the a pool entry of a vector with two entries to 0.
* @param setLength
* Defines the array length of this entry. Should be equal to the
* intializer list length.
* @param setValid * @param setValid
* Sets the initialization flag. It is invalid by default. * Sets the initialization flag. It is invalid by default.
*/ */
PoolEntry(std::initializer_list<T> initValue = {}, uint8_t setLength = 1, PoolEntry(std::initializer_list<T> initValue = {0}, bool setValid = false);
bool setValid = false);
/** /**
* @brief In the classe's constructor, space is allocated on the heap and * @brief In the classe's constructor, space is allocated on the heap and
* potential init values are copied to that space. * potential init values are copied to that space.
@ -66,9 +64,9 @@ public:
*/ */
PoolEntry(T* initValue, uint8_t setLength = 1, bool setValid = false); PoolEntry(T* initValue, uint8_t setLength = 1, bool setValid = false);
//! Explicitely deleted copy ctor, copying is not allowed! //! Explicitely deleted copy ctor, copying is not allowed.
PoolEntry(const PoolEntry&) = delete; PoolEntry(const PoolEntry&) = delete;
//! Explicitely deleted copy assignment, copying is not allowed! //! Explicitely deleted copy assignment, copying is not allowed.
PoolEntry& operator=(const PoolEntry&) = delete; PoolEntry& operator=(const PoolEntry&) = delete;
/** /**
@ -82,21 +80,16 @@ public:
~PoolEntry(); ~PoolEntry();
/** /**
* @brief This is the address pointing to the allocated memory. * Return typed pointer to start of data.
* @return
*/ */
T* address; T* getDataPtr();
/**
* @brief This attribute stores the length information.
*/
uint8_t length;
/**
* @brief Here, the validity information for a variable is stored.
* Every entry (single variable or vector) has one valid flag.
*/
uint8_t valid;
/** /**
* @brief getSize returns the array size of the entry. * @brief getSize returns the array size of the entry.
* @details A single parameter has size 1. * @details
* For non-array pool entries return type size, for vector entries
* return type size times the number of entries.
*/ */
uint8_t getSize(); uint8_t getSize();
/** /**
@ -123,8 +116,22 @@ public:
* information to the screen. It prints all array entries in a row. * information to the screen. It prints all array entries in a row.
*/ */
void print(); void print();
Type getType(); Type getType();
private:
/**
* @brief This attribute stores the length information.
*/
uint8_t length;
/**
* @brief Here, the validity information for a variable is stored.
* Every entry (single variable or vector) has one valid flag.
*/
uint8_t valid;
/**
* @brief This is the address pointing to the allocated memory.
*/
T* address;
}; };
#endif /* FSFW_DATAPOOL_POOLENTRY_H_ */ #endif /* FSFW_DATAPOOL_POOLENTRY_H_ */