Commander-API  V2.0.0
Commander-API is a C++ API, that parses character based commands.
Commander Class Reference

Commander class. More...

#include <Commander-API.hpp>

Classes

struct  API_t
 Structure for command data. More...
 

Public Types

typedef struct Commander::API_t API_t
 Structure for command data. More...
 

Public Member Functions

void attachTreeFunction (API_t *API_tree_p, uint32_t API_tree_size_p)
 Attach API-tree to the object. More...
 
void init ()
 Initializer. More...
 
API_toperator[] (int i)
 Array index operator overload for int type. More...
 
API_toperator[] (char *name)
 Array index operator overload for char array( string ). More...
 
API_toperator[] (const char *name)
 Array index operator overload for const char array( string ). More...
 
void execute (char *cmd)
 Default execution function. More...
 
void execute (const char *cmd)
 Default execution function. More...
 
void enableDebug ()
 Enables debug messages. More...
 
void disableDebug ()
 Disables debug messages. More...
 

Static Public Attributes

static const char * version = COMMANDER_API_VERSION
 Library version string. More...
 

Detailed Description

Commander class.

This class can be used to create a command parser. Its job is to parse a command from a character array( string ) and find the matching function for that command from a database. This database consists an array of API_t-type elements, and these elements are store the relevant information for that specific command.

Member Typedef Documentation

◆ API_t

Structure for command data.

Every command will get a structure like this. This structure is used to store your commands in a balanced binary tree.

Member Function Documentation

◆ attachTreeFunction()

void Commander::attachTreeFunction ( API_t API_tree_p,
uint32_t  API_tree_size_p 
)

Attach API-tree to the object.

With this function you can attach the API-tree structure array to the object. This array contains the data for each command.

Note
There is a macro( attachTree ) to simplify this process.

◆ disableDebug()

void Commander::disableDebug ( )

Disables debug messages.

◆ enableDebug()

void Commander::enableDebug ( )

Enables debug messages.

◆ execute() [1/2]

void Commander::execute ( char *  cmd)

Default execution function.

This function tries to execute a command. It uses the default response channel, so the messages from the command handler wont be visible.

◆ execute() [2/2]

void Commander::execute ( const char *  cmd)

Default execution function.

This function tries to execute a command. It uses the default response channel, so the messages from the command handler wont be visible.

◆ init()

void Commander::init ( )

Initializer.

This function initializes the object and its internal parts. Firstly it makes the API-tree alphabetically ordered, then creates a balanced binary tree from it. It is necessary to speed up the search process.

◆ operator[]() [1/3]

Commander::API_t * Commander::operator[] ( char *  name)

Array index operator overload for char array( string ).

With this function you can get a pointer to an element from the API-tree by it's name. If the name is not found the return value will be NULL.

◆ operator[]() [2/3]

Commander::API_t * Commander::operator[] ( const char *  name)

Array index operator overload for const char array( string ).

With this function you can get a pointer to an element from the API-tree by it's name. If the name is not found the return value will be NULL.

◆ operator[]() [3/3]

Commander::API_t * Commander::operator[] ( int  i)

Array index operator overload for int type.

With this function you can get a pointer to an element from the API-tree by it's index. If the index is invalid, the return value will be NULL.

Member Data Documentation

◆ version

const char * Commander::version = COMMANDER_API_VERSION
static

Library version string.