EEPROM-Storage Library
The EEPROM Storage library provides the ability to access variables stored in EEPROM just as if they were stored in RAM.
 
Loading...
Searching...
No Matches
EEPROMBase< T > Class Template Reference

Base class to wrap an EEPROM variable. More...

#include <EEPROM-Base.h>

Inheritance diagram for EEPROMBase< T >:
EEPROMCache< T > EEPROMStorage< T >

Public Member Functions

 EEPROMBase (const uint address)
 Initialize an instance of EEPROMBase<T> with the specified address.
 
 EEPROMBase (const uint address, T defaultValue)
 Initialize an instance of EEPROMBase with the specified address and default value.
 
 operator T ()
 Implicitly converts the class instance to the value of type T. This allows the variable to be used on the right side of the equal sign.
 
byte operator[] (const uint index)
 Treating the variable as a byte array, get the byte at position index where index is between 0 and length.
 
operator++ (int)
 Postfix increment operator.
 
operator++ ()
 Prefix increment operator.
 
operator-- (int)
 Postfix decrement operator.
 
operator-- ()
 Postfix decrement operator.
 
operator+= (T const &value)
 Addition assignment operator.
 
operator-= (T const &value)
 Subtraction assignment operator.
 
operator*= (T const &value)
 Multiplication assignment operator.
 
operator/= (T const &value)
 Division assignment operator.
 
operator^= (T const &value)
 Bitwise XOR assignment operator.
 
operator%= (T const &value)
 Modulus assignment operator.
 
operator&= (T const &value)
 Bitwise AND assignment operator.
 
operator|= (T const &value)
 Bitwise OR assignment operator.
 
operator<<= (T const &value)
 Bitwise left shift assignment operator.
 
operator>>= (T const &value)
 Bitwise right shift assignment operator.
 
virtual T get () const
 Get the variable value.
 
virtual T set (T const &value)
 Set the variable value.
 
read () const
 Read the variable value from the EEPROM using the address in this variable.
 
void write (T const &value) const
 Write the value to the EEPROM using the address in this instance.
 
bool isInitialized () const
 Checks whether the EEPROM variable has been initialized.
 
uint length () const
 Returns the number of EEPROM bytes used.
 
uint size () const
 Returns the number of EEPROM bytes used by T.
 
void unset (byte unsetValue=UNSET_VALUE)
 Unset the variable.
 
uint checksumAddress () const
 Gets the address of the checksum byte in EEPROM for this variable.
 
byte checksumByte () const
 Gets the stored checksum byte.
 
byte checksum () const
 Calculate the checksum of the data in the EEPROM for this instance.
 
void copyTo (byte *data, uint length) const
 Copy the EEPROM bytes of this instance to a byte array.
 
uint getAddress () const
 Get the EEPROM address of the variable.
 
uint nextAddress () const
 Gets the next EEPROM address after this variable.
 
getDefaultValue () const
 Gets the default value for this instance.
 

Protected Member Functions

byte computeChecksum (T value)
 Computes the checksum of the given value.
 
uint normalizeAddress (uint address) const
 Normalize the given EEPROM address to ensure it is within valid range.
 

Protected Attributes

uint _address = 0
 The address of this variable in the EEPROM.
 
_defaultValue
 The default value.
 

Detailed Description

template<typename T>
class EEPROMBase< T >

Base class to wrap an EEPROM variable.

This class contains the methods and properties to allow reading and writing EEPROM, storing the location of the variable (address), calculating, storing and comparing the variable checksum, computing the next address for subsequent EEPROM variables, standard operator functionality, and implicit conversion to the value type from the class instance.

Template Parameters
TThe type of the variable stored.

Definition at line 53 of file EEPROM-Base.h.

Constructor & Destructor Documentation

◆ EEPROMBase() [1/2]

template<typename T >
EEPROMBase< T >::EEPROMBase ( const uint  address)
inline

Initialize an instance of EEPROMBase<T> with the specified address.

Parameters
addressThe address (or index) of the variable within EEPROM.

Definition at line 60 of file EEPROM-Base.h.

◆ EEPROMBase() [2/2]

template<typename T >
EEPROMBase< T >::EEPROMBase ( const uint  address,
defaultValue 
)
inline

Initialize an instance of EEPROMBase with the specified address and default value.

Parameters
addressThe address (or index) of the variable within EEPROM.
Template Parameters
defaultValueThe default value returned when the variable has not been initialized.

Definition at line 70 of file EEPROM-Base.h.

Member Function Documentation

◆ checksum()

template<typename T >
byte EEPROMBase< T >::checksum ( ) const
inline

Calculate the checksum of the data in the EEPROM for this instance.

Returns
The calculated checksum as a byte.

Definition at line 386 of file EEPROM-Base.h.

◆ checksumAddress()

template<typename T >
uint EEPROMBase< T >::checksumAddress ( ) const
inline

