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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309 | /* *****************************************************************
MESQUITE -- The Mesh Quality Improvement Toolkit
Copyright 2008 Sandia National Laboratories. Developed at the
University of Wisconsin--Madison under SNL contract number
624796. The U.S. Government and the University of Wisconsin
retain certain rights to this software.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
(lgpl.txt) along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(2008) [email protected]
***************************************************************** */
/** \file CLArgFlag.hpp
* \brief
* \author Jason Kraftcheck
*/
#ifndef MSQ_CLARG_FLAG_HPP
#define MSQ_CLARG_FLAG_HPP
#include "Mesquite.hpp"
#include "CLArgs.hpp"
#include <string>
#include <vector>
#include <iosfwd>
class CLArgFlag
{
private:
char mFlag;
std::string mDesc;
protected:
CLArgFlag( char pflag, const char* pdesc ) : mFlag( pflag ), mDesc( pdesc ) {}
public:
virtual ~CLArgFlag();
char flag() const
{
return mFlag;
}
const char* desc() const
{
return mDesc.c_str();
}
virtual const CLArgs::ArgIBase* callback() const = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
virtual bool is_toggle() const;<--- Virtual function in base class<--- Virtual function in base class
virtual bool parse( const char* string_value ) const = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
/** Get brief format of option */
virtual std::string brief() const = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
/** Get UNIX man-page formated synposis of flag */
virtual std::string manstr() const = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
virtual bool add_set( int size, const char* const* names );<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class
std::string make_man_string( int count, const char* names[] ) const;
std::string make_man_string( const char* arg_name ) const
{
return make_man_string( 1, &arg_name );
}
std::string make_man_string() const
{
return make_man_string( 0, 0 );
}
std::string make_literal_man_string( int count, const char* literal_args[] ) const;
std::string make_literal_man_string( const char* literal_args ) const
{
return make_literal_man_string( 1, &literal_args );
}
};
class CLArgToggle : public CLArgFlag
{
private:
bool mValue; //!< value to pass to callback when flag is encountered
CLArgs::ToggleArgI* mCallback;
CLArgToggle* mOpposite;
public:
CLArgToggle( char pflag, const char* pdesc, bool value, CLArgs::ToggleArgI* pcallback )
: CLArgFlag( pflag, pdesc ), mValue( value ), mCallback( pcallback ), mOpposite( 0 )
{
}
CLArgToggle( char pflag, const char* pdesc, CLArgToggle* opposite )
: CLArgFlag( pflag, pdesc ), mValue( !opposite->mValue ), mCallback( opposite->mCallback ),
mOpposite( opposite )
{
mOpposite->mOpposite = this;
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool is_toggle() const<--- Function in derived class<--- Function in derived class
{
return true;
}
virtual bool parse( const char* option ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
};
class CLArgString : public CLArgFlag
{
private:
std::string mName;
CLArgs::StringArgI* mCallback;
public:
CLArgString( char fl, const char* name, const char* pdesc, CLArgs::StringArgI* pcallback )
: CLArgFlag( fl, pdesc ), mName( name ), mCallback( pcallback )
{
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool parse( const char* option ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
};
class CLArgLong : public CLArgFlag
{
private:
CLArgs::LongArgI* mCallback;
std::string mName;
public:
CLArgLong( char fl, const char* name, const char* pdesc, CLArgs::LongArgI* pcallback )
: CLArgFlag( fl, pdesc ), mCallback( pcallback ), mName( name )
{
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool parse( const char* option ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
};
class CLArgInt : public CLArgFlag
{
private:
CLArgs::IntArgI* mCallback;
std::string mName;
public:
CLArgInt( char fl, const char* name, const char* pdesc, CLArgs::IntArgI* pcallback )
: CLArgFlag( fl, pdesc ), mCallback( pcallback ), mName( name )
{
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool parse( const char* option ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
};
class CLArgDouble : public CLArgFlag
{
private:
CLArgs::DoubleArgI* mCallback;
std::string mName;
public:
CLArgDouble( char fl, const char* name, const char* pdesc, CLArgs::DoubleArgI* pcallback )
: CLArgFlag( fl, pdesc ), mCallback( pcallback ), mName( name )
{
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool parse( const char* option ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
};
class CLArgIDList : public CLArgFlag
{
public:
CLArgs::IntListArgI* mCallback;
public:
CLArgIDList( char fl, const char* pdesc, CLArgs::IntListArgI* pcallback )
: CLArgFlag( fl, pdesc ), mCallback( pcallback )
{
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool parse( const char* str ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
};
class CLArgListData
{
std::vector< std::vector< std::string > > mSets;
public:
bool add_set( int size, const char* const* names );
bool acceptable_length( unsigned len ) const;
bool accept_any_length() const
{
return mSets.empty();
}
std::string set_string( int set ) const;
std::string brief() const;
std::string manstr( char type_char, const CLArgFlag& f ) const;
};
class CLArgIntList : public CLArgFlag
{
private:
CLArgListData listData;
CLArgs::IntListArgI* mCallback;
public:
CLArgIntList( char fl, const char* pdesc, CLArgs::IntListArgI* pcallback )
: CLArgFlag( fl, pdesc ), mCallback( pcallback )
{
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool parse( const char* option ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
virtual bool add_set( int size, const char* const* names )<--- Function in derived class<--- Function in derived class
{
return listData.add_set( size, names );
}
};
class CLArgDoubleList : public CLArgFlag
{
private:
CLArgListData listData;
std::string mName;
CLArgs::DoubleListArgI* mCallback;
public:
CLArgDoubleList( char fl, const char* pdesc, CLArgs::DoubleListArgI* pcallback )
: CLArgFlag( fl, pdesc ), mCallback( pcallback )
{
}
virtual const CLArgs::ArgIBase* callback() const<--- Function in derived class<--- Function in derived class
{
return mCallback;
}
virtual bool parse( const char* option ) const;<--- Function in derived class<--- Function in derived class
virtual std::string brief() const;<--- Function in derived class<--- Function in derived class
virtual std::string manstr() const;<--- Function in derived class<--- Function in derived class
virtual bool add_set( int size, const char* const* names )<--- Function in derived class<--- Function in derived class
{
return listData.add_set( size, names );
}
};
#endif
|