2016-12-23 09:55:12 +01:00
# ifndef APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H
# define APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H
2017-09-29 20:58:58 +02:00
# include "./argumentparser.h"
# include "./commandlineutils.h"
2021-05-28 19:15:09 +02:00
# include <optional>
2019-06-10 21:56:46 +02:00
namespace CppUtilities {
2016-12-23 09:55:12 +01:00
2017-06-10 21:52:08 +02:00
class CPP_UTILITIES_EXPORT ArgumentReader {
public :
2016-12-23 09:55:12 +01:00
ArgumentReader ( ArgumentParser & parser , const char * const * argv , const char * const * end , bool completionMode = false ) ;
2019-06-10 21:56:46 +02:00
ArgumentReader & reset ( const char * const * argv , const char * const * end ) ;
2018-05-07 20:04:30 +02:00
bool read ( ) ;
bool read ( ArgumentVector & args ) ;
2016-12-23 09:55:12 +01:00
2016-12-23 22:41:06 +01:00
/// \brief The associated ArgumentParser instance.
2016-12-23 09:55:12 +01:00
ArgumentParser & parser ;
2016-12-23 22:41:06 +01:00
/// \brief The Argument instances to store the results. Sub arguments of args are considered as well.
2016-12-23 09:55:12 +01:00
ArgumentVector & args ;
2016-12-23 22:41:06 +01:00
/// \brief An index which is incremented when an argument is encountered (the current index is stored in the occurrence) or a value is encountered.
2020-11-25 17:51:13 +01:00
std : : size_t index ;
2016-12-23 09:55:12 +01:00
/// \brief Points to the first argument denotation and will be incremented when a denotation has been processed.
const char * const * argv ;
/// \brief Points to the end of the \a argv array.
const char * const * end ;
2016-12-23 22:41:06 +01:00
/// \brief The last Argument instance which could be detected. Set to nullptr in the initial call. Used for Bash completion.
2016-12-23 09:55:12 +01:00
Argument * lastArg ;
2016-12-23 22:41:06 +01:00
/// \brief Points to the element in argv where lastArg was encountered. Unspecified if lastArg is not set.
const char * const * lastArgDenotation ;
/// \brief The currently processed abbreviation denotation (should be substring of one of the args in argv). Set to nullptr for processing argv from the beginning (default).
2016-12-23 09:55:12 +01:00
const char * argDenotation ;
2016-12-23 22:41:06 +01:00
/// \brief The type of the currently processed abbreviation denotation. Unspecified if argDenotation is not set.
unsigned char argDenotationType ;
/// \brief Whether completion mode is enabled. In this case reading args will be continued even if an denotation is unknown (regardless of unknownArgumentBehavior()).
2016-12-23 09:55:12 +01:00
bool completionMode ;
} ;
2017-09-29 20:58:58 +02:00
class Wrapper ;
std : : ostream & operator < < ( std : : ostream & os , const Wrapper & wrapper ) ;
class Wrapper {
friend std : : ostream & operator < < ( std : : ostream & os , const Wrapper & wrapper ) ;
public :
Wrapper ( const char * str , Indentation currentIndentation = Indentation ( ) ) ;
private :
const char * const m_str ;
Indentation m_indentation ;
} ;
2019-04-13 20:30:31 +02:00
inline Wrapper : : Wrapper ( const char * str , Indentation currentIndentation )
2017-09-29 20:58:58 +02:00
: m_str ( str )
, m_indentation ( currentIndentation )
{
}
2021-05-28 19:15:09 +02:00
std : : optional < bool > isEnvVariableSet ( const char * variableName ) ;
2019-06-10 21:56:46 +02:00
} // namespace CppUtilities
2016-12-23 09:55:12 +01:00
# endif // APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H