24#ifndef TCLAP_DOC_BOOK_OUTPUT_H
25#define TCLAP_DOC_BOOK_OUTPUT_H
72 static std::string
escapeXml(
const std::string &text) {
74 for (std::string::const_iterator it = text.begin(); it != text.end(); ++it) {
76 case '&': result +=
"&";
break;
77 case '<': result +=
"<";
break;
78 case '>': result +=
">";
break;
79 case '\"': result +=
""";
break;
80 case '\'': result +=
"'";
break;
81 default: result += *it;
break;
88 const std::string
id = arg.
shortID();
89 const std::string label = arg.
getFlag().empty()
92 const std::string::size_type labelStart =
id.find(label);
93 if (labelStart != std::string::npos) {
94 const std::string::size_type open = labelStart + label.size() + 1;
95 const std::string::size_type close =
id.rfind(
'>');
96 if (open <
id.size() &&
id[open] ==
'<' &&
97 close != std::string::npos && close > open)
98 return id.substr(open + 1, close - open - 1);
110 const std::string &x)
const;
111 void removeChar(std::string &s,
char r)
const;
116 if (!(*it)->hasLabel() && (*it)->visibleInHelp())
return true;
127 const std::list<ArgGroup *> &groups,
128 const std::string &programName);
129 static ArgGroup *_findArgGroup(
const std::list<ArgGroup *> &groups,
131 void _printLongEntry(
Arg &arg,
bool forceRequired)
const;
132 void _printAliasTerms(
const Arg &arg)
const;
133 void _printValuePlaceholder(
const Arg &arg)
const;
141inline const char *GroupChoice(
const ArgGroup &group) {
157 if ((*it)->visibleInHelp() && (!labelsOnly || (*it)->hasLabel())) ++visible;
159 std::cout <<
"<group choice='" << internal::GroupChoice(group) <<
"'>\n";
165 if (visible > 1) std::cout <<
"</group>\n";
174 std::cout <<
"<?xml version='1.0'?>\n";
176 <<
"<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.2//EN\"\n";
178 <<
"\t\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\">\n\n";
180 std::cout <<
"<refentry>\n";
182 std::cout <<
"<refmeta>\n";
183 std::cout <<
"<refentrytitle>" <<
escapeXml(progName) <<
"</refentrytitle>\n";
184 std::cout <<
"<manvolnum>1</manvolnum>\n";
185 std::cout <<
"</refmeta>\n";
187 std::cout <<
"<refnamediv>\n";
188 std::cout <<
"<refname>" <<
escapeXml(progName) <<
"</refname>\n";
190 std::cout <<
"</refnamediv>\n";
192 _printSynopsis(_cmd, argSets, progName);
194 std::cout <<
"<refsect1>\n";
195 std::cout <<
"<title>Description</title>\n";
196 std::cout <<
"<para>\n";
198 std::cout <<
"</para>\n";
199 std::cout <<
"</refsect1>\n";
201 std::cout <<
"<refsect1>\n";
202 std::cout <<
"<title>Options</title>\n";
204 std::cout <<
"<variablelist>\n";
206 for (std::list<ArgGroup *>::iterator sit = argSets.begin();
207 sit != argSets.end(); ++sit) {
211 std::cout <<
"</variablelist>\n";
212 std::cout <<
"</refsect1>\n";
214 std::cout <<
"<refsect1>\n";
215 std::cout <<
"<title>Version</title>\n";
216 std::cout <<
"<para>\n";
217 std::cout <<
escapeXml(xversion) <<
'\n';
218 std::cout <<
"</para>\n";
219 std::cout <<
"</refsect1>\n";
221 std::cout <<
"</refentry>" << std::endl;
225 const std::list<ArgGroup *> &groups,
226 const std::string &programName) {
227 std::cout <<
"<refsynopsisdiv>\n";
228 std::cout <<
"<cmdsynopsis>\n";
230 std::cout <<
"<command>" <<
escapeXml(programName) <<
"</command>\n";
232 for (std::list<ArgGroup *>::const_iterator it = groups.begin();
233 it != groups.end(); ++it) {
238 const std::list<Arg *> operands = cmd.
getArgList();
239 std::list<ArgGroup *> shown;
240 for (
ArgListIterator it = operands.begin(); it != operands.end(); ++it) {
242 if (arg->hasLabel() || !arg->visibleInHelp())
continue;
243 ArgGroup *owner = _findArgGroup(groups, arg);
244 if (owner && owner->isExclusive()) {
245 if (std::find(shown.begin(), shown.end(), owner) == shown.end()) {
247 shown.push_back(owner);
254 std::cout <<
"</cmdsynopsis>\n";
255 std::cout <<
"</refsynopsisdiv>\n";
258inline ArgGroup *DocBookOutput::_findArgGroup(
259 const std::list<ArgGroup *> &groups,
const Arg *arg) {
260 for (std::list<ArgGroup *>::const_iterator group = groups.begin();
261 group != groups.
end(); ++group)
262 if (std::find((*group)->begin(), (*group)->end(), arg) !=
269 static_cast<void>(_cmd);
270 std::cout << e.
what() << std::endl;
275 const std::string &x)
const {
277 while ((p = s.find_first_of(r)) != std::string::npos) {
285 while ((p = s.find_first_of(r)) != std::string::npos) {
292 std::string choice =
"opt";
297 std::cout <<
"<arg choice='" << choice <<
'\'';
303 <<
"</replaceable></arg>" << std::endl;
312 _printValuePlaceholder(*a);
314 std::cout <<
"</arg>" << std::endl;
325 _printLongEntry(a, forceRequired);
329inline void DocBookOutput::_printLongEntry(
Arg &a,
bool forceRequired)
const {
332 std::cout <<
"<varlistentry>\n";
335 <<
"</replaceable></term>\n<listitem><para>"
336 <<
escapeXml(desc) <<
"</para></listitem>\n</varlistentry>"
342 std::cout <<
"<term>\n";
343 std::cout <<
"<option>";
345 std::cout <<
"</option>\n";
346 std::cout <<
"</term>\n";
349 std::cout <<
"<term>\n";
350 std::cout <<
"<option>";
353 _printValuePlaceholder(a);
356 std::cout <<
"</option>\n";
357 std::cout <<
"</term>\n";
361 std::cout <<
"<listitem>\n";
362 std::cout <<
"<para>\n";
364 std::cout <<
"</para>\n";
365 std::cout <<
"</listitem>\n";
367 std::cout <<
"</varlistentry>" << std::endl;
370inline void DocBookOutput::_printAliasTerms(
const Arg &a)
const {
371 for (std::vector<ArgAlias>::const_iterator alias = a.aliases().begin();
372 alias != a.aliases().end(); ++alias) {
373 for (
int spelling = 0; spelling < 2; ++spelling) {
374 const std::string &label =
375 spelling == 0 ? alias->flag : alias->name;
376 if (label.empty())
continue;
377 std::cout <<
"<term><option>"
378 <<
escapeXml((spelling == 0 ? a.flagStartString()
379 : a.nameStartString()) +
381 if (a.isValueRequired())
385 std::cout <<
"</option></term>\n";
390inline void DocBookOutput::_printValuePlaceholder(
const Arg &arg)
const {
393 std::cout <<
"<replaceable>" <<
escapeXml(label) <<
"</replaceable>";
A simple class that defines and argument exception.
const char * what() const
Returns the arg id and error text.
ArgGroup is the base class for implementing groups of arguments that are mutually exclusive (it repla...
virtual bool isExclusive() const =0
Returns true if this argument group is exclusive.
Container::const_iterator const_iterator
virtual bool showAsGroup() const
If arguments in this group should show up as grouped in help.
virtual bool isRequired() const =0
Returns true if this argument group is required.
A virtual base class that defines the essential data for all arguments.
static const std::string nameStartString()
const std::string & getFlag() const
Returns the argument flag.
bool isValueRequired() const
Indicates whether a value must be specified for argument.
static char flagStartChar()
const std::string & getName() const
Returns the argument name.
std::string getDescription() const
Returns the argument description.
virtual bool acceptsMultipleValues()
Use by output classes to determine whether an Arg accepts multiple values.
virtual bool hasLabel() const
virtual bool visibleInHelp() const
Returns true if this Arg is visible in the help output.
virtual bool isRequired() const
Indicates whether the argument is required.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
static const std::string flagStartString()
The base class that manages the command line definition and passes along the parsing to the appropria...
virtual std::string getVersion() const =0
Returns the version string.
virtual std::string getMessage() const =0
Returns the message string.
virtual std::string getProgramName() const =0
Returns the program name string.
virtual std::list< ArgGroup * > getArgGroups()=0
Returns the list of ArgGroups.
virtual char getDelimiter() const =0
Returns the delimiter string.
virtual std::list< Arg * > getArgList() const =0
The interface that any output object must implement.
A class that generates DocBook output for usage() method for the given CmdLine and its Args.
void printLongArg(const ArgGroup &it) const
static std::string valueLabel(const Arg &arg)
virtual void version(CmdLineInterface &c)
Prints the version to stdout.
void substituteSpecialChars(std::string &s, char r, const std::string &x) const
Substitutes the char r for string x in string s.
static std::string escapeXml(const std::string &text)
virtual void failure(CmdLineInterface &c, ArgException &e)
Prints (to stderr) an error message, short usage Can be overridden to produce alternative behavior.
void printShortArg(Arg *it, bool required)
void removeChar(std::string &s, char r) const
void printShortGroup(const ArgGroup &group, bool labelsOnly)
static bool hasVisiblePositional(const ArgGroup &group)
virtual void usage(CmdLineInterface &c)
Prints the usage to stdout.
Thrown when TCLAP thinks the program should exit.
int CountVisibleArgs(const ArgGroup &g)
std::list< Arg * >::const_iterator ArgListIterator
Typedef of an Arg list iterator.