fsfw/src/fsfw/storagemanager/StorageAccessor.h

45 lines
1.5 KiB
C
Raw Normal View History

2020-09-29 14:42:48 +02:00
#ifndef FSFW_STORAGEMANAGER_STORAGEACCESSOR_H_
#define FSFW_STORAGEMANAGER_STORAGEACCESSOR_H_
2020-09-29 14:35:05 +02:00
2020-09-29 14:42:48 +02:00
#include "ConstStorageAccessor.h"
2020-09-29 14:35:05 +02:00
class StorageManagerIF;
/**
* @brief Child class for modifyable data. Also has a normal pointer member.
*/
2022-02-02 10:29:30 +01:00
class StorageAccessor : public ConstStorageAccessor {
//! StorageManager classes have exclusive access to private variables.
friend class PoolManager;
friend class LocalPool;
2022-09-15 10:30:22 +02:00
friend class StorageManagerIF;
2022-02-02 10:29:30 +01:00
public:
2022-09-15 10:30:22 +02:00
explicit StorageAccessor(store_address_t storeId);
2022-02-02 10:29:30 +01:00
StorageAccessor(store_address_t storeId, StorageManagerIF* store);
/**
* @brief Move ctor and move assignment allow returning accessors as
* a returnvalue. They prevent resource being freed prematurely.
* See: https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/cpp/
* move-constructors-and-move-assignment-operators-cpp.md
* @param
* @return
*/
2022-09-15 10:30:22 +02:00
StorageAccessor& operator=(StorageAccessor&&) noexcept;
StorageAccessor(StorageAccessor&&) noexcept;
2022-02-02 10:29:30 +01:00
ReturnValue_t write(uint8_t* data, size_t size, uint16_t offset = 0);
uint8_t* data();
ReturnValue_t getDataCopy(uint8_t* pointer, size_t maxSize) override;
private:
//! Non-const pointer for modifyable data.
uint8_t* dataPointer = nullptr;
//! For modifyable data, the const pointer is assigned to the normal
//! pointer by the pool manager so both access functions can be used safely
void assignConstPointer();
2020-09-29 14:35:05 +02:00
};
2020-09-29 14:42:48 +02:00
#endif /* FSFW_STORAGEMANAGER_STORAGEACCESSOR_H_ */