VR-Link API Documentation for HLA 1.3
cmdDocBookOutput.h
Go to the documentation of this file.
00001 
00002 /****************************************************************************** 
00003  * 
00004  *  file:  DocBookOutput.h
00005  * 
00006  *  Copyright (c) 2004, Michael E. Smoot
00007  *  All rights reverved.
00008  * 
00009  *  See the file COPYING in the top directory of this distribution for
00010  *  more information.
00011  *  
00012  *  THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 
00013  *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
00014  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
00015  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
00016  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
00017  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
00018  *  DEALINGS IN THE SOFTWARE.  
00019  *  
00020  *****************************************************************************/ 
00021 
00022 #ifndef DtCmdLine_DOCBOOKOUTPUT_H
00023 #define DtCmdLine_DOCBOOKOUTPUT_H
00024  
00028 
00029 #include <string>
00030 #include <vector>
00031 #include <list>
00032 #include <iostream>
00033 #include <algorithm>
00034 
00035 #include "cmdLineInterface.h"
00036 #include "cmdLineOutput.h"
00037 #include "cmdXorHandler.h"
00038 #include "cmdArg.h"
00039 
00040 #ifdef DtUSE_UTILITIES_NAMESPACE
00041 namespace DtUSE_UTILITIES_NAMESPACE
00042 {
00043 #endif
00044 
00045 namespace DtCmdLine {
00046 
00051 
00052    class DocBookOutput : public CmdLineOutput
00053    {
00054 
00055    public:
00056 
00062       virtual void usage(CmdLineInterface& c);
00063 
00069       virtual void version(CmdLineInterface& c);
00070 
00077       virtual void failure(CmdLineInterface& c, 
00078                            ArgException& e );
00079 
00080    protected:
00081 
00088       void substituteSpecialChars( std::string& s, char r, std::string& x );
00089    };
00090 
00091 
00092    inline void DocBookOutput::version(CmdLineInterface& _cmd) 
00093    { 
00094       std::cout << _cmd.getVersion() << std::endl;
00095    }
00096 
00097    inline void DocBookOutput::usage(CmdLineInterface& _cmd ) 
00098    {
00099       std::list<Arg*> argList = _cmd.getArgList();
00100       std::string progName = _cmd.getProgramName();
00101       XorHandler xorHandler = _cmd.getXorHandler();
00102       std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
00103 
00104 
00105       std::cout << "<?xml version='1.0'?>" << std::endl;
00106       std::cout << "<!DOCTYPE book PUBLIC \"-//Norman Walsh//DTD DocBk XML V4.2//EN\"" << std::endl;
00107       std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
00108 
00109       std::cout << "<book>" << std::endl;
00110       std::cout << "<cmdsynopsis>" << std::endl;
00111 
00112       std::cout << "<command>" << progName << "</command>" << std::endl;
00113 
00114       std::string lt = "&lt;"; 
00115       std::string gt = "&gt;"; 
00116 
00118       for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
00119       {
00120          std::cout << "<group>" << std::endl;
00121          for ( ArgVectorIterator it = xorList[i].begin(); 
00122                it != xorList[i].end(); it++ )
00123          {
00124             std::string id = (*it)->shortID();
00125             substituteSpecialChars(id,'<',lt);
00126             substituteSpecialChars(id,'>',gt);
00127             std::cout << "<arg>" << id << "</arg>" << std::endl; 
00128          }
00129 
00130          std::cout << "</group>" << std::endl;
00131       }
00132 
00133       for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
00134          if ( !xorHandler.contains( (*it) ) )
00135          {
00136             std::string id = (*it)->shortID();
00137             substituteSpecialChars(id,'<',lt);
00138             substituteSpecialChars(id,'>',gt);
00139             std::cout << "<arg>" << id << "</arg>" << std::endl; 
00140          }
00141 
00142       std::cout << "</cmdsynopsis>" << std::endl;
00143       std::cout << "</book>" << std::endl;
00144 
00145    }
00146 
00147    inline void DocBookOutput::failure( CmdLineInterface& _cmd,
00148                                        ArgException& e ) 
00149    { 
00150       std::cout << e.what() << std::endl;
00151    }
00152 
00153    inline void DocBookOutput::substituteSpecialChars( std::string& s,
00154                                                       char r,
00155                                                       std::string& x )
00156    {
00157       size_t p;
00158       while ( (p = s.find_first_of(r)) != std::string::npos )
00159       {
00160          s.erase(p,1);
00161          s.insert(p,x);
00162       }
00163    }
00164 
00165 } //namespace DtCmdLine
00166 
00167 #ifdef DtUSE_UTILITIES_NAMESPACE
00168 }     
00169 #endif
00170 
00171 #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)