WIP: somethings wrong.. #19
@ -176,10 +176,9 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(
|
|||||||
template<uint8_t NUMBER_OF_POOLS>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
inline AccessorPair LocalPool<NUMBER_OF_POOLS>::modifyData(
|
inline AccessorPair LocalPool<NUMBER_OF_POOLS>::modifyData(
|
||||||
store_address_t storeId) {
|
store_address_t storeId) {
|
||||||
uint8_t* tempData = nullptr;
|
|
||||||
StorageAccessor accessor(storeId, this);
|
StorageAccessor accessor(storeId, this);
|
||||||
ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_);
|
ReturnValue_t status = modifyData(storeId, &accessor.dataPointer,
|
||||||
accessor.constDataPointer = tempData;
|
&accessor.size_);
|
||||||
accessor.assignConstPointer();
|
accessor.assignConstPointer();
|
||||||
return AccessorPair(status, std::move(accessor));
|
return AccessorPair(status, std::move(accessor));
|
||||||
}
|
}
|
||||||
@ -187,9 +186,9 @@ inline AccessorPair LocalPool<NUMBER_OF_POOLS>::modifyData(
|
|||||||
template<uint8_t NUMBER_OF_POOLS>
|
template<uint8_t NUMBER_OF_POOLS>
|
||||||
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
|
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
|
||||||
store_address_t storeId, StorageAccessor& storeAccessor) {
|
store_address_t storeId, StorageAccessor& storeAccessor) {
|
||||||
|
storeAccessor.assignStore(this);
|
||||||
ReturnValue_t status = modifyData(storeId, &storeAccessor.dataPointer,
|
ReturnValue_t status = modifyData(storeId, &storeAccessor.dataPointer,
|
||||||
&storeAccessor.size_);
|
&storeAccessor.size_);
|
||||||
storeAccessor.assignStore(this);
|
|
||||||
storeAccessor.assignConstPointer();
|
storeAccessor.assignConstPointer();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,14 @@ ConstStorageAccessor::~ConstStorageAccessor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other):
|
||||||
|
constDataPointer(other.constDataPointer), storeId(other.storeId),
|
||||||
|
size_(other.size_), store(other.store), deleteData(other.deleteData),
|
||||||
|
internalState(other.internalState) {
|
||||||
|
// This prevent premature deletion
|
||||||
|
other.store = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
ConstStorageAccessor& ConstStorageAccessor::operator=(
|
ConstStorageAccessor& ConstStorageAccessor::operator=(
|
||||||
ConstStorageAccessor&& other) {
|
ConstStorageAccessor&& other) {
|
||||||
constDataPointer = other.constDataPointer;
|
constDataPointer = other.constDataPointer;
|
||||||
@ -29,36 +37,6 @@ ConstStorageAccessor& ConstStorageAccessor::operator=(
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageAccessor::StorageAccessor(store_address_t storeId):
|
|
||||||
ConstStorageAccessor(storeId) {
|
|
||||||
}
|
|
||||||
|
|
||||||
StorageAccessor::StorageAccessor(store_address_t storeId,
|
|
||||||
StorageManagerIF* store):
|
|
||||||
ConstStorageAccessor(storeId, store) {
|
|
||||||
}
|
|
||||||
|
|
||||||
StorageAccessor& StorageAccessor::operator =(
|
|
||||||
StorageAccessor&& other) {
|
|
||||||
// Call the parent move assignment and also assign own member.
|
|
||||||
dataPointer = other.dataPointer;
|
|
||||||
StorageAccessor::operator=(std::move(other));
|
|
||||||
return * this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the parent move ctor and also transfer own member.
|
|
||||||
StorageAccessor::StorageAccessor(StorageAccessor&& other):
|
|
||||||
ConstStorageAccessor(std::move(other)), dataPointer(other.dataPointer) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstStorageAccessor::ConstStorageAccessor(ConstStorageAccessor&& other):
|
|
||||||
constDataPointer(other.constDataPointer), storeId(other.storeId),
|
|
||||||
size_(other.size_), store(other.store), deleteData(other.deleteData),
|
|
||||||
internalState(other.internalState) {
|
|
||||||
// This prevent premature deletion
|
|
||||||
other.store = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint8_t* ConstStorageAccessor::data() const {
|
const uint8_t* ConstStorageAccessor::data() const {
|
||||||
return constDataPointer;
|
return constDataPointer;
|
||||||
}
|
}
|
||||||
@ -113,6 +91,41 @@ void ConstStorageAccessor::assignStore(StorageManagerIF* store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StorageAccessor::StorageAccessor(store_address_t storeId):
|
||||||
|
ConstStorageAccessor(storeId) {
|
||||||
|
}
|
||||||
|
|
||||||
|
StorageAccessor::StorageAccessor(store_address_t storeId,
|
||||||
|
StorageManagerIF* store):
|
||||||
|
ConstStorageAccessor(storeId, store) {
|
||||||
|
}
|
||||||
|
|
||||||
|
StorageAccessor& StorageAccessor::operator =(
|
||||||
|
StorageAccessor&& other) {
|
||||||
|
// Call the parent move assignment and also assign own member.
|
||||||
|
dataPointer = other.dataPointer;
|
||||||
|
StorageAccessor::operator=(std::move(other));
|
||||||
|
return * this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the parent move ctor and also transfer own member.
|
||||||
|
StorageAccessor::StorageAccessor(StorageAccessor&& other):
|
||||||
|
ConstStorageAccessor(std::move(other)), dataPointer(other.dataPointer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t StorageAccessor::getDataCopy(uint8_t *pointer, size_t maxSize) {
|
||||||
|
if(internalState == AccessState::UNINIT) {
|
||||||
|
sif::warning << "StorageAccessor: Not initialized!" << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
if(size_ > maxSize) {
|
||||||
|
sif::error << "StorageAccessor: Supplied buffer not large enough" << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
std::copy(dataPointer, dataPointer + size_, pointer);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t* StorageAccessor::data() {
|
uint8_t* StorageAccessor::data() {
|
||||||
if(internalState == AccessState::UNINIT) {
|
if(internalState == AccessState::UNINIT) {
|
||||||
sif::warning << "StorageAccessor: Not initialized!" << std::endl;
|
sif::warning << "StorageAccessor: Not initialized!" << std::endl;
|
||||||
@ -130,7 +143,7 @@ ReturnValue_t StorageAccessor::write(uint8_t *data, size_t size,
|
|||||||
sif::error << "StorageAccessor: Data too large for pool entry!" << std::endl;
|
sif::error << "StorageAccessor: Data too large for pool entry!" << std::endl;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
std::copy(data, data + size, dataPointer);
|
std::copy(data, data + size, dataPointer + offset);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
* @brief Copies the read-only data to the supplied pointer
|
* @brief Copies the read-only data to the supplied pointer
|
||||||
* @param pointer
|
* @param pointer
|
||||||
*/
|
*/
|
||||||
ReturnValue_t getDataCopy(uint8_t *pointer, size_t maxSize);
|
virtual ReturnValue_t getDataCopy(uint8_t *pointer, size_t maxSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calling this will prevent the Accessor from deleting the data
|
* @brief Calling this will prevent the Accessor from deleting the data
|
||||||
@ -137,8 +137,9 @@ public:
|
|||||||
StorageAccessor (StorageAccessor&&);
|
StorageAccessor (StorageAccessor&&);
|
||||||
|
|
||||||
ReturnValue_t write(uint8_t *data, size_t size,
|
ReturnValue_t write(uint8_t *data, size_t size,
|
||||||
uint16_t offset);
|
uint16_t offset = 0);
|
||||||
uint8_t* data();
|
uint8_t* data();
|
||||||
|
ReturnValue_t getDataCopy(uint8_t *pointer, size_t maxSize) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Non-const pointer for modifyable data.
|
//! Non-const pointer for modifyable data.
|
||||||
|
Loading…
Reference in New Issue
Block a user