docbook_output.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef TCLAP_DOCBOOKOUTPUT_H
16 #define TCLAP_DOCBOOKOUTPUT_H
17 
18 #include <string>
19 #include <vector>
20 #include <list>
21 #include <iostream>
22 #include <algorithm>
23 
24 #include "cmd_line_interface.hpp"
25 #include "cmd_line_output.hpp"
26 #include "xor_handler.hpp"
27 #include "arg.hpp"
28 
29 namespace ecl {
30 
38 {
39 
40  public:
41 
47  virtual void usage(CmdLineInterface& c);
48 
54  virtual void version(CmdLineInterface& c);
55 
62  virtual void failure(CmdLineInterface& c,
63  ArgException& e );
64 
65  protected:
66 
73  void substituteSpecialChars( std::string& s, char r, std::string& x );
74  void removeChar( std::string& s, char r);
75 
76  void printShortArg(Arg* it);
77  void printLongArg(Arg* it);
78 };
79 
80 
82 {
83  std::cout << _cmd.getVersion() << std::endl;
84 }
85 
87 {
88  std::list<Arg*> argList = _cmd.getArgList();
89  std::string progName = _cmd.getProgramName();
90  std::string version = _cmd.getVersion();
91  XorHandler xorHandler = _cmd.getXorHandler();
92  std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
93 
94 
95  std::cout << "<?xml version='1.0'?>" << std::endl;
96  std::cout << "<!DOCTYPE book PUBLIC \"-//Norman Walsh//DTD DocBk XML V4.2//EN\"" << std::endl;
97  std::cout << "\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">" << std::endl << std::endl;
98 
99  std::cout << "<book>" << std::endl;
100  std::cout << "<refentry>" << std::endl;
101 
102  std::cout << "<refmeta>" << std::endl;
103  std::cout << "<refentrytitle>" << std::endl;
104  std::cout << progName << std::endl;
105  std::cout << "</refentrytitle>" << std::endl;
106  std::cout << "<manvolnum>1</manvolnum>" << std::endl;
107  std::cout << "</refmeta>" << std::endl;
108 
109  std::cout << "<refnamediv>" << std::endl;
110  std::cout << "<refname>" << std::endl;
111  std::cout << progName << std::endl;
112  std::cout << "</refname>" << std::endl;
113  std::cout << "</refnamediv>" << std::endl;
114 
115  std::cout << "<cmdsynopsis>" << std::endl;
116 
117  std::cout << "<command>" << progName << "</command>" << std::endl;
118 
119  // xor
120  for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
121  {
122  std::cout << "<group choice='req'>" << std::endl;
123  for ( ArgVectorIterator it = xorList[i].begin();
124  it != xorList[i].end(); it++ )
125  printShortArg((*it));
126 
127  std::cout << "</group>" << std::endl;
128  }
129 
130  // rest of args
131  for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
132  if ( !xorHandler.contains( (*it) ) )
133  printShortArg((*it));
134 
135  std::cout << "</cmdsynopsis>" << std::endl;
136 
137  std::cout << "<refsect1>" << std::endl;
138  std::cout << "<title>Description</title>" << std::endl;
139  std::cout << "<para>" << std::endl;
140  std::cout << _cmd.getMessage() << std::endl;
141  std::cout << "</para>" << std::endl;
142  std::cout << "</refsect1>" << std::endl;
143 
144  std::cout << "<refsect1>" << std::endl;
145  std::cout << "<title>Options</title>" << std::endl;
146  std::cout << "<para>" << std::endl;
147  std::cout << "<itemizedlist>" << std::endl;
148  // xor
149  for ( int i = 0; (unsigned int)i < xorList.size(); i++ )
150  {
151  std::cout << "<itemizedlist>" << std::endl;
152  size_t xlen = xorList.size() - 1;
153  size_t xcount = 0;
154  for ( ArgVectorIterator it = xorList[i].begin();
155  it != xorList[i].end(); it++, xcount++ )
156  {
157  printLongArg((*it));
158  if ( xcount < xlen )
159  std::cout << "<listitem>OR</listitem>" << std::endl;
160  }
161 
162  std::cout << "</itemizedlist>" << std::endl;
163  }
164 
165  // rest of args
166  for (ArgListIterator it = argList.begin(); it != argList.end(); it++)
167  if ( !xorHandler.contains( (*it) ) )
168  printLongArg((*it));
169 
170  std::cout << "</itemizedlist>" << std::endl;
171  std::cout << "</para>" << std::endl;
172  std::cout << "</refsect1>" << std::endl;
173 
174  std::cout << "<refsect1>" << std::endl;
175  std::cout << "<title>Version</title>" << std::endl;
176  std::cout << "<para>" << std::endl;
177  std::cout << version << std::endl;
178  std::cout << "</para>" << std::endl;
179  std::cout << "</refsect1>" << std::endl;
180 
181  std::cout << "</refentry>" << std::endl;
182  std::cout << "</book>" << std::endl;
183 
184 }
185 
187  ArgException& e )
188 {
189  std::cout << e.what() << std::endl;
190 }
191 
192 inline void DocBookOutput::substituteSpecialChars( std::string& s,
193  char r,
194  std::string& x )
195 {
196  size_t p;
197  while ( (p = s.find_first_of(r)) != std::string::npos )
198  {
199  s.erase(p,1);
200  s.insert(p,x);
201  }
202 }
203 
204 inline void DocBookOutput::removeChar( std::string& s, char r)
205 {
206  size_t p;
207  while ( (p = s.find_first_of(r)) != std::string::npos )
208  {
209  s.erase(p,1);
210  }
211 }
212 
214 {
215  std::string lt = "&lt;";
216  std::string gt = "&gt;";
217 
218  std::string id = a->shortID();
219  substituteSpecialChars(id,'<',lt);
220  substituteSpecialChars(id,'>',gt);
221  removeChar(id,'[');
222  removeChar(id,']');
223 
224  std::string choice = "opt";
225  if ( a->isRequired() )
226  choice = "req";
227 
228  std::string repeat = "norepeat";
229  if ( a->acceptsMultipleValues() )
230  repeat = "repeat";
231 
232 
233 
234  std::cout << "<arg choice='" << choice
235  << "' repeat='" << repeat << "'>"
236  << id << "</arg>" << std::endl;
237 
238 }
239 
241 {
242  std::string lt = "&lt;";
243  std::string gt = "&gt;";
244 
245  std::string id = a->longID();
246  substituteSpecialChars(id,'<',lt);
247  substituteSpecialChars(id,'>',gt);
248  removeChar(id,'[');
249  removeChar(id,']');
250 
251  std::string desc = a->getDescription();
252  substituteSpecialChars(desc,'<',lt);
253  substituteSpecialChars(desc,'>',gt);
254 
255  std::cout << "<simplelist>" << std::endl;
256 
257  std::cout << "<member>" << std::endl;
258  std::cout << id << std::endl;
259  std::cout << "</member>" << std::endl;
260 
261  std::cout << "<member>" << std::endl;
262  std::cout << desc << std::endl;
263  std::cout << "</member>" << std::endl;
264 
265  std::cout << "</simplelist>" << std::endl;
266 }
267 
268 }; // namespace ecl
269 
270 #endif
void printShortArg(Arg *it)
virtual void version(CmdLineInterface &c)
TCLAP command line argument parser classes.
virtual std::string shortID(const std::string &valueId="val") const
Definition: arg.hpp:396
virtual bool isRequired() const
Definition: arg.hpp:465
virtual std::string & getVersion()=0
virtual void usage(CmdLineInterface &c)
void printLongArg(Arg *it)
Tclap class indirectly used by children for standardising outputs.
Managing interface for The base class that manages the command line definition and passes along the p...
Virtual parent for all the different argument classes.
Definition: arg.hpp:37
std::list< Arg * >::iterator ArgListIterator
Definition: arg.hpp:336
virtual std::list< Arg * > & getArgList()=0
virtual void failure(CmdLineInterface &c, ArgException &e)
std::vector< std::vector< Arg * > > & getXorList()
void removeChar(std::string &s, char r)
Defines the exception that is thrown whenever a command line is created and parsed.
virtual XorHandler & getXorHandler()=0
std::vector< Arg * >::iterator ArgVectorIterator
Definition: arg.hpp:341
virtual std::string & getMessage()=0
TCLAP command line argument parser classes.
TCLAP command line argument parser classes.
TClap class indirectly used by CmdLine for handling xor&#39;d arguments.
Definition: xor_handler.hpp:32
virtual std::string longID(const std::string &valueId="val") const
Definition: arg.hpp:417
std::string getDescription() const
Definition: arg.hpp:448
bool contains(const Arg *a)
TCLAP command line argument parser classes.
TClap class used for generating docbook output.
virtual bool acceptsMultipleValues()
Definition: arg.hpp:568
void substituteSpecialChars(std::string &s, char r, std::string &x)
const char * what() const
virtual std::string & getProgramName()=0


ecl_command_line
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:08