25
25
#include < avr/eeprom.h>
26
26
#include < avr/io.h>
27
27
28
+ struct EEPtr ; // Forward declaration for EERef::opreator&
29
+
28
30
/* **
29
31
EERef class.
30
32
@@ -41,6 +43,8 @@ struct EERef{
41
43
// Access/read members.
42
44
uint8_t operator *() const { return eeprom_read_byte ( (uint8_t *) index ); }
43
45
operator uint8_t () const { return **this ; }
46
+
47
+ EEPtr operator &() const ; // Defined below EEPtr
44
48
45
49
// Assignment/write members.
46
50
EERef &operator =( const EERef &ref ) { return *this = *ref; }
@@ -88,18 +92,22 @@ struct EEPtr{
88
92
89
93
template < typename T > EEPtr ( T *ptr ) : index( (int ) ptr ) {}
90
94
EEPtr ( const int index ) : index( index ) {}
91
-
95
+
96
+ // Pointer read/write.
92
97
operator int () const { return index ; }
93
98
EEPtr &operator =( int in ) { return index = in, *this ; }
94
99
EERef operator []( int idx ) { return index + idx; }
95
100
96
101
// Iterator functionality.
97
102
bool operator !=( const EEPtr &ptr ) { return index != ptr.index ; }
103
+ EEPtr& operator +=( int idx ) { return index += idx, *this ; }
104
+ EEPtr& operator -=( int idx ) { return index -= idx, *this ; }
98
105
99
106
// Dreference & member access.
100
107
EERef operator *() { return index ; }
101
-
102
- /* * Prefix & Postfix increment/decrement **/
108
+ EERef *operator ->() { return (EERef*) this ; }
109
+
110
+ // Prefix & Postfix increment/decrement
103
111
EEPtr& operator ++() { return ++index , *this ; }
104
112
EEPtr& operator --() { return --index , *this ; }
105
113
EEPtr operator ++ (int ) { return index ++; }
@@ -108,6 +116,8 @@ struct EEPtr{
108
116
int index; // Index of current EEPROM cell.
109
117
};
110
118
119
+ inline EEPtr EERef::operator &() const { return index ; } // Deferred definition till EEPtr becomes available.
120
+
111
121
/* **
112
122
EEPROMClass class.
113
123
0 commit comments