Commander-API V3.0.0
Lightweight Command Parser
|
Database class. More...
#include <Commander-Database.hpp>
Classes | |
struct | dataRecord_t |
Data record element. More... | |
Public Types | |
enum | debugLevel_t { DEBUG_OFF = 0 , DEBUG_ERROR = 1 , DEBUG_DEBUG = 2 , DEBUG_VERBOSE = 3 } |
Debug level definitions. More... | |
Public Member Functions | |
CommanderDatabase () | |
Empty constructor. More... | |
CommanderDatabase (dataRecord_t *dataTree_p, uint16_t dataTreeSize_p) | |
Constructor. More... | |
void | attachDebugChannel (Stream *debugChannel_p) |
Redirect debug messages. More... | |
void | setDebugLevel (debugLevel_t debugLevel_p) |
Set the debug level. More... | |
bool | init () |
Init function. More... | |
dataRecord_t * | operator[] (int i) |
Overload for indexing operator. More... | |
dataRecord_t * | operator[] (const char *name) |
Overload for indexing operator. More... | |
uint16_t | findIndexByPlace (uint16_t place) |
Find array index by element place. More... | |
uint16_t | getSize () |
Get tree size. More... | |
int | completeFragment (const char *fragment, char *buffer, int buffer_size) |
Protected Member Functions | |
int | strcmpElementElementRegular (dataRecord_t *element1, dataRecord_t *element2) |
int | strcmpElementCharArrayRegular (dataRecord_t *element1, const char *element2) |
int | strncmpElementElementRegular (dataRecord_t *element1, dataRecord_t *element2, size_t num) |
int | strncmpElementCharArrayRegular (dataRecord_t *element1, const char *element2, size_t num) |
void | swapElements (uint16_t a, uint16_t b) |
bool | optimizeDataTree () |
int | strcmpDB (const char *p1, const char *p2) |
Custom strcmp function. More... | |
int | strncmpDB (const char *p1, const char *p2, size_t num) |
Protected Attributes | |
dataRecord_t * | dataTree = NULL |
Starting address of the API-tree. More... | |
uint16_t | dataTreeSize = 0 |
Number of elements in the API-tree. More... | |
Stream * | debugChannel = NULL |
Pointer to a Stream object, which will be used as debug output. More... | |
debugLevel_t | debugLevel = DEBUG_OFF |
Debug level. More... | |
bool | initFlag = false |
If initialised correctly, it will be true. More... | |
int(CommanderDatabase::* | strcmpElementElement )(dataRecord_t *element1, dataRecord_t *element2) |
Function pointer to an internal strcmp like function. More... | |
int(CommanderDatabase::* | strcmpElementCharArray )(dataRecord_t *element1, const char *element2) |
Function pointer to an internal strcmp like function. More... | |
int(CommanderDatabase::* | strncmpElementElement )(dataRecord_t *element1, dataRecord_t *element2, size_t num) |
Function pointer to an internal strcmp like function. More... | |
int(CommanderDatabase::* | strncmpElementCharArray )(dataRecord_t *element1, const char *element2, size_t num) |
Function pointer to an internal strncmp like function. More... | |
Friends | |
class | CommanderDatabaseUT |
Database class.
This class is designed to create a database for any type of data. Every element has to have a unique name, which is case sensitive. The elements can be accessed by their names.
Definition at line 57 of file Commander-Database.hpp.
enum CommanderDatabase::debugLevel_t |
Debug level definitions.
Definition at line 62 of file Commander-Database.hpp.
CommanderDatabase< T >::CommanderDatabase |
Empty constructor.
Definition at line 215 of file Commander-Database.hpp.
CommanderDatabase< T >::CommanderDatabase | ( | dataRecord_t * | dataTree_p, |
uint16_t | dataTreeSize_p | ||
) |
Constructor.
To construct a working object, this must be used.
dataTree_p | Pointer to the data array. The element type must be a configured dataRecord_t. For example: CommanderDatabase<int>::dataRecord_t testData[ 10 ] will create a data array for integer type with 10 elements. |
dataTreeSize_p | The size of the data array in elements. |
Definition at line 230 of file Commander-Database.hpp.
void CommanderDatabase< T >::attachDebugChannel | ( | Stream * | debugChannel_p | ) |
Redirect debug messages.
You can specify an output stream, where the debug messages will be printed. By default it is not specified and no debug messages will be printed.
debugChannel_p | Pointer to a stream, where the debug messages will be printed. |
Definition at line 245 of file Commander-Database.hpp.
int CommanderDatabase< T >::completeFragment | ( | const char * | fragment, |
char * | buffer, | ||
int | buffer_size | ||
) |
Definition at line 710 of file Commander-Database.hpp.
uint16_t CommanderDatabase< T >::findIndexByPlace | ( | uint16_t | place | ) |
Find array index by element place.
This function returns the array index( from 1 to tree size ) of an element by its place variable. It can be handy because the actual place not represents the real index in the binary tree.
place | Place of the searched element. |
Definition at line 275 of file Commander-Database.hpp.
uint16_t CommanderDatabase< T >::getSize |
Get tree size.
You can get the size of the tree wit this function.
Definition at line 638 of file Commander-Database.hpp.
bool CommanderDatabase< T >::init |
Init function.
This function must be called in the init section of your system. It will generate a balanced binary tree structure from the data tree.
Definition at line 492 of file Commander-Database.hpp.
CommanderDatabase< T >::dataRecord_t * CommanderDatabase< T >::operator[] | ( | const char * | name | ) |
Overload for indexing operator.
The indexing operator is overloaded and it can be used with a string to get a pointer to an element by its name parameter. If it is not found, NULL will be returned.
name | The name of the searched element. |
Definition at line 592 of file Commander-Database.hpp.
CommanderDatabase< T >::dataRecord_t * CommanderDatabase< T >::operator[] | ( | int | i | ) |
Overload for indexing operator.
The indexing operator is overloaded and it can be used with an integer to get a pointer to the data tree element. The indexing is protected against wrong addressing.
i | Index of the element in the tree. If the index is incorrect, the returned value will be NULL. |
Definition at line 580 of file Commander-Database.hpp.
|
protected |
Definition at line 322 of file Commander-Database.hpp.
void CommanderDatabase< T >::setDebugLevel | ( | debugLevel_t | debugLevel_p | ) |
Set the debug level.
You can set, how detailed debug is needed.
debugLevel_p | Please check debugLevel_t for more information. |
Definition at line 250 of file Commander-Database.hpp.
|
protected |
Custom strcmp function.
It works like the original strcmp, but it terminates to space character as well.
Definition at line 643 of file Commander-Database.hpp.
|
protected |
|
protected |
|
protected |
Definition at line 673 of file Commander-Database.hpp.
|
protected |
|
protected |
|
protected |
Definition at line 299 of file Commander-Database.hpp.
|
friend |
Definition at line 210 of file Commander-Database.hpp.
|
protected |
Starting address of the API-tree.
Definition at line 160 of file Commander-Database.hpp.
|
protected |
Number of elements in the API-tree.
Definition at line 163 of file Commander-Database.hpp.
|
protected |
Pointer to a Stream object, which will be used as debug output.
Definition at line 166 of file Commander-Database.hpp.
|
protected |
Debug level.
Definition at line 169 of file Commander-Database.hpp.
|
protected |
If initialised correctly, it will be true.
Definition at line 172 of file Commander-Database.hpp.
|
protected |
Function pointer to an internal strcmp like function.
It uses the regular version by default.
Definition at line 180 of file Commander-Database.hpp.
|
protected |
Function pointer to an internal strcmp like function.
It uses the regular version by default.
Definition at line 176 of file Commander-Database.hpp.
|
protected |
Function pointer to an internal strncmp like function.
It uses the regular version by default.
Definition at line 188 of file Commander-Database.hpp.
|
protected |
Function pointer to an internal strcmp like function.
It uses the regular version by default.
Definition at line 184 of file Commander-Database.hpp.