New Pool List Initializer.

Needs testing !!!
This commit is contained in:
Robin Müller 2020-01-23 15:45:21 +01:00
parent d330958abb
commit 6eedb3f097
2 changed files with 8 additions and 6 deletions

View File

@ -2,12 +2,13 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h>
template <typename T>
PoolEntry<T>::PoolEntry( T* initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) {
PoolEntry<T>::PoolEntry(std::initializer_list<T> initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) {
this->address = new T[this->length];
if (initValue != NULL) {
memcpy(this->address, initValue, this->getByteSize() );
} else {
memset(this->address, 0, this->getByteSize() );
if(initValue.size() == 0) {
memset(this->address, 0, this->getByteSize());
}
else {
memcpy(this->address, initValue.begin(), this->getByteSize());
}
}

View File

@ -5,6 +5,7 @@
#include <framework/datapool/PoolEntryIF.h>
#include <stddef.h>
#include <cstring>
#include <initializer_list>
/**
* \brief This is a small helper class that defines a single data pool entry.
*
@ -31,7 +32,7 @@ public:
* \param set_length Defines the array length of this entry.
* \param set_valid Sets the initialization flag. It is invalid (0) by default.
*/
PoolEntry( T* initValue = NULL, uint8_t set_length = 1, uint8_t set_valid = 0 );
PoolEntry( std::initializer_list<T> initValue = {}, uint8_t set_length = 1, uint8_t set_valid = 0 );
/**
* \brief The allocated memory for the variable is freed in the destructor.
* \details As the data pool is global, this dtor is only called on program exit.