Gets the address of the checksum byte in EEPROM for this variable.

Returns
The EEPROM address of the checksum as an unsigned integer.

Definition at line 368 of file EEPROM-Base.h.

◆ checksumByte()

template<typename T >
byte EEPROMBase< T >::checksumByte ( ) const
inline

Gets the stored checksum byte.

Returns
The checksum value read from EEPROM for this variable as a byte.

Definition at line 377 of file EEPROM-Base.h.

◆ computeChecksum()

template<typename T >
byte EEPROMBase< T >::computeChecksum ( value)
protected

Computes the checksum of the given value.

Template Parameters
valueThe value to compute the checksum for.
Returns
The computed checksum as a byte.

◆ copyTo()

template<typename T >
void EEPROMBase< T >::copyTo ( byte *  data,
uint  length 
) const
inline

Copy the EEPROM bytes of this instance to a byte array.

Definition at line 394 of file EEPROM-Base.h.

◆ get()

template<typename T >
virtual T EEPROMBase< T >::get ( ) const
inlinevirtual

Get the variable value.

Returns
The current value of the variable as type T.

Reimplemented in EEPROMCache< T >, and EEPROMStorage< T >.

Definition at line 242 of file EEPROM-Base.h.

◆ getAddress()

template<typename T >
uint EEPROMBase< T >::getAddress ( ) const
inline

Get the EEPROM address of the variable.

Returns
The memory address in EEPROM as an unsigned integer.

Definition at line 407 of file EEPROM-Base.h.

◆ getDefaultValue()

template<typename T >
T EEPROMBase< T >::getDefaultValue ( ) const
inline

Gets the default value for this instance.

Returns
The default value as type T.

Definition at line 426 of file EEPROM-Base.h.

◆ isInitialized()

template<typename T >
bool EEPROMBase< T >::isInitialized ( ) const
inline

Checks whether the EEPROM variable has been initialized.

Determines if the variable has been initialized by comparing the stored checksum to the actual checksum of the bytes stored.

Returns
True if the EEPROM variable has been initialized, false otherwise.

Definition at line 318 of file EEPROM-Base.h.

◆ length()

template<typename T >
uint EEPROMBase< T >::length ( ) const
inline

Returns the number of EEPROM bytes used.

Returns the number of EEPROM bytes used by this instance including the checksum byte.

Returns
The number of bytes used in the EEPROM as an unsigned integer .

Definition at line 328 of file EEPROM-Base.h.

◆ nextAddress()

template<typename T >
uint EEPROMBase< T >::nextAddress ( ) const
inline

Gets the next EEPROM address after this variable.

This can be used to set the address of another EEPROM variable.

Returns
The next address in EEPROM as an unsigned integer.

Definition at line 417 of file EEPROM-Base.h.

◆ normalizeAddress()

template<typename T >
uint EEPROMBase< T >::normalizeAddress ( uint  address) const
inlineprotected

Normalize the given EEPROM address to ensure it is within valid range.

Parameters
addressThe address to normalize.
Returns
The normalized address as an unsigned integer.

Definition at line 458 of file EEPROM-Base.h.

◆ operator T()

template<typename T >
EEPROMBase< T >::operator T ( )
inline

Implicitly converts the class instance to the value of type T. This allows the variable to be used on the right side of the equal sign.

Returns
The current value of the variable as type T.

Definition at line 80 of file EEPROM-Base.h.

◆ operator%=()

template<typename T >
T EEPROMBase< T >::operator%= ( T const &  value)
inline

Modulus assignment operator.

Template Parameters
valueThe value to mod with.
Returns
The result of the modulus operation as type T.

Definition at line 193 of file EEPROM-Base.h.

◆ operator&=()

template<typename T >
T EEPROMBase< T >::operator&= ( T const &  value)
inline

Bitwise AND assignment operator.

Template Parameters
valueThe value to AND with.
Returns
The result of the AND operation as type T.

Definition at line 203 of file EEPROM-Base.h.

◆ operator*=()

template<typename T >
T EEPROMBase< T >::operator*= ( T const &  value)
inline

Multiplication assignment operator.

Template Parameters
valueThe value to multiply by.
Returns
The result of the multiplication as type T.

Definition at line 163 of file EEPROM-Base.h.

◆ operator++() [1/2]

template<typename T >
T EEPROMBase< T >::operator++ ( )
inline

Prefix increment operator.

Returns
The value after incrementing as type T.

Definition at line 113 of file EEPROM-Base.h.

◆ operator++() [2/2]

template<typename T >
T EEPROMBase< T >::operator++ ( int  )
inline

Postfix increment operator.

Returns
The value before incrementing as type T.

Definition at line 102 of file EEPROM-Base.h.

◆ operator+=()

template<typename T >
T EEPROMBase< T >::operator+= ( T const &  value)
inline

