1 #ifndef APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H
2 #define APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H
3
4 #include "./argumentparser.h"
5 #include "./commandlineutils.h"
6
7 #include <optional>
8
9 namespace CppUtilities {
10
11 class CPP_UTILITIES_EXPORT ArgumentReader {
12 public:
13 ArgumentReader(ArgumentParser &parser, const char *const *argv, const char *const *end, bool completionMode = false);
14 ArgumentReader &reset(const char *const *argv, const char *const *end);
15 bool read();
16 bool read(ArgumentVector &args);
17
18 /// \brief The associated ArgumentParser instance.
19 ArgumentParser &parser;
20 /// \brief The Argument instances to store the results. Sub arguments of args are considered as well.
21 ArgumentVector &args;
22 /// \brief An index which is incremented when an argument is encountered (the current index is stored in the occurrence) or a value is encountered.
23 std::size_t index;
24 /// \brief Points to the first argument denotation and will be incremented when a denotation has been processed.
25 const char *const *argv;
26 /// \brief Points to the end of the \a argv array.
27 const char *const *end;
28 /// \brief The last Argument instance which could be detected. Set to nullptr in the initial call. Used for Bash completion.
29 Argument *lastArg;
30 /// \brief Points to the element in argv where lastArg was encountered. Unspecified if lastArg is not set.
31 const char *const *lastArgDenotation;
32 /// \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).
33 const char *argDenotation;
34 /// \brief The type of the currently processed abbreviation denotation. Unspecified if argDenotation is not set.
35 unsigned char argDenotationType;
36 /// \brief Whether completion mode is enabled. In this case reading args will be continued even if an denotation is unknown (regardless of unknownArgumentBehavior()).
37 bool completionMode;
38 };
39
40 class Wrapper;
41
42 std::ostream &operator<<(std::ostream &os, const Wrapper &wrapper);
43
44 class Wrapper {
45 friend std::ostream &operator<<(std::ostream &os, const Wrapper &wrapper);
46
47 public:
48 Wrapper(const char *str, Indentation currentIndentation = Indentation());
49
50 private:
51 const char *const m_str;
52 Indentation m_indentation;
53 };
54
Wrapper(const char * str,Indentation currentIndentation)55 inline Wrapper::Wrapper(const char *str, Indentation currentIndentation)
56 : m_str(str)
57 , m_indentation(currentIndentation)
58 {
59 }
60
61 std::optional<bool> isEnvVariableSet(const char *variableName);
62
63 } // namespace CppUtilities
64
65 #endif // APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H
66