VR-Link API Documentation for HLA 1.3
 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  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
A base class that defines the interface for visitors.
Definition: cmdVisitor.h:41
const bool operator==(const DtU128 &lhs, const DtU128 &rhs)
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition: cmdArg.h:125
UnlabeledValueArg(const std::string &name, const std::string &desc, T value, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
UnlabeledValueArg constructor.
Definition: cmdUnlabeledValueArg.h:223
std::string getDescription() const
Returns the argument description.
Definition: cmdArg.h:458
const std::string & getName() const
Returns the argument name.
Definition: cmdArg.h:473
virtual std::string longID(const std::string &val="val") const
Overrides longID for specific behavior.
Definition: cmdUnlabeledValueArg.h:312
The basic labeled argument that parses a value.
Definition: cmdValueArg.h:63
virtual void addToList(std::list< Arg * > &argList) const
Instead of pushing to the front of list, push to the back.
Definition: cmdUnlabeledValueArg.h:335
A virtual base class that defines the essential data for all arguments.
Definition: cmdArg.h:48
virtual void add(Arg &a)=0
Adds an argument to the list of arguments to be parsed.
The basic unlabeled argument that parses a value.
Definition: cmdUnlabeledValueArg.h:51
virtual std::string shortID(const std::string &val="val") const
Overrides shortID for specific behavior.
Definition: cmdUnlabeledValueArg.h:301
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition: cmdLineInterface.h:52
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
Definition: cmdUnlabeledValueArg.h:281
virtual bool operator==(const Arg &a) const
Overrides operator== for specific behavior.
Definition: cmdUnlabeledValueArg.h:326
This file declares the class DtCmdLine::ValueArg.

Document ID: Generated on Thu Sep 19 02:12:35 EDT 2024 from SVN revision 269601
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)