Main MRPT website > C++ reference
MRPT logo
XorHandler.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 TCLAP_XORHANDLER_H
24 #define TCLAP_XORHANDLER_H
25 
27 #include <string>
28 #include <vector>
29 #include <algorithm>
30 #include <iostream>
31 
32 namespace TCLAP {
33 
34 /**
35  * This class handles lists of Arg's that are to be XOR'd on the command
36  * line. This is used by CmdLine and you shouldn't ever use it.
37  */
39 {
40  protected:
41 
42  /**
43  * The list of of lists of Arg's to be or'd together.
44  */
45  std::vector< std::vector<Arg*> > _orList;
46 
47  public:
48 
49  /**
50  * Constructor. Does nothing.
51  */
52  XorHandler( ) {}
53 
54  /**
55  * Add a list of Arg*'s that will be orred together.
56  * \param ors - list of Arg* that will be xor'd.
57  */
58  void add( std::vector<Arg*>& ors );
59 
60  /**
61  * Checks whether the specified Arg is in one of the xor lists and
62  * if it does match one, returns the size of the xor list that the
63  * Arg matched. If the Arg matches, then it also sets the rest of
64  * the Arg's in the list. You shouldn't use this.
65  * \param a - The Arg to be checked.
66  */
67  int check( const Arg* a );
68 
69  /**
70  * Returns the XOR specific short usage.
71  */
72  std::string shortUsage();
73 
74  /**
75  * Prints the XOR specific long usage.
76  * \param os - Stream to print to.
77  */
78  void printLongUsage(std::ostream& os);
79 
80  /**
81  * Simply checks whether the Arg is contained in one of the arg
82  * lists.
83  * \param a - The Arg to be checked.
84  */
85  bool contains( const Arg* a );
86 
87  std::vector< std::vector<Arg*> >& getXorList();
88 
89 };
90 
91 
92 //////////////////////////////////////////////////////////////////////
93 //BEGIN XOR.cpp
94 //////////////////////////////////////////////////////////////////////
95 inline void XorHandler::add( std::vector<Arg*>& ors )
96 {
97  _orList.push_back( ors );
98 }
99 
100 inline int XorHandler::check( const Arg* a )
101 {
102  // iterate over each XOR list
103  for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
104  {
105  // if the XOR list contains the arg..
106  ArgVectorIterator ait = std::find( _orList[i].begin(),
107  _orList[i].end(), a );
108  if ( ait != _orList[i].end() )
109  {
110  // go through and set each arg that is not a
111  for ( ArgVectorIterator it = _orList[i].begin();
112  it != _orList[i].end();
113  it++ )
114  if ( a != (*it) )
115  (*it)->xorSet();
116 
117  // return the number of required args that have now been set
118  if ( (*ait)->allowMore() )
119  return 0;
120  else
121  return static_cast<int>(_orList[i].size());
122  }
123  }
124 
125  if ( a->isRequired() )
126  return 1;
127  else
128  return 0;
129 }
130 
131 inline bool XorHandler::contains( const Arg* a )
132 {
133  for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
134  for ( ArgVectorIterator it = _orList[i].begin();
135  it != _orList[i].end();
136  it++ )
137  if ( a == (*it) )
138  return true;
139 
140  return false;
141 }
142 
143 inline std::vector< std::vector<Arg*> >& XorHandler::getXorList()
144 {
145  return _orList;
146 }
147 
148 
149 
150 //////////////////////////////////////////////////////////////////////
151 //END XOR.cpp
152 //////////////////////////////////////////////////////////////////////
153 
154 } //namespace TCLAP
155 
156 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013