#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 |
Protected Attributes | |
int | startListPos |
byte | itemSize |
int | listSize |
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...
Definition at line 31 of file EEPROM_ItemList.hpp.
|
inline |
Default constructor.
Definition at line 40 of file EEPROM_ItemList.hpp.
|
inline |
Initialize the instance.
inStartListPos | EEPROM address of the begginning of the memory used for the storage |
inItemSize | Size in bytes of one item to save. |
inListSize | Number of bytes of EEPROM used for the total list. |
Definition at line 47 of file EEPROM_ItemList.hpp.
void EEPROM_ItemListClass::clear | ( | ) | const |
Clears all the EEPROM memory area reserved for this list.
Definition at line 103 of file EEPROM_ItemList.cpp.
byte EEPROM_ItemListClass::CountItems | ( | byte | inType | ) |
Counts the used slot number.
inType | Counts all items of this type. 0 means all types. |
Definition at line 58 of file EEPROM_ItemList.cpp.
byte EEPROM_ItemListClass::CountOwnedItems | ( | byte | inOwnerId | ) |
Counts the children of the given item id.
inOwnerId | Parent id. |
Definition at line 69 of file EEPROM_ItemList.cpp.
byte EEPROM_ItemListClass::FindItem | ( | byte | inType, |
byte | inStartSlotNumber = 0 , |
||
byte | inOwnerId = 255 |
||
) |
Try to find an item according to its type.
inType | type of the item to find. |
inStartSlotNumber | Starting position for the research. Default 0. |
inOwnerId | Try to find a child of the given owner id. Default is 255, meaning no research by owner id. |
Definition at line 43 of file EEPROM_ItemList.cpp.
void EEPROM_ItemListClass::FreeItem | ( | byte | inSlotNumber | ) |
Reset the given slot and children to empty.
inSlotNumber | This slot will be declared as empty. If this item have children, there will be freed too. |
Definition at line 18 of file EEPROM_ItemList.cpp.
void EEPROM_ItemListClass::FreeOwnedItems | ( | byte | inOwnerSlotNumber | ) |
Reset all the children of the given slot to empty. The slot itself will not be freed.
inOwnerSlotNumber | Owner of the slots to free. |
Definition at line 25 of file EEPROM_ItemList.cpp.
byte EEPROM_ItemListClass::GetFirstFreeSlot | ( | ) |
Gets the first free slot number.
Definition at line 80 of file EEPROM_ItemList.cpp.
|
inline |
Gets the parent of the slot item.
inSlotNumber | slot to check. |
Definition at line 98 of file EEPROM_ItemList.hpp.
|
inline |
Gets the absolute EEPROM address for the given slot's item.
inSlotNumber | Slot number to check. |
Definition at line 62 of file EEPROM_ItemList.hpp.
|
inline |
Gets the absolute EEPROM address for the full given slot.
inSlotNumber | Slot number to check. |
Definition at line 71 of file EEPROM_ItemList.hpp.
|
inline |
Gets the type of the slot item.
inSlotNumber | slot to check. |
Definition at line 89 of file EEPROM_ItemList.hpp.
|
inline |
Gets the slot number from an absolute EEPROM address.
inPosition | EEPROM address. |
Definition at line 80 of file EEPROM_ItemList.hpp.
int EEPROM_ItemListClass::SaveItemPrefix | ( | byte | inSlotNumber, |
byte | inType, | ||
byte | inOwner | ||
) |
Save the prefix (bytes T and P) of this item.
inSlotNumber | slot to write. |
inType | type byte to write. |
inOwner | parent slot number to write, 255 if no parent. |
Definition at line 95 of file EEPROM_ItemList.cpp.