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 
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

Document ID: Generated on Mon Jun 22 21:18:40 EDT 2020 from SVN revision 213785
Copyright © 2005-2018 MAK Technologies. All Rights Reserved (www.mak.com)