From 761a0c9bac4ba94e88eb285eecf88ca9665b5eab Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Apr 2022 15:39:02 +0200 Subject: [PATCH] new pool ctor which only takes len --- src/fsfw/datapool/PoolEntry.cpp | 14 ++++++++++---- src/fsfw/datapool/PoolEntry.h | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/fsfw/datapool/PoolEntry.cpp b/src/fsfw/datapool/PoolEntry.cpp index fd110e6c..d8e1d634 100644 --- a/src/fsfw/datapool/PoolEntry.cpp +++ b/src/fsfw/datapool/PoolEntry.cpp @@ -7,13 +7,19 @@ #include "fsfw/serviceinterface/ServiceInterface.h" template -PoolEntry::PoolEntry(std::initializer_list initValue, bool setValid) - : length(static_cast(initValue.size())), valid(setValid) { +PoolEntry::PoolEntry(uint8_t len, bool setValid): length(len), valid(setValid) { this->address = new T[this->length]; - if (initValue.size() == 0) { + std::memset(this->address, 0, this->getByteSize()); +} + +template +PoolEntry::PoolEntry(std::initializer_list initValues, bool setValid) + : length(static_cast(initValues.size())), valid(setValid) { + this->address = new T[this->length]; + if (initValues.size() == 0) { std::memset(this->address, 0, this->getByteSize()); } else { - std::copy(initValue.begin(), initValue.end(), this->address); + std::copy(initValues.begin(), initValues.end(), this->address); } } diff --git a/src/fsfw/datapool/PoolEntry.h b/src/fsfw/datapool/PoolEntry.h index d3d80f09..8bf9a41c 100644 --- a/src/fsfw/datapool/PoolEntry.h +++ b/src/fsfw/datapool/PoolEntry.h @@ -33,6 +33,9 @@ class PoolEntry : public PoolEntryIF { "instead! The ECSS standard defines a boolean as a one bit " "field. Therefore it is preferred to store a boolean as an " "uint8_t"); + + PoolEntry(uint8_t len = 1, bool setValid = false); + /** * @brief In the classe's constructor, space is allocated on the heap and * potential initialization values are copied to that space. @@ -49,7 +52,7 @@ class PoolEntry : public PoolEntryIF { * @param setValid * Sets the initialization flag. It is invalid by default. */ - PoolEntry(std::initializer_list initValue = {0}, bool setValid = false); + PoolEntry(std::initializer_list initValue, bool setValid = false); /** * @brief In the classe's constructor, space is allocated on the heap and