xor_handler.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef TCLAP_XORHANDLER_H
16 #define TCLAP_XORHANDLER_H
17 
18 #include "arg.hpp"
19 #include <string>
20 #include <vector>
21 #include <algorithm>
22 #include <iostream>
23 
24 namespace ecl {
25 
33 {
34  protected:
35 
39  std::vector< std::vector<Arg*> > _orList;
40 
41  public:
42 
46  XorHandler( ) {}
47 
52  void add( std::vector<Arg*>& ors );
53 
61  int check( const Arg* a );
62 
66  std::string shortUsage();
67 
72  void printLongUsage(std::ostream& os);
73 
79  bool contains( const Arg* a );
80 
81  std::vector< std::vector<Arg*> >& getXorList();
82 
83 };
84 
85 
87 //BEGIN XOR.cpp
89 inline void XorHandler::add( std::vector<Arg*>& ors )
90 {
91  _orList.push_back( ors );
92 }
93 
94 inline int XorHandler::check( const Arg* a )
95 {
96  // iterate over each XOR list
97  for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
98  {
99  // if the XOR list contains the arg..
100  ArgVectorIterator ait = std::find( _orList[i].begin(),
101  _orList[i].end(), a );
102  if ( ait != _orList[i].end() )
103  {
104  // go through and set each arg that is not a
105  for ( ArgVectorIterator it = _orList[i].begin();
106  it != _orList[i].end();
107  it++ )
108  if ( a != (*it) )
109  (*it)->xorSet();
110 
111  // return the number of required args that have now been set
112  if ( (*ait)->allowMore() )
113  return 0;
114  else
115  return static_cast<int>(_orList[i].size());
116  }
117  }
118 
119  if ( a->isRequired() )
120  return 1;
121  else
122  return 0;
123 }
124 
125 inline bool XorHandler::contains( const Arg* a )
126 {
127  for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ )
128  for ( ArgVectorIterator it = _orList[i].begin();
129  it != _orList[i].end();
130  it++ )
131  if ( a == (*it) )
132  return true;
133 
134  return false;
135 }
136 
137 inline std::vector< std::vector<Arg*> >& XorHandler::getXorList()
138 {
139  return _orList;
140 }
141 
142 }; // namespace ecl
143 
144 
145 #endif
int check(const Arg *a)
Definition: xor_handler.hpp:94
TCLAP command line argument parser classes.
virtual bool isRequired() const
Definition: arg.hpp:465
Virtual parent for all the different argument classes.
Definition: arg.hpp:37
std::vector< std::vector< Arg * > > & getXorList()
std::vector< Arg * >::iterator ArgVectorIterator
Definition: arg.hpp:341
TClap class indirectly used by CmdLine for handling xor&#39;d arguments.
Definition: xor_handler.hpp:32
bool contains(const Arg *a)
std::string shortUsage()
void printLongUsage(std::ostream &os)
std::vector< std::vector< Arg * > > _orList
Definition: xor_handler.hpp:39
void add(std::vector< Arg * > &ors)
Definition: xor_handler.hpp:89


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:08