VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmdXorHandler.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * file: XorHandler.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 #ifndef DtCmdLine_XORHANDLER_H
24 #define DtCmdLine_XORHANDLER_H
25 
29 
30 #include "cmdArg.h"
31 #include <string>
32 #include <vector>
33 #include <algorithm>
34 #include <iostream>
35 
36 #ifdef DtUSE_UTILITIES_NAMESPACE
37 namespace DtUSE_UTILITIES_NAMESPACE
38 {
39 #endif
40 
41 namespace DtCmdLine {
42 
47  class XorHandler
49  {
50  protected:
51 
55  std::vector< std::vector<Arg*> > _orList;
56 
57  public:
58 
62  XorHandler( ) {}
63 
68  void add( std::vector<Arg*>& ors );
69 
77  int check( const Arg* a );
78 
82  std::string shortUsage();
83 
88  void printLongUsage(std::ostream& os);
89 
95  bool contains( const Arg* a );
96 
97  std::vector< std::vector<Arg*> >& getXorList();
98 
99  };
100 
101 
103  //BEGIN XOR.cpp
105  inline void XorHandler::add( std::vector<Arg*>& ors )
106  {
107  _orList.push_back( ors );
108  }
109 
110  /*
111  inline std::string XorHandler::shortUsage()
112  {
113  std::string out = "";
114  for ( int i = 0; (unsigned int)i < _orList.size(); i++ )
115  {
116  out += " {";
117  for ( ArgVectorIterator it = _orList[i].begin();
118  it != _orList[i].end(); it++ )
119  out += (*it)->shortID() + "|";
120 
121  out[out.length()-1] = '}';
122  }
123 
124  return out;
125  }
126 
127  inline void XorHandler::printLongUsage( std::ostream& os )
128  {
129  for ( int i = 0; (unsigned int)i < _orList.size(); i++ )
130  {
131  for ( ArgVectorIterator it = _orList[i].begin();
132  it != _orList[i].end();
133  it++ )
134  {
135  spacePrint( os, (*it)->longID(), 75, 3, 3 );
136  spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
137 
138  if ( it+1 != _orList[i].end() )
139  spacePrint(os, "-- OR --", 75, 9);
140  }
141  os << std::endl << std::endl;
142  }
143  }
144  */
145  inline int XorHandler::check( const Arg* a )
146  {
148  int i;
149  for (i = 0; (unsigned int)i < _orList.size(); i++ )
150  {
152  if ( std::find( _orList[i].begin(), _orList[i].end(), a ) !=
153  _orList[i].end() )
154  {
156  for ( ArgVectorIterator it = _orList[i].begin();
157  it != _orList[i].end();
158  it++ )
159  if ( a != (*it) )
160  (*it)->xorSet();
161 
163  return (int)_orList[i].size();
164  }
165  }
166 
167  if ( a->isRequired() )
168  return 1;
169  else
170  return 0;
171  }
172 
173  inline bool XorHandler::contains( const Arg* a )
174  {
175  for ( int i = 0; (unsigned int)i < _orList.size(); i++ )
176  for ( ArgVectorIterator it = _orList[i].begin();
177  it != _orList[i].end();
178  it++ )
179  if ( a == (*it) )
180  return true;
181 
182  return false;
183  }
184 
185  inline std::vector< std::vector<Arg*> >& XorHandler::getXorList()
186  {
187  return _orList;
188  }
189 
190 
191 
193  //END XOR.cpp
195 
196 } //namespace DtCmdLine
197 
198 #ifdef DtUSE_UTILITIES_NAMESPACE
199 }
200 #endif
201 
202 #endif
XorHandler()
Constructor.
Definition: cmdXorHandler.h:62
This file declares classes for VR-Link command line parsing utility.
virtual bool isRequired() const
Indicates whether the argument is required.
Definition: cmdArg.h:490
std::vector< std::vector< Arg * > > _orList
The list of of lists of Arg&#39;s to be or&#39;d together.
Definition: cmdXorHandler.h:55
A virtual base class that defines the essential data for all arguments.
Definition: cmdArg.h:48
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
Definition: cmdArg.h:357

Document ID: Generated on Thu Oct 16 00:12:25 EDT 2025 from SVN revision 280738
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)