From 424c82ce165e1da122729ce058be19a32ade7dfa Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 18 Jan 2020 23:07:43 +0100 Subject: [PATCH] Extracted one logic block To increase readability --- datapool/PoolRawAccess.cpp | 47 ++++++++++++++++++++------------------ datapool/PoolRawAccess.h | 1 + 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 4eeba4f5..899eedd6 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -14,33 +14,13 @@ PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, } } -PoolRawAccess::~PoolRawAccess() { - -} +PoolRawAccess::~PoolRawAccess() {} ReturnValue_t PoolRawAccess::read() { ReturnValue_t result = RETURN_FAILED; PoolEntryIF* read_out = ::dataPool.getRawData(dataPoolId); if (read_out != NULL) { - valid = read_out->getValid(); - if (read_out->getSize() > arrayEntry) { - arraySize = read_out->getSize(); - typeSize = read_out->getByteSize() / read_out->getSize(); - type = read_out->getType(); - if (typeSize <= sizeof(value)) { - uint16_t arrayPosition = arrayEntry * typeSize; - sizeTillEnd = read_out->getByteSize() - arrayPosition; - uint8_t* ptr = - &((uint8_t*) read_out->getRawData())[arrayPosition]; - memcpy(value, ptr, typeSize); - return HasReturnvaluesIF::RETURN_OK; - } else { - result = READ_TYPE_TOO_LARGE; - } - } else { - //debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl; - result = READ_INDEX_TOO_LARGE; - } + result = handleReadOut(read_out); } else { result = READ_ENTRY_NON_EXISTENT; } @@ -62,6 +42,29 @@ ReturnValue_t PoolRawAccess::read() { return result; } +ReturnValue_t PoolRawAccess::handleReadOut(PoolEntryIF* read_out) { + ReturnValue_t result = RETURN_FAILED; + valid = read_out->getValid(); + if (read_out->getSize() > arrayEntry) { + arraySize = read_out->getSize(); + typeSize = read_out->getByteSize() / read_out->getSize(); + type = read_out->getType(); + if (typeSize <= sizeof(value)) { + uint16_t arrayPosition = arrayEntry * typeSize; + sizeTillEnd = read_out->getByteSize() - arrayPosition; + uint8_t* ptr = &((uint8_t*) read_out->getRawData())[arrayPosition]; + memcpy(value, ptr, typeSize); + return RETURN_OK; + } else { + result = READ_TYPE_TOO_LARGE; + } + } else { + //debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl; + result = READ_INDEX_TOO_LARGE; + } + return result; +} + ReturnValue_t PoolRawAccess::commit() { PoolEntryIF* write_back = ::dataPool.getRawData(dataPoolId); if ((write_back != NULL) && (readWriteMode != VAR_READ)) { diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 432d9ad9..5fb482f0 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -156,6 +156,7 @@ protected: */ ReturnValue_t commit(); + ReturnValue_t handleReadOut(PoolEntryIF* read_out); private: /** * \brief To access the correct data pool entry on read and commit calls, the data pool id