Commander-API V3.0.0
Lightweight Command Parser
|
#include <Commander-Arguments.hpp>
Classes | |
struct | boolFields |
union | returnData |
Public Member Functions | |
Argument (const char *source_p, int place_p) | |
Constructor for place dependent argument. More... | |
Argument (const char *source_p, char shortName_p) | |
Constructor for optional or place independent argument with only short name. More... | |
Argument (const char *source_p, char shortName_p, const char *longName_p) | |
Constructor for optional or place independent argument with short and long name. More... | |
operator int () | |
Override return behaviour for int. More... | |
operator float () | |
Override return behaviour for float. More... | |
operator char * () | |
Override return behaviour for char array. More... | |
operator bool () | |
Override return behaviour for boolean. More... | |
bool | parseInt () |
bool | parseFloat () |
bool | parseStringFunction (char *buffer, int bufferSize) |
bool | find () |
bool | isFound () |
Commander::systemVariable_t * | getSystemVariable () |
Private Types | |
typedef bool | boolField |
Private Member Functions | |
struct Argument::boolFields | __attribute__ ((packed)) |
int | findShortName () |
Find the start position of a short named argument. More... | |
int | findLongName () |
Find the start position of a long named argument. More... | |
int | findByPlace () |
Find the start position of a place dependent argument. More... | |
int | findStart () |
bool | inString (int index) |
int | substring (char *str1, char *str2) |
Private Attributes | |
const char * | source = NULL |
int | sourceSize = -1 |
int | place = -1 |
char | shortName = '\0' |
const char * | longName = NULL |
Commander::systemVariable_t * | systemVariable = NULL |
boolFields | bFields |
union returnData | ret |
Static Private Attributes | |
static const char | failedString = '\0' |
Friends | |
class | ArgumentUT |
Argument class.
This class is made to parse simply int, float and string arguments from a source character array with the syntax style of the getopt library. Sadly getopt can not be used with an embedded system, like an AVR. It is too resource hungry. Also the C version of getopt does not support long argument names. This is a lightweight argument parser and it can be used for 4 kinds of arguments:
This library supports 3 kinds of values:
Definition at line 90 of file Commander-Arguments.hpp.
|
private |
Definition at line 180 of file Commander-Arguments.hpp.
Argument::Argument | ( | const char * | source_p, |
int | place_p | ||
) |
Constructor for place dependent argument.
Use this constructor to create a place dependent argument object.
source_p | The source argument string. This character array must contain the whole argument string. It must be terminated with string end character( '\0' ). |
place_p | The place of the argument in the argument string. It is valid from 0 - N-1, where N is the number of white space separated tokens in the argument string. |
Definition at line 3 of file Commander-Arguments.cpp.
Argument::Argument | ( | const char * | source_p, |
char | shortName_p | ||
) |
Constructor for optional or place independent argument with only short name.
Use this constructor to create an optional or place independent argument object. This version only supports short argument names.
source_p | The source argument string. This character array must contain the whole argument string. It must be terminated with string end character( '\0' ). |
shortName_p | This is a simple character. It is valid from a-z or A-Z. |
Definition at line 33 of file Commander-Arguments.cpp.
Argument::Argument | ( | const char * | source_p, |
char | shortName_p, | ||
const char * | longName_p | ||
) |
Constructor for optional or place independent argument with short and long name.
Use this constructor to create an optional or place independent argument object. This version supports both short and long names.
source_p | The source argument string. This character array must contain the whole argument string. It must be terminated with string end character( '\0' ). |
shortName_p | This is a simple character. It is valid from a-z or A-Z. |
longName_p | Pointer to a character array, that contains the long name. |
Definition at line 63 of file Commander-Arguments.cpp.
|
private |
bool Argument::find | ( | ) |
|
private |
Find the start position of a place dependent argument.
This function will return the position( index ) of the start location of a place dependent argument, if the argument is found in the source string.
Definition at line 303 of file Commander-Arguments.cpp.
|
private |
Find the start position of a long named argument.
This function will return the position( index ) of the start location of a long named argument, if the argument is found in the source string.
Definition at line 175 of file Commander-Arguments.cpp.
|
private |
Find the start position of a short named argument.
This function will return the position( index ) of the start location of a short named argument, if the argument is found in the source string.
Definition at line 92 of file Commander-Arguments.cpp.
|
private |
Definition at line 377 of file Commander-Arguments.cpp.
Commander::systemVariable_t * Argument::getSystemVariable | ( | ) |
Definition at line 790 of file Commander-Arguments.cpp.
|
private |
bool Argument::isFound | ( | ) |
Definition at line 727 of file Commander-Arguments.cpp.
Argument::operator bool | ( | ) |
Override return behaviour for boolean.
The return behaviour is overriden in such a way, that it will return true value if the parsing process for the specified type was successful. Otherwise it will return false.
Definition at line 707 of file Commander-Arguments.cpp.
Argument::operator char * | ( | ) |
Override return behaviour for char array.
The return behaviour is overriden in such a way, that it will return a pointer to the parsed string if the parseString function was successfully parsed the input argument string. Otherwise it will return a pointer to an empty string( "" ).
Definition at line 714 of file Commander-Arguments.cpp.
Argument::operator float | ( | ) |
Override return behaviour for float.
The return behaviour is overriden in such a way, that it will return the parsed float number if the parseFloat function was successfully parsed the input argument string. Otherwise it will return 0.0.
Definition at line 697 of file Commander-Arguments.cpp.
Argument::operator int | ( | ) |
Override return behaviour for int.
The return behaviour is overriden in such a way, that it will return the parsed integer number if the parseInt function was successfully parsed the input argument string. Otherwise it will return 0.
Definition at line 687 of file Commander-Arguments.cpp.
bool Argument::parseFloat | ( | ) |
bool Argument::parseInt | ( | ) |
bool Argument::parseStringFunction | ( | char * | buffer, |
int | bufferSize | ||
) |
|
private |
|
friend |
Definition at line 260 of file Commander-Arguments.hpp.
|
private |
Definition at line 210 of file Commander-Arguments.hpp.
|
staticprivate |
Definition at line 216 of file Commander-Arguments.hpp.
|
private |
Definition at line 203 of file Commander-Arguments.hpp.
|
private |
Definition at line 197 of file Commander-Arguments.hpp.
|
private |
Definition at line 212 of file Commander-Arguments.hpp.
|
private |
Definition at line 200 of file Commander-Arguments.hpp.
|
private |
Definition at line 190 of file Commander-Arguments.hpp.
|
private |
Definition at line 194 of file Commander-Arguments.hpp.
|
private |
Definition at line 207 of file Commander-Arguments.hpp.