VR-Link API Documentation for HLA 1516
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmdUnlabeledMultiArg.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * file: UnlabeledMultiArg.h
5  *
6  * Copyright (c) 2003, Michael E. Smoot.
7  * All rights reverved.
8  *
9  * See the file COPYING in the top directory of this distribution for
10  * more information.
11  *
12  * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18  * DEALINGS IN THE SOFTWARE.
19  *
20  *****************************************************************************/
21 
22 
23 #ifndef DtCmdLine_MULTIPLE_UNLABELED_ARGUMENT_H
24 #define DtCmdLine_MULTIPLE_UNLABELED_ARGUMENT_H
25 
29 
30 #include <string>
31 #include <vector>
32 
33 #include "cmdMultiArg.h"
34 
35 #ifdef DtUSE_UTILITIES_NAMESPACE
36 namespace DtUSE_UTILITIES_NAMESPACE
37 {
38 #endif
39 
40  namespace DtCmdLine {
41 
47  template<class T>
49  class UnlabeledMultiArg : public MultiArg<T>
50  {
51 #ifndef __solaris__
58  using MultiArg<T>::_name;
60 #endif
61 
62  public:
63 
79  UnlabeledMultiArg( const std::string& name,
80  const std::string& desc,
81  const std::string& typeDesc,
82  bool ignoreable = false,
83  Visitor* v = NULL );
100  UnlabeledMultiArg( const std::string& name,
101  const std::string& desc,
102  const std::string& typeDesc,
103  CmdLineInterface& parser,
104  bool ignoreable = false,
105  Visitor* v = NULL );
106 
120  UnlabeledMultiArg( const std::string& name,
121  const std::string& desc,
122  const std::vector<T>& allowed,
123  bool ignoreable = false,
124  Visitor* v = NULL );
125 
140  UnlabeledMultiArg( const std::string& name,
141  const std::string& desc,
142  const std::vector<T>& allowed,
143  CmdLineInterface& parser,
144  bool ignoreable = false,
145  Visitor* v = NULL );
146 
155  virtual bool processArg(int* i, std::vector<std::string>& args);
156 
161  virtual std::string shortID(const std::string& val="val") const;
162 
167  virtual std::string longID(const std::string& val="val") const;
168 
173  virtual bool operator==(const Arg& a) const;
174 
179  virtual void addToList( std::list<Arg*>& argList ) const;
180  };
181 
182  template<class T>
183  UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
184  const std::string& desc,
185  const std::string& typeDesc,
186  bool ignoreable,
187  Visitor* v)
188  : MultiArg<T>("", name, desc, false, typeDesc, v)
189  {
190  _ignoreable = ignoreable;
191  }
192 
193  template<class T>
194  UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
195  const std::string& desc,
196  const std::string& typeDesc,
197  CmdLineInterface& parser,
198  bool ignoreable,
199  Visitor* v)
200  : MultiArg<T>("", name, desc, false, typeDesc, v)
201  {
202  _ignoreable = ignoreable;
203  parser.add( this );
204  }
205 
206 
207  template<class T>
208  UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
209  const std::string& desc,
210  const std::vector<T>& allowed,
211  bool ignoreable,
212  Visitor* v)
213  : MultiArg<T>("", name, desc, false, allowed, v)
214  {
215  _ignoreable = ignoreable;
216  }
217 
218  template<class T>
219  UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name,
220  const std::string& desc,
221  const std::vector<T>& allowed,
222  CmdLineInterface& parser,
223  bool ignoreable,
224  Visitor* v)
225  : MultiArg<T>("", name, desc, false, allowed, v)
226  {
227  _ignoreable = ignoreable;
228  parser.add( this );
229  }
230 
231 
232  template<class T>
233  bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args)
234  {
235 
236  if ( _hasBlanks( args[*i] ) )
237  return false;
238 
240 
241  _extractValue( args[*i] );
242  return true;
243  }
244 
245  template<class T>
246  std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
247  {
248  std::string id = "<" + _typeDesc + "> ...";
249 
250  return id;
251  }
252 
253  template<class T>
254  std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
255  {
256  std::string id = "<" + _typeDesc + "> (accepted multiple times)";
257 
258  return id;
259  }
260 
261  template<class T>
263  {
264  if ( _name == a.getName() || _description == a.getDescription() )
265  return true;
266  else
267  return false;
268  }
269 
270  template<class T>
271  void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
272  {
273  argList.push_back( (Arg*)this );
274  }
275 
276  }
277 
278 #ifdef DtUSE_UTILITIES_NAMESPACE
279 }
280 #endif
281 
282 #endif
A base class that defines the interface for visitors.
Definition: cmdVisitor.h:41
const bool operator==(const DtU128 &lhs, const DtU128 &rhs)
Just like a MultiArg, except that the arguments are unlabeled.
Definition: cmdUnlabeledMultiArg.h:49
bool _ignoreable
Whether this argument can be ignored, if desired.
Definition: cmdArg.h:125
virtual bool processArg(int *i, std::vector< std::string > &args)
Handles the processing of the argument.
Definition: cmdUnlabeledMultiArg.h:233
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 shortID(const std::string &val="val") const
Returns the a short id string.
Definition: cmdUnlabeledMultiArg.h:246
virtual void addToList(std::list< Arg * > &argList) const
Pushes this to back of list rather than front.
Definition: cmdUnlabeledMultiArg.h:271
virtual std::string longID(const std::string &val="val") const
Returns the a long id string.
Definition: cmdUnlabeledMultiArg.h:254
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.
This file declares the class DtCmdLine::MultiArg and several helper classes.
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition: cmdLineInterface.h:52
An argument that allows multiple values of type T to be specified.
Definition: cmdMultiArg.h:59
virtual bool operator==(const Arg &a) const
Opertor ==.
Definition: cmdUnlabeledMultiArg.h:262
UnlabeledMultiArg(const std::string &name, const std::string &desc, const std::string &typeDesc, bool ignoreable=false, Visitor *v=NULL)
Constructor.
Definition: cmdUnlabeledMultiArg.h:183

Document ID: Generated on Tue Aug 10 00:12:31 EDT 2021 from SVN revision 232765
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)