Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <EEPROM.h>
- template<typename Type>
- struct IProperty {
- virtual ~IProperty() noexcept = default;
- virtual void setValue(const Type&) = 0;
- virtual const Type& value() const = 0;
- };
- template<typename Type>
- class AbstractEepromProperty: public IProperty<Type> {
- protected:
- EEPROMClass& m_eeprom;
- const int m_address{};
- Type m_value{};
- public:
- AbstractEepromProperty(EEPROMClass& eeprom, int address)
- :m_eeprom{ eeprom }, m_address{ address } {}
- public:
- virtual void read_from_eeprom() = 0;
- virtual void write_to_eeprom() = 0;
- public:
- virtual const Type& value() const override final {
- return m_value;
- }
- };
- template<size_t length>
- class ByteArrayEepromProperty: public AbstractEepromProperty<uint8_t[length]> {
- public:
- ByteArrayEepromProperty(EEPROMClass& eeprom, int address)
- :AbstractEepromProperty<uint8_t[length]>{ eeprom, address } {}
- public:
- virtual void setValue(const uint8_t(&value)[length]) override {
- memcpy(this->m_value, value, length);
- }
- virtual void read_from_eeprom() override final {
- this->m_eeprom.readBytes(this->m_address, this->m_value, length);
- }
- virtual void write_to_eeprom() override final {
- this->m_eeprom.writeBytes(this->m_address, this->m_value, length);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement