new ctor and bugfixes
This commit is contained in:
parent
d873fcbf8e
commit
291710f257
@ -148,7 +148,7 @@ template<uint8_t NUMBER_OF_POOLS>
|
|||||||
inline ConstAccessorPair LocalPool<NUMBER_OF_POOLS>::getData(
|
inline ConstAccessorPair LocalPool<NUMBER_OF_POOLS>::getData(
|
||||||
store_address_t storeId) {
|
store_address_t storeId) {
|
||||||
uint8_t* tempData = nullptr;
|
uint8_t* tempData = nullptr;
|
||||||
ConstStorageAccessor constAccessor(storeId);
|
ConstStorageAccessor constAccessor(storeId, this);
|
||||||
ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_);
|
ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_);
|
||||||
constAccessor.constDataPointer = tempData;
|
constAccessor.constDataPointer = tempData;
|
||||||
return ConstAccessorPair(status, std::move(constAccessor));
|
return ConstAccessorPair(status, std::move(constAccessor));
|
||||||
@ -159,6 +159,7 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(store_address_t storeId
|
|||||||
ConstStorageAccessor& storeAccessor) {
|
ConstStorageAccessor& storeAccessor) {
|
||||||
uint8_t* tempData = nullptr;
|
uint8_t* tempData = nullptr;
|
||||||
ReturnValue_t status = modifyData(storeId, &tempData, &storeAccessor.size_);
|
ReturnValue_t status = modifyData(storeId, &tempData, &storeAccessor.size_);
|
||||||
|
storeAccessor.assignStore(this);
|
||||||
storeAccessor.constDataPointer = tempData;
|
storeAccessor.constDataPointer = tempData;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -176,7 +177,7 @@ 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;
|
uint8_t* tempData = nullptr;
|
||||||
StorageAccessor accessor(storeId);
|
StorageAccessor accessor(storeId, this);
|
||||||
ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_);
|
ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_);
|
||||||
accessor.constDataPointer = tempData;
|
accessor.constDataPointer = tempData;
|
||||||
accessor.assignConstPointer();
|
accessor.assignConstPointer();
|
||||||
@ -188,6 +189,7 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
|
|||||||
store_address_t storeId, StorageAccessor& storeAccessor) {
|
store_address_t storeId, StorageAccessor& storeAccessor) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,12 @@
|
|||||||
ConstStorageAccessor::ConstStorageAccessor(store_address_t storeId):
|
ConstStorageAccessor::ConstStorageAccessor(store_address_t storeId):
|
||||||
storeId(storeId) {}
|
storeId(storeId) {}
|
||||||
|
|
||||||
|
ConstStorageAccessor::ConstStorageAccessor(store_address_t storeId,
|
||||||
|
StorageManagerIF* store):
|
||||||
|
storeId(storeId), store(store) {
|
||||||
|
internalState = AccessState::ASSIGNED;
|
||||||
|
}
|
||||||
|
|
||||||
ConstStorageAccessor::~ConstStorageAccessor() {
|
ConstStorageAccessor::~ConstStorageAccessor() {
|
||||||
if(deleteData and store != nullptr) {
|
if(deleteData and store != nullptr) {
|
||||||
sif::debug << "deleting store data" << std::endl;
|
sif::debug << "deleting store data" << std::endl;
|
||||||
@ -27,6 +33,11 @@ StorageAccessor::StorageAccessor(store_address_t storeId):
|
|||||||
ConstStorageAccessor(storeId) {
|
ConstStorageAccessor(storeId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StorageAccessor::StorageAccessor(store_address_t storeId,
|
||||||
|
StorageManagerIF* store):
|
||||||
|
ConstStorageAccessor(storeId, store) {
|
||||||
|
}
|
||||||
|
|
||||||
StorageAccessor& StorageAccessor::operator =(
|
StorageAccessor& StorageAccessor::operator =(
|
||||||
StorageAccessor&& other) {
|
StorageAccessor&& other) {
|
||||||
// Call the parent move assignment and also assign own member.
|
// Call the parent move assignment and also assign own member.
|
||||||
@ -97,7 +108,7 @@ void ConstStorageAccessor::print() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConstStorageAccessor::assignStore(StorageManagerIF* store) {
|
void ConstStorageAccessor::assignStore(StorageManagerIF* store) {
|
||||||
internalState = AccessState::READ;
|
internalState = AccessState::ASSIGNED;
|
||||||
this->store = store;
|
this->store = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,23 +31,7 @@ public:
|
|||||||
* @param storeId
|
* @param storeId
|
||||||
*/
|
*/
|
||||||
ConstStorageAccessor(store_address_t storeId);
|
ConstStorageAccessor(store_address_t storeId);
|
||||||
|
ConstStorageAccessor(store_address_t storeId, StorageManagerIF* store);
|
||||||
/**
|
|
||||||
* @brief Move ctor and move assignment allow returning accessors as
|
|
||||||
* a returnvalue. They prevent resource being free prematurely.
|
|
||||||
* Refer to: https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/cpp/
|
|
||||||
* move-constructors-and-move-assignment-operators-cpp.md
|
|
||||||
* @param
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
ConstStorageAccessor& operator= (ConstStorageAccessor&&);
|
|
||||||
ConstStorageAccessor (ConstStorageAccessor&&);
|
|
||||||
|
|
||||||
//! The copy ctor and copy assignemnt should be deleted implicitely
|
|
||||||
//! according to https://foonathan.net/2019/02/special-member-functions/
|
|
||||||
//! but I still deleted them to make it more explicit. (remember rule of 5).
|
|
||||||
ConstStorageAccessor& operator= (ConstStorageAccessor&) = delete;
|
|
||||||
ConstStorageAccessor (ConstStorageAccessor&) = delete;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The destructor in default configuration takes care of
|
* @brief The destructor in default configuration takes care of
|
||||||
@ -86,6 +70,23 @@ public:
|
|||||||
store_address_t getId() const;
|
store_address_t getId() const;
|
||||||
|
|
||||||
void print() const;
|
void print() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Move ctor and move assignment allow returning accessors as
|
||||||
|
* a returnvalue. They prevent resource being free prematurely.
|
||||||
|
* Refer to: https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/cpp/
|
||||||
|
* move-constructors-and-move-assignment-operators-cpp.md
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ConstStorageAccessor& operator= (ConstStorageAccessor&&);
|
||||||
|
ConstStorageAccessor (ConstStorageAccessor&&);
|
||||||
|
|
||||||
|
//! The copy ctor and copy assignemnt should be deleted implicitely
|
||||||
|
//! according to https://foonathan.net/2019/02/special-member-functions/
|
||||||
|
//! but I still deleted them to make it more explicit. (remember rule of 5).
|
||||||
|
ConstStorageAccessor& operator= (ConstStorageAccessor&) = delete;
|
||||||
|
ConstStorageAccessor (ConstStorageAccessor&) = delete;
|
||||||
protected:
|
protected:
|
||||||
const uint8_t* constDataPointer = nullptr;
|
const uint8_t* constDataPointer = nullptr;
|
||||||
store_address_t storeId;
|
store_address_t storeId;
|
||||||
@ -96,7 +97,7 @@ protected:
|
|||||||
|
|
||||||
enum class AccessState {
|
enum class AccessState {
|
||||||
UNINIT,
|
UNINIT,
|
||||||
READ
|
ASSIGNED
|
||||||
};
|
};
|
||||||
//! Internal state for safety reasons.
|
//! Internal state for safety reasons.
|
||||||
AccessState internalState = AccessState::UNINIT;
|
AccessState internalState = AccessState::UNINIT;
|
||||||
@ -109,7 +110,6 @@ protected:
|
|||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
void assignStore(StorageManagerIF*);
|
void assignStore(StorageManagerIF*);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -124,6 +124,7 @@ class StorageAccessor: public ConstStorageAccessor {
|
|||||||
friend class LocalPool;
|
friend class LocalPool;
|
||||||
public:
|
public:
|
||||||
StorageAccessor(store_address_t storeId);
|
StorageAccessor(store_address_t storeId);
|
||||||
|
StorageAccessor(store_address_t storeId, StorageManagerIF* store);
|
||||||
/**
|
/**
|
||||||
* @brief Move ctor and move assignment allow returning accessors as
|
* @brief Move ctor and move assignment allow returning accessors as
|
||||||
* a returnvalue. They prevent resource being free prematurely.
|
* a returnvalue. They prevent resource being free prematurely.
|
||||||
|
@ -55,6 +55,10 @@ union store_address_t {
|
|||||||
* Alternative access to the raw value.
|
* Alternative access to the raw value.
|
||||||
*/
|
*/
|
||||||
uint32_t raw;
|
uint32_t raw;
|
||||||
|
|
||||||
|
bool operator==(const store_address_t& other) const {
|
||||||
|
return raw == other.raw;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user