VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmdUnlabeledValueArg.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * file: UnlabeledValueArg.h
5  *
6  * Copyright (c) 2003, Michael E. Smoot .
7  * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
8  * All rights reverved.
9  *
10  * See the file COPYING in the top directory of this distribution for
11  * more information.
12  *
13  * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
14  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19  * DEALINGS IN THE SOFTWARE.
20  *
21  *****************************************************************************/
22 
23 
24 #ifndef DtCmdLine_UNLABELED_VALUE_ARGUMENT_H
25 #define DtCmdLine_UNLABELED_VALUE_ARGUMENT_H
26 
30 
31 #include <string>
32 #include <vector>
33 
34 #include "cmdValueArg.h"
35 
36 #ifdef DtUSE_UTILITIES_NAMESPACE
37 namespace DtUSE_UTILITIES_NAMESPACE
38 {
39 #endif
40 
41  namespace DtCmdLine {
42 
49 
50  template<class T>
51  class UnlabeledValueArg : public ValueArg<T>
52  {
53 
60  using ValueArg<T>::_name;
63 
64  public:
65 
89  UnlabeledValueArg( const std::string& name,
90  const std::string& desc,
91  T value,
92  const std::string& typeDesc,
93  bool ignoreable = false,
94  Visitor* v = NULL);
95 
120  UnlabeledValueArg( const std::string& name,
121  const std::string& desc,
122  T value,
123  const std::string& typeDesc,
124  CmdLineInterface& parser,
125  bool ignoreable = false,
126  Visitor* v = NULL );
127 
149  UnlabeledValueArg( const std::string& name,
150  const std::string& desc,
151  T value,
152  const std::vector<T>& allowed,
153  bool ignoreable = false,
154  Visitor* v = NULL );
155 
156 
179  UnlabeledValueArg( const std::string& name,
180  const std::string& desc,
181  T value,
182  const std::vector<T>& allowed,
183  CmdLineInterface& parser,
184  bool ignoreable = false,
185  Visitor* v = NULL);
186 
195  virtual bool processArg(int* i, std::vector<std::string>& args);
196 
200  virtual std::string shortID(const std::string& val="val") const;
201 
205  virtual std::string longID(const std::string& val="val") const;
206 
210  virtual bool operator==(const Arg& a ) const;
211 
216  virtual void addToList( std::list<Arg*>& argList ) const;
217  };
218 
222  template<class T>
223  UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
224  const std::string& desc,
225  T val,
226  const std::string& typeDesc,
227  bool ignoreable,
228  Visitor* v)
229  : ValueArg<T>("", name, desc, true, val, typeDesc, v)
230  {
231  _ignoreable = ignoreable;
232  }
233 
234  template<class T>
235  UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
236  const std::string& desc,
237  T val,
238  const std::string& typeDesc,
239  CmdLineInterface& parser,
240  bool ignoreable,
241  Visitor* v)
242  : ValueArg<T>("", name, desc, true, val, typeDesc, v)
243  {
244  _ignoreable = ignoreable;
245  parser.add( this );
246  }
247 
251  template<class T>
252  UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
253  const std::string& desc,
254  T val,
255  const std::vector<T>& allowed,
256  bool ignoreable,
257  Visitor* v)
258  : ValueArg<T>("", name, desc, true, val, allowed, v)
259  {
260  _ignoreable = ignoreable;
261  }
262 
263  template<class T>
264  UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name,
265  const std::string& desc,
266  T val,
267  const std::vector<T>& allowed,
268  CmdLineInterface& parser,
269  bool ignoreable,
270  Visitor* v)
271  : ValueArg<T>("", name, desc, true, val, allowed, v)
272  {
273  _ignoreable = ignoreable;
274  parser.add( this );
275  }
276 
280  template<class T>
281  bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args)
282  {
283 
284  if ( _alreadySet )
285  return false;
286 
287  if ( _hasBlanks( args[*i] ) )
288  return false;
289 
291 
292  _extractValue( args[*i] );
293  _alreadySet = true;
294  return true;
295  }
296 
300  template<class T>
301  std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
302  {
303  std::string id = "<" + _typeDesc + ">";
304 
305  return id;
306  }
307 
311  template<class T>
312  std::string UnlabeledValueArg<T>::longID(const std::string& val) const
313  {
317  std::string id = "<" + _typeDesc + ">";
318 
319  return id;
320  }
321 
325  template<class T>
326  bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
327  {
328  if ( _name == a.getName() || _description == a.getDescription() )
329  return true;
330  else
331  return false;
332  }
333 
334  template<class T>
335  void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
336  {
337  argList.push_back( (Arg*)this );
338  }
339 
340  }
341 
342 #ifdef DtUSE_UTILITIES_NAMESPACE
343 }
344 #endif
345 
346 #endif

Document ID: Generated on Tue Mar 1 02:56:17 EST 2016 from SVN revision 162687
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)