Commander-API V3.0.0
Lightweight Command Parser
Loading...
Searching...
No Matches
CommanderDatabase< T > Class Template Reference

Database class. More...

#include <Commander-Database.hpp>

Collaboration diagram for CommanderDatabase< T >:

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_toperator[] (int i)
 Overload for indexing operator. More...
 
dataRecord_toperator[] (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_tdataTree = 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
 

Detailed Description

template<typename T>
class CommanderDatabase< T >

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.

Member Enumeration Documentation

◆ debugLevel_t

template<typename T >
enum CommanderDatabase::debugLevel_t

Debug level definitions.

Enumerator
DEBUG_OFF 

All debug messages will be turned off.

DEBUG_ERROR 

Only error messages will be printed.

DEBUG_DEBUG 

Some debug data and the error messages will be printed.

DEBUG_VERBOSE 

All debug messages will be turned on.

Definition at line 62 of file Commander-Database.hpp.

Constructor & Destructor Documentation

◆ CommanderDatabase() [1/2]

template<typename T >
CommanderDatabase< T >::CommanderDatabase

Empty constructor.

Definition at line 215 of file Commander-Database.hpp.

Here is the call graph for this function:

◆ CommanderDatabase() [2/2]

template<typename T >
CommanderDatabase< T >::CommanderDatabase ( dataRecord_t dataTree_p,
uint16_t  dataTreeSize_p 
)

Constructor.

To construct a working object, this must be used.

Parameters
dataTree_pPointer 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_pThe size of the data array in elements.

Definition at line 230 of file Commander-Database.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ attachDebugChannel()

template<typename T >
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.

Parameters
debugChannel_pPointer to a stream, where the debug messages will be printed.
Note
You have to call this function before init, if you need any debug data.

Definition at line 245 of file Commander-Database.hpp.

◆ completeFragment()

template<typename T >
int CommanderDatabase< T >::completeFragment ( const char *  fragment,
char *  buffer,
int  buffer_size 
)

Definition at line 710 of file Commander-Database.hpp.

◆ findIndexByPlace()

template<typename T >
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.

Parameters
placePlace of the searched element.
Returns
The array index of the element if the place is found. If the place is invalid or not found, the returned value will be 0 to avoid bad addressing.

Definition at line 275 of file Commander-Database.hpp.

◆ getSize()

template<typename T >
uint16_t CommanderDatabase< T >::getSize

Get tree size.

You can get the size of the tree wit this function.

Returns
The size of the tree in elements.

Definition at line 638 of file Commander-Database.hpp.

◆ init()

template<typename T >
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.

Returns
If anything goes well, it will return true. If something wrong happens during the tree generation, it will return false.

Definition at line 492 of file Commander-Database.hpp.

◆ operator[]() [1/2]

template<typename T >
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.

Parameters
nameThe name of the searched element.
Returns
The address of the element which has the same name as the name parameter.

Definition at line 592 of file Commander-Database.hpp.

◆ operator[]() [2/2]

template<typename T >
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.

Parameters
iIndex of the element in the tree. If the index is incorrect, the returned value will be NULL.
Returns
The address of the indexed element.

Definition at line 580 of file Commander-Database.hpp.

◆ optimizeDataTree()

template<typename T >
bool CommanderDatabase< T >::optimizeDataTree
protected

Definition at line 322 of file Commander-Database.hpp.

◆ setDebugLevel()

template<typename T >
void CommanderDatabase< T >::setDebugLevel ( debugLevel_t  debugLevel_p)

Set the debug level.

You can set, how detailed debug is needed.

Parameters
debugLevel_pPlease check debugLevel_t for more information.
Note
You have to specify a Stream for the debug messages with attachDebugChannel.

Definition at line 250 of file Commander-Database.hpp.

◆ strcmpDB()

template<typename T >
int CommanderDatabase< T >::strcmpDB ( const char *  p1,
const char *  p2 
)
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.

◆ strcmpElementCharArrayRegular()

template<typename T >
int CommanderDatabase< T >::strcmpElementCharArrayRegular ( dataRecord_t element1,
const char *  element2 
)
protected

Definition at line 260 of file Commander-Database.hpp.

Here is the caller graph for this function:

◆ strcmpElementElementRegular()

template<typename T >
int CommanderDatabase< T >::strcmpElementElementRegular ( dataRecord_t element1,
dataRecord_t element2 
)
protected

Definition at line 255 of file Commander-Database.hpp.

Here is the caller graph for this function:

◆ strncmpDB()

template<typename T >
int CommanderDatabase< T >::strncmpDB ( const char *  p1,
const char *  p2,
size_t  num 
)
protected

Definition at line 673 of file Commander-Database.hpp.

◆ strncmpElementCharArrayRegular()

template<typename T >
int CommanderDatabase< T >::strncmpElementCharArrayRegular ( dataRecord_t element1,
const char *  element2,
size_t  num 
)
protected

Definition at line 270 of file Commander-Database.hpp.

Here is the caller graph for this function:

◆ strncmpElementElementRegular()

template<typename T >
int CommanderDatabase< T >::strncmpElementElementRegular ( dataRecord_t element1,
dataRecord_t element2,
size_t  num 
)
protected

Definition at line 265 of file Commander-Database.hpp.

Here is the caller graph for this function:

◆ swapElements()

template<typename T >
void CommanderDatabase< T >::swapElements ( uint16_t  a,
uint16_t  b 
)
protected

Definition at line 299 of file Commander-Database.hpp.

Friends And Related Function Documentation

◆ CommanderDatabaseUT

template<typename T >
friend class CommanderDatabaseUT
friend

Definition at line 210 of file Commander-Database.hpp.

Member Data Documentation

◆ dataTree

template<typename T >
dataRecord_t* CommanderDatabase< T >::dataTree = NULL
protected

Starting address of the API-tree.

Definition at line 160 of file Commander-Database.hpp.

◆ dataTreeSize

template<typename T >
uint16_t CommanderDatabase< T >::dataTreeSize = 0
protected

Number of elements in the API-tree.

Definition at line 163 of file Commander-Database.hpp.

◆ debugChannel

template<typename T >
Stream* CommanderDatabase< T >::debugChannel = NULL
protected

Pointer to a Stream object, which will be used as debug output.

Definition at line 166 of file Commander-Database.hpp.

◆ debugLevel

template<typename T >
debugLevel_t CommanderDatabase< T >::debugLevel = DEBUG_OFF
protected

Debug level.

Definition at line 169 of file Commander-Database.hpp.

◆ initFlag

template<typename T >
bool CommanderDatabase< T >::initFlag = false
protected

If initialised correctly, it will be true.

Definition at line 172 of file Commander-Database.hpp.

◆ strcmpElementCharArray

template<typename T >
int(CommanderDatabase::* CommanderDatabase< T >::strcmpElementCharArray) (dataRecord_t *element1, const char *element2)
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.

◆ strcmpElementElement

template<typename T >
int(CommanderDatabase::* CommanderDatabase< T >::strcmpElementElement) (dataRecord_t *element1, dataRecord_t *element2)
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.

◆ strncmpElementCharArray

template<typename T >
int(CommanderDatabase::* CommanderDatabase< T >::strncmpElementCharArray) (dataRecord_t *element1, const char *element2, size_t num)
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.

◆ strncmpElementElement

template<typename T >
int(CommanderDatabase::* CommanderDatabase< T >::strncmpElementElement) (dataRecord_t *element1, dataRecord_t *element2, size_t num)
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.