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(
|
||||
store_address_t storeId) {
|
||||
uint8_t* tempData = nullptr;
|
||||
ConstStorageAccessor constAccessor(storeId);
|
||||
ConstStorageAccessor constAccessor(storeId, this);
|
||||
ReturnValue_t status = modifyData(storeId, &tempData, &constAccessor.size_);
|
||||
constAccessor.constDataPointer = tempData;
|
||||
return ConstAccessorPair(status, std::move(constAccessor));
|
||||
@ -159,6 +159,7 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getData(store_address_t storeId
|
||||
ConstStorageAccessor& storeAccessor) {
|
||||
uint8_t* tempData = nullptr;
|
||||
ReturnValue_t status = modifyData(storeId, &tempData, &storeAccessor.size_);
|
||||
storeAccessor.assignStore(this);
|
||||
storeAccessor.constDataPointer = tempData;
|
||||
return status;
|
||||
}
|
||||
@ -176,7 +177,7 @@ template<uint8_t NUMBER_OF_POOLS>
|
||||
inline AccessorPair LocalPool<NUMBER_OF_POOLS>::modifyData(
|
||||
store_address_t storeId) {
|
||||
uint8_t* tempData = nullptr;
|
||||
StorageAccessor accessor(storeId);
|
||||
StorageAccessor accessor(storeId, this);
|
||||
ReturnValue_t status = modifyData(storeId, &tempData, &accessor.size_);
|
||||
accessor.constDataPointer = tempData;
|
||||
accessor.assignConstPointer();
|
||||
@ -188,6 +189,7 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(
|
||||
store_address_t storeId, StorageAccessor& storeAccessor) {
|
||||
ReturnValue_t status = modifyData(storeId, &storeAccessor.dataPointer,
|
||||
&storeAccessor.size_);
|
||||
storeAccessor.assignStore(this);
|
||||
storeAccessor.assignConstPointer();
|
||||
return status;
|
||||
}
|
||||
|
@ -3,6 +3,12 @@
|
||||
ConstStorageAccessor::ConstStorageAccessor(store_address_t storeId):
|
||||
storeId(storeId) {}
|
||||
|
||||
ConstStorageAccessor::ConstStorageAccessor(store_address_t storeId,
|
||||
StorageManagerIF* store):
|
||||
storeId(storeId), store(store) {
|
||||
internalState = AccessState::ASSIGNED;
|
||||
}
|
||||
|
||||
ConstStorageAccessor::~ConstStorageAccessor() {
|
||||
if(deleteData and store != nullptr) {
|
||||
sif::debug << "deleting store data" << std::endl;
|
||||
@ -27,6 +33,11 @@ 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.
|
||||
@ -97,7 +108,7 @@ void ConstStorageAccessor::print() const {
|
||||
}
|
||||
|
||||
void ConstStorageAccessor::assignStore(StorageManagerIF* store) {
|
||||
internalState = AccessState::READ;
|
||||
internalState = AccessState::ASSIGNED;
|
||||
this->store = store;
|
||||
}
|
||||
|
||||
|
@ -31,23 +31,7 @@ public:
|
||||
* @param storeId
|
||||
*/
|
||||
ConstStorageAccessor(store_address_t storeId);
|
||||
|
||||
/**
|
||||
* @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;
|
||||
ConstStorageAccessor(store_address_t storeId, StorageManagerIF* store);
|
||||
|
||||
/**
|
||||
* @brief The destructor in default configuration takes care of
|
||||
@ -86,6 +70,23 @@ public:
|
||||
store_address_t getId() 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:
|
||||
const uint8_t* constDataPointer = nullptr;
|
||||
store_address_t storeId;
|
||||
@ -96,7 +97,7 @@ protected:
|
||||
|
||||
enum class AccessState {
|
||||
UNINIT,
|
||||
READ
|
||||
ASSIGNED
|
||||
};
|
||||
//! Internal state for safety reasons.
|
||||
AccessState internalState = AccessState::UNINIT;
|
||||
@ -109,7 +110,6 @@ protected:
|
||||
* @param
|
||||
*/
|
||||
void assignStore(StorageManagerIF*);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -124,6 +124,7 @@ class StorageAccessor: public ConstStorageAccessor {
|
||||
friend class LocalPool;
|
||||
public:
|
||||
StorageAccessor(store_address_t storeId);
|
||||
StorageAccessor(store_address_t storeId, StorageManagerIF* store);
|
||||
/**
|
||||
* @brief Move ctor and move assignment allow returning accessors as
|
||||
* a returnvalue. They prevent resource being free prematurely.
|
||||
|
@ -55,6 +55,10 @@ union store_address_t {
|
||||
* Alternative access to the raw value.
|
||||
*/
|
||||
uint32_t raw;
|
||||
|
||||
bool operator==(const store_address_t& other) const {
|
||||
return raw == other.raw;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user