From 6eedb3f09748ed698ece38cb9fc5be6ebe1d3c66 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 23 Jan 2020 15:45:21 +0100 Subject: [PATCH] New Pool List Initializer. Needs testing !!! --- datapool/PoolEntry.cpp | 11 ++++++----- datapool/PoolEntry.h | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/datapool/PoolEntry.cpp b/datapool/PoolEntry.cpp index f2968c32..af5584d8 100644 --- a/datapool/PoolEntry.cpp +++ b/datapool/PoolEntry.cpp @@ -2,12 +2,13 @@ #include template -PoolEntry::PoolEntry( T* initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) { +PoolEntry::PoolEntry(std::initializer_list 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()); } } diff --git a/datapool/PoolEntry.h b/datapool/PoolEntry.h index ce41a991..97364bf0 100644 --- a/datapool/PoolEntry.h +++ b/datapool/PoolEntry.h @@ -5,6 +5,7 @@ #include #include #include +#include /** * \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 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.