VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmdDocBookOutput.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * file: DocBookOutput.h
5  *
6  * Copyright (c) 2004, Michael E. Smoot
7  * All rights reverved.
8  *
9  * See the file COPYING in the top directory of this distribution for
10  * more information.
11  *
12  * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
13  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18  * DEALINGS IN THE SOFTWARE.
19  *
20  *****************************************************************************/
21 
22 #ifndef DtCmdLine_DOCBOOKOUTPUT_H
23 #define DtCmdLine_DOCBOOKOUTPUT_H
24 
28 
29 #include <string>
30 #include <vector>
31 #include <list>
32 #include <iostream>
33 #include <algorithm>
34 
35 #include "cmdLineInterface.h"
36 #include "cmdLineOutput.h"
37 #include "cmdXorHandler.h"
38 #include "cmdArg.h"
39 
40 #ifdef DtUSE_UTILITIES_NAMESPACE
41 namespace DtUSE_UTILITIES_NAMESPACE
42 {
43 #endif
44 
45 namespace DtCmdLine {
46 
51  class DocBookOutput : public CmdLineOutput
53  {
54 
55  public:
56 
62  virtual void usage(CmdLineInterface& c);
63 
69  virtual void version(CmdLineInterface& c);
70 
77  virtual void failure(CmdLineInterface& c,
78  ArgException& e );
79 
80  protected:
81 
88  void substituteSpecialChars( std::string& s, char r, std::string& x );
89  };
90 
91 
92  inline void DocBookOutput::version(CmdLineInterface& _cmd)
93  {
94  std::cout << _cmd.getVersion() << std::endl;
95  }
96 
97  inline void DocBookOutput::usage(CmdLineInterface& _cmd )
98  {
99  std::list<Arg*> argList = _cmd.getArgList();
100  std::string progName = _cmd.getProgramName();
101  XorHandler xorHandler = _cmd.getXorHandler();
102  std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
103 
104 
105  std::cout << "<?xml version='1.0'?>" << std::endl;
106  std::cout << "<!DOCTYPE book PUBLIC \"-//Norman Walsh//DTD DocBk XML V4.2//EN\"" << std::endl;
107  std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
108 
109  std::cout << "<book>" << std::endl;
110  std::cout << "<cmdsynopsis>" << std::endl;
111 
112  std::cout << "<command>" << progName << "</command>" << std::endl;
113 
114  std::string lt = "&lt;";
115  std::string gt = "&gt;";
116 
118  for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
119  {
120  std::cout << "<group>" << std::endl;
121  for ( ArgVectorIterator it = xorList[i].begin();
122  it != xorList[i].end(); it++ )
123  {
124  std::string id = (*it)->shortID();
125  substituteSpecialChars(id,'<',lt);
126  substituteSpecialChars(id,'>',gt);
127  std::cout << "<arg>" << id << "</arg>" << std::endl;
128  }
129 
130  std::cout << "</group>" << std::endl;
131  }
132 
133  for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
134  if ( !xorHandler.contains( (*it) ) )
135  {
136  std::string id = (*it)->shortID();
137  substituteSpecialChars(id,'<',lt);
138  substituteSpecialChars(id,'>',gt);
139  std::cout << "<arg>" << id << "</arg>" << std::endl;
140  }
141 
142  std::cout << "</cmdsynopsis>" << std::endl;
143  std::cout << "</book>" << std::endl;
144 
145  }
146 
147  inline void DocBookOutput::failure( CmdLineInterface& _cmd,
148  ArgException& e )
149  {
150  std::cout << e.what() << std::endl;
151  }
152 
153  inline void DocBookOutput::substituteSpecialChars( std::string& s,
154  char r,
155  std::string& x )
156  {
157  size_t p;
158  while ( (p = s.find_first_of(r)) != std::string::npos )
159  {
160  s.erase(p,1);
161  s.insert(p,x);
162  }
163  }
164 
165 } //namespace DtCmdLine
166 
167 #ifdef DtUSE_UTILITIES_NAMESPACE
168 }
169 #endif
170 
171 #endif
This file declares the class DtCmdLine::CmdLineOutput.
std::vector< std::vector< Arg * > > & getXorList()
Definition: cmdXorHandler.h:185
This file declares classes for VR-Link command line parsing utility.
This file declares the class DtCmdLine::CmdLineInterface.
This class handles lists of Arg&#39;s that are to be XOR&#39;d on the command line.
Definition: cmdXorHandler.h:48
virtual std::list< Arg * > & getArgList()=0
Returns the argList.
A simple class that defines and argument exception.
Definition: cmdArgException.h:43
virtual XorHandler & getXorHandler()=0
Returns the XorHandler.
virtual std::string & getProgramName()=0
Returns the program name string.
This file declares the class DtCmdLine::XorHandler.
bool contains(const Arg *a)
Simply checks whether the Arg is contained in one of the arg lists.
Definition: cmdXorHandler.h:173
virtual std::string & getVersion()=0
Returns the version string.
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
Definition: cmdArg.h:342
The base class that manages the command line definition and passes along the parsing to the appropria...
Definition: cmdLineInterface.h:52
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
Definition: cmdArg.h:347
const char * what() const
Returns the arg id and error text.
Definition: cmdArgException.h:87

Document ID: Generated on Mon Apr 25 03:39:01 EDT 2022 from SVN revision 242502
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)