File: CommandLineParser.hpp

package info (click to toggle)
pbseqlib 0~20161219-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,924 kB
  • ctags: 5,123
  • sloc: cpp: 82,727; makefile: 305; python: 239; sh: 8
file content (173 lines) | stat: -rw-r--r-- 4,869 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifndef _BLASR_COMMAND_LINE_PARSER_HPP_
#define _BLASR_COMMAND_LINE_PARSER_HPP_

#include <vector>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <assert.h>
#include <sstream>
#include "StringUtils.hpp"

class CommandLineParser {
public:
    enum ErrorValue {
        CLGood,
        CLBadOption,
        CLMissingOption,
        CLMissingValue,
        CLInvalidInteger,
        CLInvalidPositiveInteger,
        CLInvalidNonNegativeInteger,
        CLInvalidFloat,
        CLInvalidPositiveFloat,
        CLInvalidNonNegativeFloat };


    enum OptionType {
        Flag,
        Integer,
        PositiveInteger, // > 0
        NonNegativeInteger, // >= 0
        IntegerList,
        Float,
        PositiveFloat,  // > 0
        NonNegativeFloat, // >= 0
        String,
        StringList };

    std::vector<bool*> boolValues;
    std::vector<int*> intValues;
    std::vector<float*> floatValues;
    std::vector<std::string*> stringValues;
    std::vector<std::vector<std::string> *>stringListValues;
    std::vector<std::vector<int> *> intListValues;
    std::vector<int*> flagList;
    std::vector<std::string> optionList;
    std::vector<OptionType>    optionTypeList;
    std::vector<int>    optionValueIndexList;
    std::vector<std::string> descriptions;
    std::vector<char>   optionRequired;
    std::vector<char>   optionUsed;
    std::vector<char>   named;

    std::string programName;
    std::string programSummary;
    std::string conciseHelp;
    std::string verboseHelp;
    std::string helpString;
    std::string examples;
    std::string version;

    int lineLength;
    int numUnnamedOptions;
    bool specialVersionFlag;

    CommandLineParser();

    void SetProgramSummary(std::string summaryp);

    void SetHelp(std::string _help);

    void SetConciseHelp(std::string _conciseHelp) ;

    void SetProgramName(std::string namep);

    void SetVersion(std::string versionp);

    void SetVerboseHelp(std::string helpp);

    void SetExamples(std::string examplesp);

    void RegisterPreviousFlagsAsHidden();

    void RegisterVersionFlag(bool *value);

    void RegisterFlagOption(std::string option, bool *value, 
        std::string description, bool required=false);

    void RegisterIntOption(std::string option, int *value, 
        std::string description, OptionType type, 
        bool required=false);

    void RegisterFloatOption(std::string option, float *value, 
        std::string description, OptionType type, bool required=false);

    void RegisterStringOption(std::string option, std::string *value, 
        std::string description, bool required=false);

    void RegisterStringListOption(std::string option, 
        std::vector<std::string> *value, std::string description, 
        bool required=false);

    void RegisterIntListOption(std::string option, std::vector<int> *value, 
        std::string description, bool required=false);

    int IsOption(char *str);

    int IsInteger(char *str);

    int IsFloat(char *str);

    int FindOption(char *option);

    static void CommandLineToString(int argc, char* argv[], 
        std::string& commandLine);

    int ParseCommandLine(int argc, char* argv[], bool isProgramNameOnlyAllowed=false);

    int ParseCommandLine(int argc, char* argv[], 
        std::vector<std::string> &unflaggedValues, bool isProgramNameOnlyAllowed=false);

    ErrorValue ParseOption(int optionIndex,
        int &argi, int argc, char *argv[]);

    void PrintErrorMessage(ErrorValue ev, char *option);

    ErrorValue ParseFlag(int optionValueIndex);

    ErrorValue ParseInteger(int optionValueIndex, 
        int &argi, int argc, char *argv[]);

    ErrorValue ParsePositiveInteger(int optionValueIndex, 
        int &argi, int argc, char *argv[]);

    ErrorValue ParseNonNegativeInteger(int optionValueIndex, 
        int &argi, int argc, char *argv[]);

    ErrorValue ParseFloat(int optionValueIndex, 
        int &argi, int argc, char *argv[]);

    ErrorValue ParsePositiveFloat(int optionValueIndex, 
        int &argi, int argc, char *argv[]);

    ErrorValue ParseNonNegativeFloat(int optionValueIndex, 
        int &argi, int argc, char *argv[]);

    ErrorValue ParseString(int optionValueIndex, int &argi, 
        int argc, char *argv[]);

    bool IsValuedOption(OptionType optType);

    ErrorValue ParseIntList(int optionValueIndex, int &argi, 
        int argc, char *argv[]);

    ErrorValue ParseStringList(int optionValueIndex, int &argi, 
        int argc, char *argv[]);

    void PrintVersion();

    void PrintUsage();

    int GetNextWordLength(std::string &text, int pos);

    void PrintIndentedText(std::ostream &out, std::string &text, 
        int allLineIndent, int lineLength = 80, int firstLineIndent=0);

    unsigned int GetMaxOptionLength();

    ErrorValue PrintErrorOnMissingOptions();
};

#endif