Skip to content

Commit acbd8bc

Browse files
committed
Updated proxy system. Now it is not restricted on types of input.
1 parent d3bd5f2 commit acbd8bc

File tree

1 file changed

+25
-24
lines changed
  • hardware/arduino/avr/libraries/EEPROM/src

1 file changed

+25
-24
lines changed

hardware/arduino/avr/libraries/EEPROM/src/EEPROM.h

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535

3636
struct EERef{
3737

38-
EERef( const int index )
39-
: index( index ) {}
38+
template< typename T > EERef( T *ptr ) : index( (int) ptr ) {}
39+
EERef( const int index ) : index( index ) {}
4040

4141
//Access/read members.
4242
uint8_t operator*() const { return eeprom_read_byte( (uint8_t*) index ); }
43-
operator const uint8_t() const { return **this; }
43+
operator uint8_t() const { return **this; }
4444

4545
//Assignment/write members.
4646
EERef &operator=( const EERef &ref ) { return *this = *ref; }
@@ -86,15 +86,18 @@ struct EERef{
8686

8787
struct EEPtr{
8888

89-
EEPtr( const int index )
90-
: index( index ) {}
89+
template< typename T > EEPtr( T *ptr ) : index( (int) ptr ) {}
90+
EEPtr( const int index ) : index( index ) {}
9191

92-
operator const int() const { return index; }
92+
operator int() const { return index; }
9393
EEPtr &operator=( int in ) { return index = in, *this; }
94+
EERef operator[]( int idx ) { return index + idx; }
9495

9596
//Iterator functionality.
9697
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
97-
EERef operator*() { return index; }
98+
99+
//Dreference & member access.
100+
EERef operator*() { return index; }
98101

99102
/** Prefix & Postfix increment/decrement **/
100103
EEPtr& operator++() { return ++index, *this; }
@@ -115,31 +118,29 @@ struct EEPtr{
115118

116119
struct EEPROMClass{
117120

118-
//Basic user access methods.
119-
EERef operator[]( const int idx ) { return idx; }
120-
uint8_t read( int idx ) { return EERef( idx ); }
121-
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
122-
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }
121+
//Basic user access methods.
122+
EERef operator[]( EERef ref ) { return ref; }
123+
EERef read( EERef ref ) { return ref; }
124+
void write( EERef ref, uint8_t val ) { ref = val; }
125+
void update( EERef ref, uint8_t val ) { ref.update( val ); }
123126

124127
//STL and C++11 iteration capability.
125128
EEPtr begin() { return 0x00; }
126129
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
127130
uint16_t length() { return E2END + 1; }
128131

129132
//Functionality to 'get' and 'put' objects to and from EEPROM.
130-
template< typename T > T &get( int idx, T &t ){
131-
EEPtr e = idx;
132-
uint8_t *ptr = (uint8_t*) &t;
133-
for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
134-
return t;
135-
}
133+
template< typename T > T &get( EEPtr ptr, T &t ){
134+
uint8_t *dest = (uint8_t*) &t;
135+
for( int count = sizeof(T) ; count ; --count, ++ptr ) *dest++ = *ptr;
136+
return t;
137+
}
136138

137-
template< typename T > const T &put( int idx, const T &t ){
138-
EEPtr e = idx;
139-
const uint8_t *ptr = (const uint8_t*) &t;
140-
for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
141-
return t;
142-
}
139+
template< typename T > const T &put( EEPtr ptr, const T &t ){
140+
const uint8_t *src = (const uint8_t*) &t;
141+
for( int count = sizeof(T) ; count ; --count, ++ptr ) (*ptr).update( *src++ );
142+
return t;
143+
}
143144
};
144145

145146
static EEPROMClass EEPROM;

0 commit comments

Comments
 (0)