Main MRPT website > C++ reference for MRPT 1.4.0
XorHandler.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 /******************************************************************************
11  *
12  * file: XorHandler.h
13  *
14  * Copyright (c) 2003, Michael E. Smoot .
15  * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
16  * All rights reverved.
17  *
18  * See the file COPYING in the top directory of this distribution for
19  * more information.
20  *
21  * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  *
29  *****************************************************************************/
30 
31 #ifndef TCLAP_XORHANDLER_H
32 #define TCLAP_XORHANDLER_H
33 
35 #include <string>
36 #include <vector>
37 #include <algorithm>
38 #include <iostream>
39 
40 namespace TCLAP {
41 
42 /**
43  * This class handles lists of Arg's that are to be XOR'd on the command
44  * line. This is used by CmdLine and you shouldn't ever use it.
45  */
47 {
48  protected:
49 
50  /**
51  * The list of of lists of Arg's to be or'd together.
52  */
53  std::vector< std::vector<Arg*> > _orList;
54 
55  public:
56 
57  /**
58  * Constructor. Does nothing.
59  */
60  XorHandler( ) {}
61 
62  /**
63  * Add a list of Arg*'s that will be orred together.
64  * \param ors - list of Arg* that will be xor'd.
65  */
66  void add( std::vector<Arg*>& ors );
67 
68  /**
69  * Checks whether the specified Arg is in one of the xor lists and
70  * if it does match one, returns the size of the xor list that the
71  * Arg matched. If the Arg matches, then it also sets the rest of
72  * the Arg's in the list. You shouldn't use this.
73  * \param a - The Arg to be checked.
74  */
75  int check( const Arg* a );
76 
77  /**
78  * Returns the XOR specific short usage.
79  */
80  std::string shortUsage();
81 
82  /**
83  * Prints the XOR specific long usage.
84  * \param os - Stream to print to.
85  */
86  void printLongUsage(std::ostream& os);
87 
88  /**
89  * Simply checks whether the Arg is contained in one of the arg
90  * lists.
91  * \param a - The Arg to be checked.
92  */
93  bool contains( const Arg* a );
94 
95  std::vector< std::vector<Arg*> >& getXorList();
96 
97 };
98 
99 
100 //////////////////////////////////////////////////////////////////////
101 //BEGIN XOR.cpp
102 //////////////////////////////////////////////////////////////////////
103 inline void XorHandler::add( std::vector<Arg*>& ors )
104 {
105  _orList.push_back( ors );
106 }
107 
108 inline int XorHandler::check( const Arg* a )
109 {
110  // iterate over each XOR list
111  for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
112  {
113  // if the XOR list contains the arg..
114  ArgVectorIterator ait = std::find( _orList[i].begin(),
115  _orList[i].end(), a );
116  if ( ait != _orList[i].end() )
117  {
118  // go through and set each arg that is not a
119  for ( ArgVectorIterator it = _orList[i].begin();
120  it != _orList[i].end();
121  it++ )
122  if ( a != (*it) )
123  (*it)->xorSet();
124 
125  // return the number of required args that have now been set
126  if ( (*ait)->allowMore() )
127  return 0;
128  else
129  return static_cast<int>(_orList[i].size());
130  }
131  }
132 
133  if ( a->isRequired() )
134  return 1;
135  else
136  return 0;
137 }
138 
139 inline bool XorHandler::contains( const Arg* a )
140 {
141  for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
142  for ( ArgVectorIterator it = _orList[i].begin();
143  it != _orList[i].end();
144  it++ )
145  if ( a == (*it) )
146  return true;
147 
148  return false;
149 }
150 
151 inline std::vector< std::vector<Arg*> >& XorHandler::getXorList()
152 {
153  return _orList;
154 }
155 
156 
157 
158 //////////////////////////////////////////////////////////////////////
159 //END XOR.cpp
160 //////////////////////////////////////////////////////////////////////
161 
162 } //namespace TCLAP
163 
164 #endif
std::string shortUsage()
Returns the XOR specific short usage.
std::vector< std::vector< Arg * > > _orList
The list of of lists of Arg&#39;s to be or&#39;d together.
Definition: XorHandler.h:53
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
void printLongUsage(std::ostream &os)
Prints the XOR specific long usage.
void add(std::vector< Arg *> &ors)
Add a list of Arg*&#39;s that will be orred together.
Definition: XorHandler.h:103
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
This class handles lists of Arg&#39;s that are to be XOR&#39;d on the command line.
Definition: XorHandler.h:46
std::vector< std::vector< Arg * > > & getXorList()
Definition: XorHandler.h:151
Definition: Arg.h:44
int check(const Arg *a)
Checks whether the specified Arg is in one of the xor lists and if it does match one, returns the size of the xor list that the Arg matched.
Definition: XorHandler.h:108
A virtual base class that defines the essential data for all arguments.
Definition: Arg.h:51
virtual bool isRequired() const
Indicates whether the argument is required.
Definition: Arg.h:479
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
Definition: Arg.h:355
XorHandler()
Constructor.
Definition: XorHandler.h:60
bool contains(const Arg *a)
Simply checks whether the Arg is contained in one of the arg lists.
Definition: XorHandler.h:139



Page generated by Doxygen 1.8.13 for MRPT 1.4.0 SVN: at Wed Mar 15 00:43:31 UTC 2017