-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwsjcpp_arguments.h
More file actions
144 lines (118 loc) · 4.96 KB
/
Copy pathwsjcpp_arguments.h
File metadata and controls
144 lines (118 loc) · 4.96 KB
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
#ifndef WSJCPP_ARGUMENTS_H
#define WSJCPP_ARGUMENTS_H
#include <string>
#include <vector>
#include <map>
class WsjcppArgumentSingle {
public:
WsjcppArgumentSingle(const std::string &sName, const std::string &sDescription);
std::string getName();
std::string getDescription();
private:
std::string TAG;
std::string m_sName;
std::string m_sDescription;
};
// ---------------------------------------------------------------------
class WsjcppArgumentParameter {
public:
WsjcppArgumentParameter(
const std::string &sName,
const std::string &sValueName,
const std::string &sDescription
);
std::string getName();
std::string getValueName();
std::string getDescription();
std::string getValue();
void setValue(const std::string &sValue);
private:
std::string TAG;
std::string m_sName;
std::string m_sValueName;
std::string m_sValue;
std::string m_sDescription;
};
// ---------------------------------------------------------------------
class WsjcppArgumentProcessor {
public:
WsjcppArgumentProcessor(
const std::vector<std::string> &vNames,
const std::string &sShortDescription,
const std::string &sDescription
);
const std::vector<std::string> &getNames();
std::string getNamesAsString();
std::string getShortDescription();
std::string getDescription();
void registryProcessor(WsjcppArgumentProcessor *p);
void registryExample(const std::string &sExample);
void registrySingleArgument(const std::string &sArgumentName, const std::string &sDescription);
void registryParameterArgument(
const std::string &sArgumentName,
const std::string &sArgumentValueName,
const std::string &sDescription
);
WsjcppArgumentProcessor *findRegisteredProcessor(const std::string &sArgumentName);
WsjcppArgumentSingle *findRegisteredSingleArgument(const std::string &sArgumentName);
WsjcppArgumentParameter *findRegisteredParameterArgument(const std::string &sArgumentName);
bool hasRegisteredArgumentName(const std::string &sArgumentName);
bool getValueOfParam(const std::string &sArgumentName);
int help(
const std::vector<std::string> &vRoutes,
const std::vector<std::string> &vSubParams
);
bool hasMoreOptions();
virtual bool applySingleArgument(const std::string &sProgramName, const std::string &sArgumentName);
virtual bool applyParameterArgument(const std::string &sProgramName, const std::string &sArgumentName, const std::string &sValue);
virtual int exec(const std::vector<std::string> &vRoutes, const std::vector<std::string> &vSubParams);
protected:
std::string TAG;
private:
std::vector<std::string> m_vNames;
std::string m_sShortDescription;
std::string m_sDescription;
std::vector<WsjcppArgumentProcessor *> m_vProcessors;
std::vector<WsjcppArgumentSingle *> m_vSingleArguments;
std::vector<WsjcppArgumentParameter *> m_vParameterArguments;
std::vector<std::string> m_vExamples;
};
// ---------------------------------------------------------------------
class WsjcppArgumentsSpliter {
public:
WsjcppArgumentsSpliter(WsjcppArgumentProcessor *pArgumentProcessor, const std::vector<std::string> &vParams);
std::vector<std::string> getSingleAgruments();
std::vector<std::string> getParamsArguments();
private:
std::vector<std::string> m_vOriginalParams;
std::vector<std::string> m_vSingleArguments;
std::vector<std::string> m_vParamsArguments;
};
// ---------------------------------------------------------------------
class WsjcppArguments {
public:
WsjcppArguments(int argc, const char* argv[], WsjcppArgumentProcessor *pRoot);
~WsjcppArguments();
void enablePrintAutoHelp(bool bEnablePrintAutoHelp);
int exec();
private:
WsjcppArgumentProcessor *m_pRoot;
std::vector<std::string> extractSingleAndParameterArguments(
WsjcppArgumentProcessor *pArgumentProcessor,
const std::vector<std::string> &vArguments,
std::vector<WsjcppArgumentSingle *> &vSingleArguments,
std::vector<WsjcppArgumentParameter *> &vParameterArguments
);
int recursiveExec(
WsjcppArgumentProcessor *pArgumentProcessor,
std::vector<std::string> &vRoutes,
std::vector<std::string> &vSubArguments
);
std::string TAG;
std::vector<std::string> m_vArguments;
std::string m_sProgramName;
bool m_bEnablePrintAutoHelp;
std::vector<WsjcppArgumentProcessor *> m_vProcessors;
};
// ---------------------------------------------------------------------
#endif // WSJCPP_ARGUMENTS_H