UniversalIndentGUI 1.2.0
|
00001 00002 /****************************************************************************** 00003 * 00004 * file: XorHandler.h 00005 * 00006 * Copyright (c) 2003, Michael E. Smoot . 00007 * Copyright (c) 2004, Michael E. Smoot, Daniel Aarno. 00008 * All rights reverved. 00009 * 00010 * See the file COPYING in the top directory of this distribution for 00011 * more information. 00012 * 00013 * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 00014 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00015 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00016 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00017 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00018 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00019 * DEALINGS IN THE SOFTWARE. 00020 * 00021 *****************************************************************************/ 00022 00023 #ifndef TCLAP_XORHANDLER_H 00024 #define TCLAP_XORHANDLER_H 00025 00026 #include <tclap/Arg.h> 00027 #include <string> 00028 #include <vector> 00029 #include <algorithm> 00030 #include <iostream> 00031 00032 namespace TCLAP { 00033 00038 class XorHandler 00039 { 00040 protected: 00041 00045 std::vector< std::vector<Arg*> > _orList; 00046 00047 public: 00048 00052 XorHandler( ) {} 00053 00058 void add( std::vector<Arg*>& ors ); 00059 00067 int check( const Arg* a ); 00068 00072 std::string shortUsage(); 00073 00078 void printLongUsage(std::ostream& os); 00079 00085 bool contains( const Arg* a ); 00086 00087 std::vector< std::vector<Arg*> >& getXorList(); 00088 00089 }; 00090 00091 00093 //BEGIN XOR.cpp 00095 inline void XorHandler::add( std::vector<Arg*>& ors ) 00096 { 00097 _orList.push_back( ors ); 00098 } 00099 00100 inline int XorHandler::check( const Arg* a ) 00101 { 00102 // iterate over each XOR list 00103 for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ ) 00104 { 00105 // if the XOR list contains the arg.. 00106 ArgVectorIterator ait = std::find( _orList[i].begin(), 00107 _orList[i].end(), a ); 00108 if ( ait != _orList[i].end() ) 00109 { 00110 // go through and set each arg that is not a 00111 for ( ArgVectorIterator it = _orList[i].begin(); 00112 it != _orList[i].end(); 00113 it++ ) 00114 if ( a != (*it) ) 00115 (*it)->xorSet(); 00116 00117 // return the number of required args that have now been set 00118 if ( (*ait)->allowMore() ) 00119 return 0; 00120 else 00121 return static_cast<int>(_orList[i].size()); 00122 } 00123 } 00124 00125 if ( a->isRequired() ) 00126 return 1; 00127 else 00128 return 0; 00129 } 00130 00131 inline bool XorHandler::contains( const Arg* a ) 00132 { 00133 for ( int i = 0; static_cast<unsigned int>(i) < _orList.size(); i++ ) 00134 for ( ArgVectorIterator it = _orList[i].begin(); 00135 it != _orList[i].end(); 00136 it++ ) 00137 if ( a == (*it) ) 00138 return true; 00139 00140 return false; 00141 } 00142 00143 inline std::vector< std::vector<Arg*> >& XorHandler::getXorList() 00144 { 00145 return _orList; 00146 } 00147 00148 00149 00151 //END XOR.cpp 00153 00154 } //namespace TCLAP 00155 00156 #endif