-
Notifications
You must be signed in to change notification settings - Fork 30
/
metaCommand.h
253 lines (195 loc) · 7.41 KB
/
metaCommand.h
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef metaCommand_h
#define metaCommand_h
#ifdef _MSC_VER
#pragma warning ( disable : 4786 )
#endif
#include <stdlib.h>
#include <string>
#include <vector>
#include <list>
#include <map>
#if (METAIO_USE_NAMESPACE)
namespace METAIO_NAMESPACE {
#endif
#include <iostream>
#include <fstream>
#define METAIO_STL std
#define METAIO_STREAM std
class MetaCommand
{
public:
typedef enum {DATA_NONE,DATA_IN,DATA_OUT} DataEnumType;
typedef enum {INT,FLOAT,CHAR,STRING,LIST,FLAG,BOOL} TypeEnumType;
struct Field{
METAIO_STL::string name;
METAIO_STL::string description;
METAIO_STL::string value;
TypeEnumType type;
DataEnumType externaldata;
METAIO_STL::string rangeMin;
METAIO_STL::string rangeMax;
bool required;
bool userDefined;
};
struct Option{
METAIO_STL::string name;
METAIO_STL::string description;
METAIO_STL::string tag;
METAIO_STL::vector<Field> fields;
bool required;
bool userDefined;
bool complete;
};
typedef METAIO_STL::vector<Option> OptionVector;
MetaCommand();
~MetaCommand() {}
bool SetOption(Option option);
bool SetOption(METAIO_STL::string name,
METAIO_STL::string tag,
bool required,
METAIO_STL::string description,
METAIO_STL::vector<Field> fields);
bool SetOption(METAIO_STL::string name,
METAIO_STL::string tag,
bool required,
METAIO_STL::string description,
TypeEnumType type = FLAG,
METAIO_STL::string defVal = "");
/** Fields are added in order */
bool AddField(METAIO_STL::string name,
METAIO_STL::string description,
TypeEnumType type,
DataEnumType externalData = DATA_NONE,
METAIO_STL::string rangeMin = "",
METAIO_STL::string rangeMax = ""
);
/** For backward compatibility */
bool AddField(METAIO_STL::string name,
METAIO_STL::string description,
TypeEnumType type,
bool externalData
)
{
if(externalData)
{
return this->AddField(name,description,type,DATA_IN);
}
return this->AddField(name,description,type,DATA_NONE);
}
/** Add a field to an option */
bool AddOptionField(METAIO_STL::string optionName,
METAIO_STL::string name,
TypeEnumType type,
bool required=true,
METAIO_STL::string defVal = "",
METAIO_STL::string description = "",
DataEnumType externalData = DATA_NONE);
/** Set the range of value as an option */
bool SetOptionRange(METAIO_STL::string optionName,
METAIO_STL::string name,
METAIO_STL::string rangeMin,
METAIO_STL::string rangeMax);
/** Collect all the information until the next tag
* \warning this function works only if the field is of type String */
void SetOptionComplete(METAIO_STL::string optionName,
bool complete);
/** Get the values given the option name */
bool GetValueAsBool(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
bool GetValueAsBool(Option option,METAIO_STL::string fieldName="");
float GetValueAsFloat(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
float GetValueAsFloat(Option option,METAIO_STL::string fieldName="");
int GetValueAsInt(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
int GetValueAsInt(Option option,METAIO_STL::string fieldName="");
METAIO_STL::string GetValueAsString(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
METAIO_STL::string GetValueAsString(Option option,METAIO_STL::string fieldName="");
METAIO_STL::list< METAIO_STL::string > GetValueAsList(METAIO_STL::string optionName);
METAIO_STL::list< METAIO_STL::string > GetValueAsList(Option option);
bool GetOptionWasSet(METAIO_STL::string optionName);
bool GetOptionWasSet(Option option);
/** List the options */
void ListOptions();
void ListOptionsXML();
void ListOptionsSimplified();
Option * GetOptionByMinusTag(METAIO_STL::string minusTag);
Option * GetOptionByTag(METAIO_STL::string minusTag);
bool OptionExistsByMinusTag(METAIO_STL::string minusTag);
bool Parse(int argc, const char* argv[]);
/** Given an XML buffer fill in the command line arguments */
bool ParseXML(const char* buffer);
/** Export the current command line arguments to a Grid Application
* Description file */
bool ExportGAD(bool dynamic=false);
/** Extract the date from cvs date */
METAIO_STL::string ExtractDateFromCVS(METAIO_STL::string date);
/** Set the version of the app */
METAIO_STL::string GetVersion()
{ return m_Version; }
void SetVersion(const char* version)
{ m_Version=version; }
/** Get the name of the application */
METAIO_STL::string GetApplicationName()
{ return m_ExecutableName; }
/** Set the date of the app */
METAIO_STL::string GetDate()
{ return m_Date; }
void SetDate(const char* date)
{ m_Date=date; }
void SetName(const char* name)
{ m_Name=name; }
void SetDescription(const char* description)
{ m_Description=description; }
METAIO_STL::string GetDescription() const
{return m_Description;}
void SetAuthor(const char* author)
{ m_Author=author; }
METAIO_STL::string GetAuthor() const
{return m_Author;}
long GetOptionId(Option* option);
/** Return the list of options */
const OptionVector & GetOptions()
{ return m_OptionVector; }
/** Return the list of parse options */
const OptionVector & GetParsedOptions()
{ return m_ParsedOptionVector; }
void SetHelpCallBack(void (* newHelpCallBack)(void))
{ m_HelpCallBack = newHelpCallBack; }
METAIO_STL::string TypeToString(TypeEnumType type);
TypeEnumType StringToType(const char* type);
void SetVerbose(bool verbose) {m_Verbose = verbose;}
protected:
/** Small XML helper */
METAIO_STL::string GetXML(const char* buffer,const char* desc,unsigned long pos);
METAIO_STL::string m_Version;
METAIO_STL::string m_Date;
METAIO_STL::string m_Name;
METAIO_STL::string m_Description;
METAIO_STL::string m_Author;
METAIO_STL::string m_ExecutableName;
private:
void (* m_HelpCallBack)(void);
OptionVector m_OptionVector;
OptionVector m_ParsedOptionVector; // We store the parsed option in
// case we have multiple options
bool m_Verbose;
}; // end of class
#if (METAIO_USE_NAMESPACE)
};
#endif
#endif