File: argumentparserprivate.h

package info (click to toggle)
martchus-cpp-utilities 5.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: cpp: 12,679; awk: 18; ansic: 12; makefile: 10
file content (61 lines) | stat: -rw-r--r-- 2,554 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H
#define APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H

#include "./argumentparser.h"
#include "./commandlineutils.h"

namespace CppUtilities {

class CPP_UTILITIES_EXPORT ArgumentReader {
public:
    ArgumentReader(ArgumentParser &parser, const char *const *argv, const char *const *end, bool completionMode = false);
    ArgumentReader &reset(const char *const *argv, const char *const *end);
    bool read();
    bool read(ArgumentVector &args);

    /// \brief The associated ArgumentParser instance.
    ArgumentParser &parser;
    /// \brief The Argument instances to store the results. Sub arguments of args are considered as well.
    ArgumentVector &args;
    /// \brief An index which is incremented when an argument is encountered (the current index is stored in the occurrence) or a value is encountered.
    std::size_t index;
    /// \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;
    /// \brief The last Argument instance which could be detected. Set to nullptr in the initial call. Used for Bash completion.
    Argument *lastArg;
    /// \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).
    const char *argDenotation;
    /// \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()).
    bool completionMode;
};

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;
};

inline Wrapper::Wrapper(const char *str, Indentation currentIndentation)
    : m_str(str)
    , m_indentation(currentIndentation)
{
}

} // namespace CppUtilities

#endif // APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H