|
AGX Dynamics 2.42.3.1
|
A small argument parser class. More...
#include <ArgumentParser.h>
Inheritance diagram for agxIO::ArgumentParser:Classes | |
| class | Argument |
| Help class for handling arguments. More... | |
Public Types | |
| typedef agx::Vector< Argument > | ArgumentVector |
Public Member Functions | |
| ArgumentParser () | |
| Constructs an argument parser from the program command line input. | |
| ArgumentParser (const agx::StringVector &arguments) | |
| Constructs an argument parser from the program command line input given as an array of strings. | |
| ArgumentParser (int argc, char **argv) | |
| Constructs an argument parser from the program command line input. | |
| void | addArgument (const char *argumentName) |
| Adds an argument manually. | |
| template<typename T > | |
| T | defaultRead (const std::string &key, const T &defaultValue, size_t startPosition=0, bool findAlsoHandled=true) |
| Reads an argument into a variable. | |
| int | find (const std::string &key, size_t startPosition=0, bool findAlsoHandled=true) |
| Finds the position of an argument. | |
| Argument * | getArgument (size_t index) |
| Gets an argument at a position in the argument container. | |
| char ** | getArgv () |
| Gets the original array of c-strings. | |
| size_t | getNumArguments () const |
| Returns the number of arguments. | |
| bool | read (const std::string &key, size_t startPosition=0, bool findAlsoHandled=true) |
| Looks for an argument, and returns true if it finds it. | |
| template<typename T > | |
| bool | read1 (const std::string &key, T &value, size_t startPosition=0, bool findAlsoHandled=true) |
| Looks for an argument, and reads it into a variable if found. | |
| template<typename T1 , typename T2 > | |
| bool | read2 (const std::string &key, T1 &value1, T2 &value2, size_t startPosition=0, bool findAlsoHandled=true) |
| Reads two argument into variables. | |
| template<typename T1 , typename T2 , typename T3 > | |
| bool | read3 (const std::string &key, T1 &value1, T2 &value2, T3 &value3, size_t startPosition=0, bool findAlsoHandled=true) |
| Reads three argument into variables. | |
| bool | reportUnreadArguments (std::ostream &out=std::cout) |
| Writes all arguments which have not been handled to a stream. | |
Public Member Functions inherited from agx::Referenced | |
| Referenced () | |
| Default constructor. | |
| Referenced (const Referenced &) | |
| template<typename T > | |
| T * | as () |
| Subclass casting. | |
| template<typename T > | |
| const T * | as () const |
| template<typename T > | |
| T * | asSafe () |
| Safe subclass casting, return nullptr if template type does not match. | |
| template<typename T > | |
| const T * | asSafe () const |
| int | getReferenceCount () const |
| template<typename T > | |
| bool | is () const |
| Subclass test. | |
| Referenced & | operator= (const Referenced &) |
| Assignment operator. Will increment the number of references to the referenced object. | |
| void | reference (void *ptr=nullptr) const |
| Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. | |
| void | unreference (void *ptr=nullptr) const |
| Decrement the reference count by one, indicating that a pointer to this object is referencing it. | |
| void | unreference_nodelete () const |
| Decrement the reference count by one, indicating that a pointer to this object is referencing it. | |
Protected Member Functions | |
| virtual | ~ArgumentParser () |
Protected Member Functions inherited from agx::Referenced | |
| virtual | ~Referenced () |
| Destructor. | |
| void | allocateObserverVector () const |
| void | deleteUsingDeleteHandler () const |
Additional Inherited Members | |
Static Public Member Functions inherited from agx::Referenced | |
| template<typename T > | |
| static bool | ValidateCast (const Referenced *object) |
Static Protected Member Functions inherited from agx::Referenced | |
| static DeleteHandler * | getDeleteHandler () |
| static void | setDeleteHandler (DeleteHandler *handler) |
| Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. | |
Protected Attributes inherited from agx::Referenced | |
| Mutex | m_mutex |
| ObserverContainer | m_observers |
| AtomicValue | m_refCount |
A small argument parser class.
Copies over the content of all c strings to std::strings.
There is no differentiation between keys and values, which means that if the arguments are "a b", then "a" could be key and "b" value, and/or both could be keys (without values).
Definition at line 37 of file ArgumentParser.h.
Definition at line 72 of file ArgumentParser.h.
| agxIO::ArgumentParser::ArgumentParser | ( | ) |
Constructs an argument parser from the program command line input.
| agxIO::ArgumentParser::ArgumentParser | ( | int | argc, |
| char ** | argv | ||
| ) |
Constructs an argument parser from the program command line input.
Each white-space separated string is treated as a separate argument, so that the number of arguments will correspond to argc. The content of argv is copied and stored internally.
| agxIO::ArgumentParser::ArgumentParser | ( | const agx::StringVector & | arguments | ) |
Constructs an argument parser from the program command line input given as an array of strings.
|
protectedvirtual |
| void agxIO::ArgumentParser::addArgument | ( | const char * | argumentName | ) |
Adds an argument manually.
Not recommended unless you know what you're doing.
| argumentName | Name of the argument to be added. |
| T agxIO::ArgumentParser::defaultRead | ( | const std::string & | key, |
| const T & | defaultValue, | ||
| size_t | startPosition = 0, |
||
| bool | findAlsoHandled = true |
||
| ) |
Reads an argument into a variable.
| key | Key argument |
| defaultValue | Value to be returned if read is not successful |
| startPosition | Position in argument array where to start searching from. |
| findAlsoHandled | Should also arguments been found which have been treated as 'handled'? |
| The | value of the value argument, if the read was successful, otherwise the defaultValue. |
Definition at line 275 of file ArgumentParser.h.
References read1().
| int agxIO::ArgumentParser::find | ( | const std::string & | key, |
| size_t | startPosition = 0, |
||
| bool | findAlsoHandled = true |
||
| ) |
Finds the position of an argument.
Returns -1 if not found.
| key | Argument name |
| startPosition | Position in argument array where to start searching from. |
| findAlsoHandled | Should also arguments been found which have been treated as 'handled'? |
| position | of argument if found, -1 if not found |
Referenced by agxUnit::haveUnittestingArguments(), read1(), read2(), and read3().
| Argument * agxIO::ArgumentParser::getArgument | ( | size_t | index | ) |
Gets an argument at a position in the argument container.
| char ** agxIO::ArgumentParser::getArgv | ( | ) |
Gets the original array of c-strings.
The content has been copied to an internal data structure.
| size_t agxIO::ArgumentParser::getNumArguments | ( | ) | const |
Returns the number of arguments.
| bool agxIO::ArgumentParser::read | ( | const std::string & | key, |
| size_t | startPosition = 0, |
||
| bool | findAlsoHandled = true |
||
| ) |
Looks for an argument, and returns true if it finds it.
| key | Argument name |
| startPosition | Position in argument array where to start searching from. |
| findAlsoHandled | Should also arguments been found which have been treated as 'handled'? |
| Returns | if the argument was found. |
| bool agxIO::ArgumentParser::read1 | ( | const std::string & | key, |
| T & | value, | ||
| size_t | startPosition = 0, |
||
| bool | findAlsoHandled = true |
||
| ) |
Looks for an argument, and reads it into a variable if found.
| key | Key argument |
| value | Value argument, which has to come directly after the key argument in the argument list. |
| startPosition | Position in argument array where to start searching from. |
| findAlsoHandled | Should also arguments been found which have been treated as 'handled'? |
| Were | the key and value argument found, and was the conversion successful? |
Definition at line 221 of file ArgumentParser.h.
References find(), and agx::Container::size().
Referenced by defaultRead().
| bool agxIO::ArgumentParser::read2 | ( | const std::string & | key, |
| T1 & | value1, | ||
| T2 & | value2, | ||
| size_t | startPosition = 0, |
||
| bool | findAlsoHandled = true |
||
| ) |
Reads two argument into variables.
| key | Key argument |
| value1 | Value argument, which has to come directly after the key argument in the argument list. |
| value2 | Value argument, which has to come directly after the key argument in the argument list. |
| startPosition | Position in argument array where to start searching from. |
| findAlsoHandled | Should also arguments been found which have been treated as 'handled'? |
| Were | the key and value argument found, and was the conversion successful? |
Definition at line 237 of file ArgumentParser.h.
References find(), and agx::Container::size().
| bool agxIO::ArgumentParser::read3 | ( | const std::string & | key, |
| T1 & | value1, | ||
| T2 & | value2, | ||
| T3 & | value3, | ||
| size_t | startPosition = 0, |
||
| bool | findAlsoHandled = true |
||
| ) |
Reads three argument into variables.
| key | Key argument |
| value1 | Value argument, which has to come directly after the key argument in the argument list. |
| value2 | Value argument, which has to come directly after the key argument in the argument list. |
| value3 | Value argument, which has to come directly after the key argument in the argument list. |
| startPosition | Position in argument array where to start searching from. |
| findAlsoHandled | Should also arguments been found which have been treated as 'handled'? |
| Were | the key and value argument found, and was the conversion successful? |
Definition at line 255 of file ArgumentParser.h.
References find(), and agx::Container::size().
| bool agxIO::ArgumentParser::reportUnreadArguments | ( | std::ostream & | out = std::cout | ) |
Writes all arguments which have not been handled to a stream.
| out | An std::ostream that should be written to. |