|
AGXDynamics
2.31.1.0
|
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. More... | |
| ArgumentParser (int argc, char **argv) | |
| Constructs an argument parser from the program command line input. More... | |
| ArgumentParser (const agx::StringVector &arguments) | |
| Constructs an argument parser from the program command line input given as an array of strings. More... | |
| void | addArgument (const char *argumentName) |
| Adds an argument manually. More... | |
| template<typename T > | |
| T * | as () |
| Subclass casting. More... | |
| template<typename T > | |
| const T * | as () const |
| template<typename T > | |
| T * | asSafe () |
| Safe subclass casting, return nullptr if template type does not match. More... | |
| template<typename T > | |
| const T * | asSafe () const |
| 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. More... | |
| int | find (const std::string &key, size_t startPosition=0, bool findAlsoHandled=true) |
| Finds the position of an argument. More... | |
| Argument * | getArgument (size_t index) |
| Gets an argument at a position in the argument container. More... | |
| char ** | getArgv () |
| Gets the original array of c-strings. More... | |
| size_t | getNumArguments () const |
| Returns the number of arguments. More... | |
| int | getReferenceCount () const |
| template<typename T > | |
| bool | is () const |
| Subclass test. More... | |
| bool | read (const std::string &key, size_t startPosition=0, bool findAlsoHandled=true) |
| Looks for an argument, and returns true if it finds it. More... | |
| 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. More... | |
| 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. More... | |
| 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. More... | |
| void | reference (void *ptr=nullptr) const |
| Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it. More... | |
| bool | reportUnreadArguments (std::ostream &out=std::cout) |
| Writes all arguments which have not been handled to a stream. More... | |
| void | unreference (void *ptr=nullptr) const |
| Decrement the reference count by one, indicating that a pointer to this object is referencing it. More... | |
| void | unreference_nodelete () const |
| Decrement the reference count by one, indicating that a pointer to this object is referencing it. More... | |
Static Public Member Functions | |
| template<typename T > | |
| static bool | ValidateCast (const Referenced *object) |
Protected Member Functions | |
| virtual | ~ArgumentParser () |
| void | allocateObserverVector () const |
| void | deleteUsingDeleteHandler () const |
Static Protected Member Functions | |
| static DeleteHandler * | getDeleteHandler () |
| static void | setDeleteHandler (DeleteHandler *handler) |
| Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to. More... | |
Protected Attributes | |
| 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 38 of file ArgumentParser.h.
Definition at line 73 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. |
|
protectedinherited |
|
inherited |
Subclass casting.
Template type must match actual type, dynamic_cast assertion will fail otherwise.
Referenced by agx::InternalData::get(), agxVehicle::Track::getNode(), agx::InternalData::getOrCreate(), and agx::InternalData::hasData().
|
inherited |
|
inherited |
Safe subclass casting, return nullptr if template type does not match.
Referenced by agxUtil::CollectBodiesAndWiresVisitor::visit().
|
inherited |
| 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 276 of file ArgumentParser.h.
References AGXCORE_EXPORT.
|
protectedinherited |
| 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().
| 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.
|
staticprotectedinherited |
| size_t agxIO::ArgumentParser::getNumArguments | ( | ) | const |
Returns the number of arguments.
|
inherited |
|
inherited |
Subclass test.
Referenced by agx::Object::getAutoScopedResource(), agxData::EntityStorage::getInstances(), and agx::Object::getResource().
| 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 222 of file ArgumentParser.h.
| 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 238 of file ArgumentParser.h.
| 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 256 of file ArgumentParser.h.
Explicitly increment the reference count by one, indicating that this object has another pointer which is referencing it.
This method should be used with care, always balanced with the same number of calls to unreference.
| 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. |
|
staticprotectedinherited |
Internal: Set a DeleteHandler to which deletion of all referenced counted objects will be delegated to.
Decrement the reference count by one, indicating that a pointer to this object is referencing it.
If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.
This method should be used with care, always balanced with the same number of calls to reference.
Referenced by agxData::EntityRef< ContactMaterialPtr >::~EntityRef().
|
inherited |
Decrement the reference count by one, indicating that a pointer to this object is referencing it.
However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be responsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.
|
staticinherited |
|
mutableprotectedinherited |
Definition at line 240 of file Referenced.h.
|
mutableprotectedinherited |
Definition at line 239 of file Referenced.h.
|
mutableprotectedinherited |
Definition at line 241 of file Referenced.h.