EEPROMextent
Arduino EEPROM library
Public Member Functions | List of all members
EEPROM_ItemListClass Class Reference

#include <EEPROM_ItemList.hpp>

Public Member Functions

 EEPROM_ItemListClass ()
 
void begin (int inStartListPos, byte inItemSize, int inListSize)
 
void FreeItem (byte inSlotNumber)
 
void FreeOwnedItems (byte inOwnerSlotNumber)
 
int GetItemPos (byte inSlotNumber)
 
int GetItemPosRaw (byte inSlotNumber)
 
byte GetSlotFromPos (int inPosition)
 
byte GetItemType (byte inSlotNumber)
 
byte GetItemOwner (byte inSlotNumber)
 
int SaveItemPrefix (byte inSlotNumber, byte inType, byte inOwner)
 
byte GetFirstFreeSlot ()
 
byte FindItem (byte inType, byte inStartSlotNumber = 0, byte inOwnerId = 255)
 
byte CountItems (byte inType)
 
byte CountOwnedItems (byte inOwnerId)
 
void clear () const
 

Detailed Description

This class can be used to save heterogeneous items form a hierarchical list..

The base of the data is a list of items of the same size in EEPROM. This size have to be the greatest size among all items to save. The list is initialized with the total size of memory dedicated to this list. The number of items which must be lower than 255, so the total size must be lower than (item size + 2) * 255 ! Each item is identified by a number, the slot number betw<een 0 and the maximum - 1 .

    0      1      2      ...     max
+------+------+------+---------------+
|TPitem|TPitem|TPitem|........|TPitem|
+------+------+------+--------+------+

Each item starts with a type on a byte (the 'T' in the schema). A type at 0 means empty slot. The following byte 'P' gives an optionnal parent slot number. A parent at 255 means no parent. And finaly, the item itself fill the rest of the 'slot' place. Parent and children can be separated and even saved in a random order...

Constructor & Destructor Documentation

EEPROM_ItemListClass::EEPROM_ItemListClass ( )
inline

Default constructor.

Member Function Documentation

void EEPROM_ItemListClass::begin ( int  inStartListPos,
byte  inItemSize,
int  inListSize 
)
inline

Initialize the instance.

Parameters
inStartListPosEEPROM address of the begginning of the memory used for the storage
inItemSizeSize in bytes of one item to save.
inListSizeNumber of bytes of EEPROM used for the total list.
void EEPROM_ItemListClass::clear ( ) const

Clears all the EEPROM memory area reserved for this list.

byte EEPROM_ItemListClass::CountItems ( byte  inType)

Counts the used slot number.

Parameters
inTypeCounts all items of this type. 0 means all types.
Returns
Number of items of the given type, or total number of items if inType is 0.
byte EEPROM_ItemListClass::CountOwnedItems ( byte  inOwnerId)

Counts the children of the given item id.

Parameters
inOwnerIdParent id.
Returns
Number of items with inOwnerId as parent.
byte EEPROM_ItemListClass::FindItem ( byte  inType,
byte  inStartSlotNumber = 0,
byte  inOwnerId = 255 
)

Try to find an item according to its type.

Parameters
inTypetype of the item to find.
inStartSlotNumberStarting position for the research. Default 0.
inOwnerIdTry to find a child of the given owner id. Default is 255, meaning no research by owner id.
Returns
First slot number corresponding to the criterias or 255 if nothing found.
void EEPROM_ItemListClass::FreeItem ( byte  inSlotNumber)

Reset the given slot and children to empty.

Parameters
inSlotNumberThis slot will be declared as empty. If this item have children, there will be freed too.
void EEPROM_ItemListClass::FreeOwnedItems ( byte  inOwnerSlotNumber)

Reset all the children of the given slot to empty. The slot itself will not be freed.

Parameters
inOwnerSlotNumberOwner of the slots to free.
byte EEPROM_ItemListClass::GetFirstFreeSlot ( )

Gets the first free slot number.

Returns
First free slot address or 255 if nothing free.
byte EEPROM_ItemListClass::GetItemOwner ( byte  inSlotNumber)
inline

Gets the parent of the slot item.

Parameters
inSlotNumberslot to check.
Returns
Parent id (byte 'P') of the slot item, 255 if no parent.
int EEPROM_ItemListClass::GetItemPos ( byte  inSlotNumber)
inline

Gets the absolute EEPROM address for the given slot's item.

Parameters
inSlotNumberSlot number to check.
Returns
EEPROM address of the given slot item, AFTER the type and parent bytes.
int EEPROM_ItemListClass::GetItemPosRaw ( byte  inSlotNumber)
inline

Gets the absolute EEPROM address for the full given slot.

Parameters
inSlotNumberSlot number to check.
Returns
EEPROM address of the type byte of the given slot.
byte EEPROM_ItemListClass::GetItemType ( byte  inSlotNumber)
inline

Gets the type of the slot item.

Parameters
inSlotNumberslot to check.
Returns
Type (byte 'T') of the slot item.
byte EEPROM_ItemListClass::GetSlotFromPos ( int  inPosition)
inline

Gets the slot number from an absolute EEPROM address.

Parameters
inPositionEEPROM address.
Returns
Slot number.
int EEPROM_ItemListClass::SaveItemPrefix ( byte  inSlotNumber,
byte  inType,
byte  inOwner 
)

Save the prefix (bytes T and P) of this item.

Parameters
inSlotNumberslot to write.
inTypetype byte to write.
inOwnerparent slot number to write, 255 if no parent.
Returns
EEPROM address to start writing the item.

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