Addition assignment operator.

Parameters
valueThe value to add.
Returns
The result of the addition as type T.

Definition at line 143 of file EEPROM-Base.h.

◆ operator--() [1/2]

template<typename T >
T EEPROMBase< T >::operator-- ( )
inline

Postfix decrement operator.

Returns
The value before decrementing as type T.

Definition at line 133 of file EEPROM-Base.h.

◆ operator--() [2/2]

template<typename T >
T EEPROMBase< T >::operator-- ( int  )
inline

Postfix decrement operator.

Returns
The value before decrementing as type T.

Definition at line 122 of file EEPROM-Base.h.

◆ operator-=()

template<typename T >
T EEPROMBase< T >::operator-= ( T const &  value)
inline

Subtraction assignment operator.

Parameters
valueThe value to subtract.
Returns
The result of the subtraction as type T.

Definition at line 153 of file EEPROM-Base.h.

◆ operator/=()

template<typename T >
T EEPROMBase< T >::operator/= ( T const &  value)
inline

Division assignment operator.

Template Parameters
valueThe value to divide by.
Returns
The result of the division as type T.

Definition at line 173 of file EEPROM-Base.h.

◆ operator<<=()

template<typename T >
T EEPROMBase< T >::operator<<= ( T const &  value)
inline

Bitwise left shift assignment operator.

Template Parameters
valueThe value to shift by.
Returns
The result of the left shift operation as type T.

Definition at line 223 of file EEPROM-Base.h.

◆ operator>>=()

template<typename T >
T EEPROMBase< T >::operator>>= ( T const &  value)
inline

Bitwise right shift assignment operator.

Template Parameters
valueThe value to shift by.
Returns
The result of the right shift operation as type T.

Definition at line 233 of file EEPROM-Base.h.

◆ operator[]()

template<typename T >
byte EEPROMBase< T >::operator[] ( const uint  index)
inline

Treating the variable as a byte array, get the byte at position index where index is between 0 and length.

Parameters
indexThe index position.
Returns
The byte at the specified index as a byte.

Definition at line 92 of file EEPROM-Base.h.

◆ operator^=()

template<typename T >
T EEPROMBase< T >::operator^= ( T const &  value)
inline

Bitwise XOR assignment operator.

Template Parameters
valueThe value to XOR with.
Returns
The result of the XOR operation as type T.

Definition at line 183 of file EEPROM-Base.h.

◆ operator|=()

template<typename T >
T EEPROMBase< T >::operator|= ( T const &  value)
inline

Bitwise OR assignment operator.

Template Parameters
valueThe value to OR with.
Returns
The result of the OR operation as type T.

Definition at line 213 of file EEPROM-Base.h.

◆ read()

template<typename T >
T EEPROMBase< T >::read ( ) const
inline

Read the variable value from the EEPROM using the address in this variable.

Returns
The value read from EEPROM as type T.

Definition at line 264 of file EEPROM-Base.h.

◆ set()

template<typename T >
virtual T EEPROMBase< T >::set ( T const &  value)
inlinevirtual

Set the variable value.

Template Parameters
valueThe new value to store in EEPROM.
Returns
The stored value as type T.

Reimplemented in EEPROMCache< T >, and EEPROMStorage< T >.

Definition at line 255 of file EEPROM-Base.h.

◆ size()

template<typename T >
uint EEPROMBase< T >::size ( ) const
inline

Returns the number of EEPROM bytes used by T.

Returns the number of EEPROM bytes used by this instance NOT including the checksum byte.

Returns
The number of bytes used by T in the EEPROM as n unsigned integer.

Definition at line 342 of file EEPROM-Base.h.

◆ unset()

template<typename T >
void EEPROMBase< T >::unset ( byte  unsetValue = UNSET_VALUE)
inline

Unset the variable.

Change the EEPROM values back to UNSET_VALUE as if the variable has never been written to the EEPROM. The isInitialized() method will return false.

Definition at line 355 of file EEPROM-Base.h.

◆ write()

template<typename T >
void EEPROMBase< T >::write ( T const &  value) const
inline

Write the value to the EEPROM using the address in this instance.

Template Parameters
valueThe new value to store in EEPROM.

Definition at line 296 of file EEPROM-Base.h.

Member Data Documentation

◆ _address

template<typename T >
uint EEPROMBase< T >::_address = 0
protected

The address of this variable in the EEPROM.

This variable cannot/will not be modified after instantiation.

Definition at line 436 of file EEPROM-Base.h.

◆ _defaultValue

template<typename T >
T EEPROMBase< T >::_defaultValue
protected

The default value.

The default value to return when the EEPROM has not been initialized. The address of this variable in the EEPROM. This variable cannot/will not be modified after instantiation.

Definition at line 444 of file EEPROM-Base.h.


The documentation for this class was generated from the following file: