mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Added length and operator[] methods, added some constness, missed dirty clear (#3855)
* Added length and operator[] methods, added some constness, missed _dirty clear * Added forgotten const
This commit is contained in:
@ -32,16 +32,16 @@ public:
|
||||
EEPROMClass(void);
|
||||
|
||||
void begin(size_t size);
|
||||
uint8_t read(int address);
|
||||
void write(int address, uint8_t val);
|
||||
uint8_t read(int const address);
|
||||
void write(int const address, uint8_t const val);
|
||||
bool commit();
|
||||
void end();
|
||||
|
||||
uint8_t * getDataPtr();
|
||||
uint8_t const * getConstDataPtr();
|
||||
uint8_t const * getConstDataPtr() const;
|
||||
|
||||
template<typename T>
|
||||
T &get(int address, T &t) {
|
||||
T &get(int const address, T &t) {
|
||||
if (address < 0 || address + sizeof(T) > _size)
|
||||
return t;
|
||||
|
||||
@ -50,17 +50,22 @@ public:
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T &put(int address, const T &t) {
|
||||
const T &put(int const address, const T &t) {
|
||||
if (address < 0 || address + sizeof(T) > _size)
|
||||
return t;
|
||||
if (memcmp(_data + address, (const uint8_t*)&t, sizeof(T)) != 0) {
|
||||
_dirty = true;
|
||||
memcpy(_data + address, (const uint8_t*)&t, sizeof(T));
|
||||
_dirty = true;
|
||||
memcpy(_data + address, (const uint8_t*)&t, sizeof(T));
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
size_t length() {return _size;}
|
||||
|
||||
uint8_t& operator[](int const address) {return getDataPtr()[address];}
|
||||
uint8_t const & operator[](int const address) const {return getConstDataPtr()[address];}
|
||||
|
||||
protected:
|
||||
uint32_t _sector;
|
||||
uint8_t* _data;
|
||||
|
Reference in New Issue
Block a user