Debian Codegraph @

metaCommand.h

raw
1 /*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18 #ifndef metaCommand_h
19 #define metaCommand_h
20
21
22 #ifdef _MSC_VER
23 #pragma warning ( disable : 4786 )
24 #endif
25
26 #include <stdlib.h>
27 #include <string>
28 #include <vector>
29 #include <list>
30 #include <map>
31
32 #ifndef METAIO_USE_NAMESPACE
33 #define METAIO_USE_NAMESPACE 0
34 #endif
35
36 #if (METAIO_USE_NAMESPACE)
37 namespace METAIO_NAMESPACE {
38 #endif
39
40 #include <iostream>
41 #include <fstream>
42
43 #define METAIO_STL std
44 #define METAIO_STREAM std
45
46 class MetaCommand
47 {
48
49 public:
50
51 typedef enum {DATA_NONE,DATA_IN,DATA_OUT} DataEnumType;
52 typedef enum {INT,FLOAT,CHAR,STRING,LIST,FLAG,BOOL} TypeEnumType;
53
54 struct Field{
55 METAIO_STL::string name;
56 METAIO_STL::string description;
57 METAIO_STL::string value;
58 TypeEnumType type;
59 DataEnumType externaldata;
60 METAIO_STL::string rangeMin;
61 METAIO_STL::string rangeMax;
62 bool required;
63 bool userDefined;
64 };
65
66 struct Option{
67 METAIO_STL::string name;
68 METAIO_STL::string description;
69 METAIO_STL::string tag;
70 METAIO_STL::vector<Field> fields;
71 bool required;
72 bool userDefined;
73 bool complete;
74 };
75
76 typedef METAIO_STL::vector<Option> OptionVector;
77
78 MetaCommand();
79 ~MetaCommand() {}
80
81 bool SetOption(Option option);
82 bool SetOption(METAIO_STL::string name,
83 METAIO_STL::string tag,
84 bool required,
85 METAIO_STL::string description,
86 METAIO_STL::vector<Field> fields);
87 bool SetOption(METAIO_STL::string name,
88 METAIO_STL::string tag,
89 bool required,
90 METAIO_STL::string description,
91 TypeEnumType type = FLAG,
92 METAIO_STL::string defVal = "");
93
94 /** Fields are added in order */
95 bool AddField(METAIO_STL::string name,
96 METAIO_STL::string description,
97 TypeEnumType type,
98 DataEnumType externalData = DATA_NONE,
99 METAIO_STL::string rangeMin = "",
100 METAIO_STL::string rangeMax = ""
101 );
102
103 /** For backward compatibility */
104 bool AddField(METAIO_STL::string name,
105 METAIO_STL::string description,
106 TypeEnumType type,
107 bool externalData
108 )
109 {
110 if(externalData)
111 {
112 return this->AddField(name,description,type,DATA_IN);
113 }
114 return this->AddField(name,description,type,DATA_NONE);
115 }
116
117
118 /** Add a field to an option */
119 bool AddOptionField(METAIO_STL::string optionName,
120 METAIO_STL::string name,
121 TypeEnumType type,
122 bool required=true,
123 METAIO_STL::string defVal = "",
124 METAIO_STL::string description = "",
125 DataEnumType externalData = DATA_NONE);
126
127 /** Set the range of value as an option */
128 bool SetOptionRange(METAIO_STL::string optionName,
129 METAIO_STL::string name,
130 METAIO_STL::string rangeMin,
131 METAIO_STL::string rangeMax);
132
133
134 /** Collect all the information until the next tag
135 * \warning this function works only if the field is of type String */
136 void SetOptionComplete(METAIO_STL::string optionName,
137 bool complete);
138
139 /** Get the values given the option name */
140 bool GetValueAsBool(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
141 bool GetValueAsBool(Option option,METAIO_STL::string fieldName="");
142
143 float GetValueAsFloat(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
144 float GetValueAsFloat(Option option,METAIO_STL::string fieldName="");
145
146 int GetValueAsInt(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
147 int GetValueAsInt(Option option,METAIO_STL::string fieldName="");
148
149 METAIO_STL::string GetValueAsString(METAIO_STL::string optionName,METAIO_STL::string fieldName="");
150 METAIO_STL::string GetValueAsString(Option option,METAIO_STL::string fieldName="");
151
152 METAIO_STL::list< METAIO_STL::string > GetValueAsList(METAIO_STL::string optionName);
153 METAIO_STL::list< METAIO_STL::string > GetValueAsList(Option option);
154
155 bool GetOptionWasSet(METAIO_STL::string optionName);
156 bool GetOptionWasSet(Option option);
157
158 /** List the options */
159 void ListOptions();
160 void ListOptionsXML();
161 void ListOptionsSimplified();
162
163 Option * GetOptionByMinusTag(METAIO_STL::string minusTag);
164 Option * GetOptionByTag(METAIO_STL::string minusTag);
165
166 bool OptionExistsByMinusTag(METAIO_STL::string minusTag);
167
168 bool Parse(int argc, const char* argv[]);
169
170 /** Given an XML buffer fill in the command line arguments */
171 bool ParseXML(const char* buffer);
172
173 /** Export the current command line arguments to a Grid Application
174 * Description file */
175 bool ExportGAD(bool dynamic=false);
176
177 /** Extract the date from cvs date */
178 METAIO_STL::string ExtractDateFromCVS(METAIO_STL::string date);
179
180 /** Set the version of the app */
181 METAIO_STL::string GetVersion()
182 { return m_Version; }
183
184 void SetVersion(const char* version)
185 { m_Version=version; }
186
187 /** Get the name of the application */
188 METAIO_STL::string GetApplicationName()
189 { return m_ExecutableName; }
190
191 /** Set the date of the app */
192 METAIO_STL::string GetDate()
193 { return m_Date; }
194
195 void SetDate(const char* date)
196 { m_Date=date; }
197
198 void SetName(const char* name)
199 { m_Name=name; }
200
201 void SetDescription(const char* description)
202 { m_Description=description; }
203 METAIO_STL::string GetDescription() const
204 {return m_Description;}
205
206 void SetAuthor(const char* author)
207 { m_Author=author; }
208 METAIO_STL::string GetAuthor() const
209 {return m_Author;}
210
211 long GetOptionId(Option* option);
212
213 /** Return the list of options */
214 const OptionVector & GetOptions()
215 { return m_OptionVector; }
216
217 /** Return the list of parse options */
218 const OptionVector & GetParsedOptions()
219 { return m_ParsedOptionVector; }
220
221 void SetHelpCallBack(void (* newHelpCallBack)(void))
222 { m_HelpCallBack = newHelpCallBack; }
223
224 METAIO_STL::string TypeToString(TypeEnumType type);
225 TypeEnumType StringToType(const char* type);
226
227 void SetVerbose(bool verbose) {m_Verbose = verbose;}
228
229 protected:
230
231 /** Small XML helper */
232 METAIO_STL::string GetXML(const char* buffer,const char* desc,unsigned long pos);
233
234 METAIO_STL::string m_Version;
235 METAIO_STL::string m_Date;
236 METAIO_STL::string m_Name;
237 METAIO_STL::string m_Description;
238 METAIO_STL::string m_Author;
239 METAIO_STL::string m_ExecutableName;
240
241 private:
242
243 void (* m_HelpCallBack)(void);
244
245 OptionVector m_OptionVector;
246 OptionVector m_ParsedOptionVector; // We store the parsed option in
247 // case we have multiple options
248
249 bool m_Verbose;
250
251 }; // end of class
252
253 #if (METAIO_USE_NAMESPACE)
254 };
255 #endif
256
257 #endif