24 #ifndef TCLAP_STD_OUTPUT_H 25 #define TCLAP_STD_OUTPUT_H 97 void spacePrint(std::ostream &os,
const std::string &s,
int maxWidth,
98 int indentSpaces,
int secondLineOffset)
const;
105 std::cout << std::endl
106 << progName <<
" version: " << xversion << std::endl
111 std::cout << std::endl <<
"USAGE: " << std::endl << std::endl;
115 std::cout << std::endl << std::endl <<
"Where: " << std::endl << std::endl;
119 std::cout << std::endl;
125 std::cerr <<
"PARSE ERROR: " << e.
argId() << std::endl
126 <<
" " << e.
error() << std::endl
130 std::cerr <<
"Brief USAGE: " << std::endl;
134 std::cerr << std::endl
135 <<
"For complete USAGE and HELP type: " << std::endl
137 <<
"help" << std::endl
149 while ((p = s.find_first_of(r)) != std::string::npos) {
155 int lowa = std::tolower(a);
156 int lowb = std::tolower(b);
196 std::pair<const Arg *, bool> b) {
198 if (!a.second && b.second) {
201 if (a.second && !b.second) {
225 std::ostream &os)
const {
233 std::list<ArgGroup *> exclusiveGroups;
234 std::list<ArgGroup *> nonExclusiveGroups;
235 for (std::list<ArgGroup *>::iterator sit = argSets.begin();
236 sit != argSets.end(); ++sit) {
241 if ((*sit)->isExclusive()) {
242 exclusiveGroups.push_back(*sit);
244 nonExclusiveGroups.push_back(*sit);
252 for (std::list<ArgGroup *>::iterator it = exclusiveGroups.begin();
253 it != exclusiveGroups.end();) {
255 nonExclusiveGroups.push_back(*it);
256 it = exclusiveGroups.erase(it);
264 for (std::list<ArgGroup *>::iterator sit = nonExclusiveGroups.begin();
265 sit != nonExclusiveGroups.end(); ++sit) {
269 switches += (*it)->getFlag();
273 std::sort(switches.begin(), switches.end(),
cmpSwitch);
276 outp <<
" [" << switches <<
']';
279 std::vector<Arg *> longSwitches;
280 for (std::list<ArgGroup *>::iterator sit = nonExclusiveGroups.begin();
281 sit != nonExclusiveGroups.end(); ++sit) {
286 longSwitches.push_back(&arg);
291 std::sort(longSwitches.begin(), longSwitches.end(),
293 for (std::vector<Arg *>::const_iterator it = longSwitches.begin();
294 it != longSwitches.end(); ++it) {
295 outp <<
" [" << (**it).
shortID() <<
']';
299 for (std::list<ArgGroup *>::iterator sit = exclusiveGroups.begin();
300 sit != exclusiveGroups.end(); ++sit) {
302 outp << (argGroup.
isRequired() ?
" {" :
" [");
304 std::vector<Arg *> args;
307 if ((**it).visibleInHelp()) {
313 std::string sep =
"";
314 for (std::vector<Arg *>::const_iterator it = args.begin();
315 it != args.end(); ++it) {
316 outp << sep << (**it).shortID();
324 std::vector<std::pair<const Arg *, bool> > options;
325 for (std::list<ArgGroup *>::iterator sit = nonExclusiveGroups.begin();
326 sit != nonExclusiveGroups.end(); ++sit) {
333 if (visible == 1 && (**sit).isRequired()) {
337 options.push_back(std::make_pair(&arg, required));
343 for (std::vector<std::pair<const Arg *, bool> >::const_iterator it =
345 it != options.end(); ++it) {
346 const Arg &arg = *it->first;
347 bool required = it->second;
348 outp << (required ?
" " :
" [");
350 outp << (required ?
"" :
"]");
354 for (std::list<ArgGroup *>::iterator sit = nonExclusiveGroups.begin();
355 sit != nonExclusiveGroups.end(); ++sit) {
373 int secondLineOffset =
static_cast<int>(_cmd.
getProgramName().length()) + 2;
374 if (secondLineOffset > 75 / 2) secondLineOffset =
static_cast<int>(75 / 2);
376 spacePrint(os, outp.str(), 75, 3, secondLineOffset);
380 std::ostream &os)
const {
384 std::list<Arg *> unlabled;
385 for (std::list<ArgGroup *>::iterator sit = argSets.begin();
386 sit != argSets.end(); ++sit) {
390 bool exclusive = visible > 1 && argGroup.
isExclusive();
391 bool forceRequired = visible == 1 && argGroup.
isRequired();
405 unlabled.push_back(&arg);
409 bool required = arg.
isRequired() || forceRequired;
421 for (
ArgListIterator it = unlabled.begin(); it != unlabled.end(); ++it) {
422 const Arg &arg = **it;
428 if (!message.empty()) {
436 inline void fmtPrintLine(std::ostream &os,
const std::string &s,
int maxWidth,
437 int indentSpaces,
int secondLineOffset) {
438 const std::string splitChars(
" ,|");
439 int maxChars = maxWidth - indentSpaces;
440 std::string indentString(indentSpaces,
' ');
443 int end = s.length();
445 if (end - from <= maxChars) {
447 os << indentString << s.substr(from) << std::endl;
455 while (tooFar - from <= maxChars &&
456 static_cast<std::size_t>(tooFar) != std::string::npos) {
458 tooFar = s.find_first_of(splitChars, to + 1);
464 to = from + maxChars - 1;
472 os << indentString << s.substr(from, to - from) <<
'\n';
475 for (; s[to] ==
' '; to++) {
479 if (secondLineOffset != 0) {
481 indentString.insert(indentString.end(), secondLineOffset,
' ');
482 maxChars -= secondLineOffset;
483 secondLineOffset = 0;
490 int maxWidth,
int indentSpaces,
491 int secondLineOffset)
const {
492 std::stringstream ss(s);
494 std::getline(ss, line);
495 fmtPrintLine(os, line, maxWidth, indentSpaces, secondLineOffset);
496 indentSpaces += secondLineOffset;
498 while (std::getline(ss, line)) {
499 fmtPrintLine(os, line, maxWidth, indentSpaces, 0);
505 #endif // TCLAP_STD_OUTPUT_H 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.
bool IsVisibleShortSwitch(const Arg &arg)
A simple class that defines and argument exception.
bool IsVisibleLongSwitch(const Arg &arg)
std::string argId() const
Returns the argument id.
virtual void usage(CmdLineInterface &c)
Prints the usage to stdout.
Thrown when TCLAP thinks the program should exit.
virtual void version(CmdLineInterface &c)
Prints the version to stdout.
bool cmpSwitch(const char &a, const char &b)
virtual bool hasLabel() const
virtual std::string getMessage() const =0
Returns the message string.
virtual std::string longID(const std::string &valueId="val") const
Returns a long ID for the usage.
void _longUsage(CmdLineInterface &c, std::ostream &os) const
Writes a longer usage message with long and short args, provides descriptions and prints message...
virtual bool isRequired() const
Indicates whether the argument is required.
bool CompareOptions(std::pair< const Arg *, bool > a, std::pair< const Arg *, bool > b)
virtual bool visibleInHelp() const
Returns true if this Arg is visible in the help output.
static const std::string ignoreNameString()
The name used to identify the ignore rest argument.
static const std::string nameStartString()
virtual bool isExclusive() const =0
Returns true if this argument group is exclusive.
Container::iterator iterator
const std::string & getName() const
Returns the argument name.
virtual std::string shortID(const std::string &valueId="val") const
Returns a short ID for the usage.
The base class that manages the command line definition and passes along the parsing to the appropria...
bool isValueRequired() const
Indicates whether a value must be specified for argument.
virtual std::list< ArgGroup * > getArgGroups()=0
Returns the list of ArgGroups.
A class that isolates any output from the CmdLine object so that it may be easily modified...
std::ostringstream ostringstream
int CountVisibleArgs(const ArgGroup &g)
std::string getDescription() const
Returns the argument description.
const std::string & getFlag() const
Returns the argument flag.
void _shortUsage(CmdLineInterface &c, std::ostream &os) const
Writes a brief usage message with short args.
virtual bool hasHelpAndVersion() const =0
Indicates whether or not the help and version switches were created automatically.
virtual std::string getProgramName() const =0
Returns the program name string.
void spacePrint(std::ostream &os, const std::string &s, int maxWidth, int indentSpaces, int secondLineOffset) const
This function inserts line breaks and indents long strings according the params input.
std::list< Arg * >::const_iterator ArgListIterator
Typedef of an Arg list iterator.
bool IsVisibleOption(const Arg &arg)
virtual void failure(CmdLineInterface &c, ArgException &e)
Prints (to stderr) an error message, short usage Can be overridden to produce alternative behavior...
ArgGroup is the base class for implementing groups of arguments that are mutually exclusive (it repla...
std::string error() const
Returns the error text.
void removeChar(std::string &s, char r)
virtual std::string getVersion() const =0
Returns the version string.
bool CompareShortID(const Arg *a, const Arg *b)
static const std::string flagStartString()
The interface that any output object must implement.