astyle
This commit is contained in:
parent
fd1e397a3e
commit
2997644d22
@ -33,42 +33,77 @@
|
||||
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
|
||||
***/
|
||||
|
||||
struct EERef{
|
||||
struct EERef {
|
||||
|
||||
EERef( const int index )
|
||||
: index( index ) {}
|
||||
EERef(const int index)
|
||||
: index(index) {}
|
||||
|
||||
//Access/read members.
|
||||
uint8_t operator*() const { return eeprom_[index]; }
|
||||
operator uint8_t() const { return **this; }
|
||||
uint8_t operator*() const {
|
||||
return eeprom_[index];
|
||||
}
|
||||
operator uint8_t() const {
|
||||
return **this;
|
||||
}
|
||||
|
||||
//Assignment/write members.
|
||||
EERef &operator=( const EERef &ref ) { return *this = *ref; }
|
||||
EERef &operator=( uint8_t in ) { eeprom_[index] = in; return *this; }
|
||||
EERef &operator +=( uint8_t in ) { return *this = **this + in; }
|
||||
EERef &operator -=( uint8_t in ) { return *this = **this - in; }
|
||||
EERef &operator *=( uint8_t in ) { return *this = **this * in; }
|
||||
EERef &operator /=( uint8_t in ) { return *this = **this / in; }
|
||||
EERef &operator ^=( uint8_t in ) { return *this = **this ^ in; }
|
||||
EERef &operator %=( uint8_t in ) { return *this = **this % in; }
|
||||
EERef &operator &=( uint8_t in ) { return *this = **this & in; }
|
||||
EERef &operator |=( uint8_t in ) { return *this = **this | in; }
|
||||
EERef &operator <<=( uint8_t in ) { return *this = **this << in; }
|
||||
EERef &operator >>=( uint8_t in ) { return *this = **this >> in; }
|
||||
EERef &operator=(const EERef &ref) {
|
||||
return *this = *ref;
|
||||
}
|
||||
EERef &operator=(uint8_t in) {
|
||||
eeprom_[index] = in;
|
||||
return *this;
|
||||
}
|
||||
EERef &operator +=(uint8_t in) {
|
||||
return *this = **this + in;
|
||||
}
|
||||
EERef &operator -=(uint8_t in) {
|
||||
return *this = **this - in;
|
||||
}
|
||||
EERef &operator *=(uint8_t in) {
|
||||
return *this = **this * in;
|
||||
}
|
||||
EERef &operator /=(uint8_t in) {
|
||||
return *this = **this / in;
|
||||
}
|
||||
EERef &operator ^=(uint8_t in) {
|
||||
return *this = **this ^ in;
|
||||
}
|
||||
EERef &operator %=(uint8_t in) {
|
||||
return *this = **this % in;
|
||||
}
|
||||
EERef &operator &=(uint8_t in) {
|
||||
return *this = **this & in;
|
||||
}
|
||||
EERef &operator |=(uint8_t in) {
|
||||
return *this = **this | in;
|
||||
}
|
||||
EERef &operator <<=(uint8_t in) {
|
||||
return *this = **this << in;
|
||||
}
|
||||
EERef &operator >>=(uint8_t in) {
|
||||
return *this = **this >> in;
|
||||
}
|
||||
|
||||
EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; }
|
||||
EERef &update(uint8_t in) {
|
||||
return in != *this ? *this = in : *this;
|
||||
}
|
||||
|
||||
/** Prefix increment/decrement **/
|
||||
EERef& operator++() { return *this += 1; }
|
||||
EERef& operator--() { return *this -= 1; }
|
||||
EERef& operator++() {
|
||||
return *this += 1;
|
||||
}
|
||||
EERef& operator--() {
|
||||
return *this -= 1;
|
||||
}
|
||||
|
||||
/** Postfix increment/decrement **/
|
||||
uint8_t operator++ (int){
|
||||
uint8_t operator++ (int) {
|
||||
uint8_t ret = **this;
|
||||
return ++(*this), ret;
|
||||
}
|
||||
|
||||
uint8_t operator-- (int){
|
||||
uint8_t operator-- (int) {
|
||||
uint8_t ret = **this;
|
||||
return --(*this), ret;
|
||||
}
|
||||
@ -131,31 +166,43 @@ struct EEPtr {
|
||||
This class is also 100% backwards compatible with earlier Arduino core releases.
|
||||
***/
|
||||
|
||||
struct EEPROMClass{
|
||||
struct EEPROMClass {
|
||||
|
||||
//Basic user access methods.
|
||||
EERef operator[]( const int idx ) { return idx; }
|
||||
uint8_t read( int idx ) { return EERef( idx ); }
|
||||
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
|
||||
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }
|
||||
EERef operator[](const int idx) {
|
||||
return idx;
|
||||
}
|
||||
uint8_t read(int idx) {
|
||||
return EERef(idx);
|
||||
}
|
||||
void write(int idx, uint8_t val) {
|
||||
(EERef(idx)) = val;
|
||||
}
|
||||
void update(int idx, uint8_t val) {
|
||||
EERef(idx).update(val);
|
||||
}
|
||||
|
||||
//STL and C++11 iteration capability.
|
||||
EEPtr begin() { return 0x00; }
|
||||
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
|
||||
EEPtr begin() {
|
||||
return 0x00;
|
||||
}
|
||||
EEPtr end() {
|
||||
return length(); //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
|
||||
}
|
||||
uint16_t length();
|
||||
|
||||
//Functionality to 'get' and 'put' objects to and from EEPROM.
|
||||
template< typename T > T &get( int idx, T &t ){
|
||||
template< typename T > T &get(int idx, T &t) {
|
||||
EEPtr e = idx;
|
||||
uint8_t *ptr = (uint8_t*) &t;
|
||||
for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
|
||||
for (int count = sizeof(T) ; count ; --count, ++e) *ptr++ = *e;
|
||||
return t;
|
||||
}
|
||||
|
||||
template< typename T > const T &put( int idx, const T &t ){
|
||||
template< typename T > const T &put(int idx, const T &t) {
|
||||
EEPtr e = idx;
|
||||
const uint8_t *ptr = (const uint8_t*) &t;
|
||||
for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
|
||||
for (int count = sizeof(T) ; count ; --count, ++e)(*e).update(*ptr++);
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user