VR-Link API Documentation for HLA 1.3
cmdXorHandler.h
Go to the documentation of this file.
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 DtCmdLine_XORHANDLER_H
00024 #define DtCmdLine_XORHANDLER_H
00025  
00029 
00030 #include "cmdArg.h"
00031 #include <string>
00032 #include <vector>
00033 #include <algorithm>
00034 #include <iostream>
00035 
00036 #ifdef DtUSE_UTILITIES_NAMESPACE
00037 namespace DtUSE_UTILITIES_NAMESPACE
00038 {
00039 #endif
00040 
00041 namespace DtCmdLine {
00042 
00047 
00048    class XorHandler
00049    {
00050    protected:
00051 
00055       std::vector< std::vector<Arg*> > _orList;
00056 
00057    public:
00058 
00062       XorHandler( ) {}
00063 
00068       void add( std::vector<Arg*>& ors );
00069 
00077       int check( const Arg* a );
00078 
00082       std::string shortUsage();
00083 
00088       void printLongUsage(std::ostream& os);
00089 
00095       bool contains( const Arg* a );
00096 
00097       std::vector< std::vector<Arg*> >& getXorList(); 
00098 
00099    };
00100 
00101 
00103    //BEGIN XOR.cpp
00105    inline void XorHandler::add( std::vector<Arg*>& ors )
00106    { 
00107       _orList.push_back( ors );
00108    }
00109 
00110    /*
00111       inline std::string XorHandler::shortUsage()
00112       {
00113       std::string out = "";
00114       for ( int i = 0; (unsigned int)i < _orList.size(); i++ )
00115       {
00116       out += " {";
00117       for ( ArgVectorIterator it = _orList[i].begin(); 
00118       it != _orList[i].end(); it++ )
00119       out += (*it)->shortID() + "|";
00120 
00121       out[out.length()-1] = '}';
00122       }
00123 
00124       return out;
00125       }
00126 
00127       inline void XorHandler::printLongUsage( std::ostream& os )
00128       {
00129       for ( int i = 0; (unsigned int)i < _orList.size(); i++ )
00130       {
00131       for ( ArgVectorIterator it = _orList[i].begin(); 
00132       it != _orList[i].end(); 
00133       it++ )
00134       {
00135       spacePrint( os, (*it)->longID(), 75, 3, 3 );
00136       spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
00137 
00138       if ( it+1 != _orList[i].end() )
00139       spacePrint(os, "-- OR --", 75, 9);
00140       }
00141       os << std::endl << std::endl;
00142       }
00143       }
00144       */
00145    inline int XorHandler::check( const Arg* a ) 
00146    {
00148       int i;
00149       for (i = 0; (unsigned int)i < _orList.size(); i++ )
00150       {
00152          if ( std::find( _orList[i].begin(), _orList[i].end(), a ) != 
00153               _orList[i].end() )
00154          {
00156             for ( ArgVectorIterator it = _orList[i].begin(); 
00157                   it != _orList[i].end(); 
00158                   it++ )   
00159                if ( a != (*it) )
00160                   (*it)->xorSet();
00161 
00163             return (int)_orList[i].size();
00164          }
00165       }
00166 
00167       if ( a->isRequired() )
00168          return 1;
00169       else
00170          return 0;
00171    }
00172 
00173    inline bool XorHandler::contains( const Arg* a )
00174    {
00175       for ( int i = 0; (unsigned int)i < _orList.size(); i++ )
00176          for ( ArgVectorIterator it = _orList[i].begin(); 
00177                it != _orList[i].end(); 
00178                it++ )   
00179             if ( a == (*it) )
00180                return true;
00181 
00182       return false;
00183    }
00184 
00185    inline std::vector< std::vector<Arg*> >& XorHandler::getXorList() 
00186    {
00187       return _orList;
00188    }
00189 
00190 
00191 
00193    //END XOR.cpp
00195 
00196 } //namespace DtCmdLine
00197 
00198 #ifdef DtUSE_UTILITIES_NAMESPACE
00199 }     
00200 #endif
00201 
00202 #endif 

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)