Loading [MathJax]/extensions/tex2jax.js
OGS
BaseLib::TCLAPCustomOutput Class Reference

Detailed Description

TCLAP standard output modified as follows

  • Print arguments in the order of added to Command object

Definition at line 30 of file TCLAPCustomOutput.h.

#include <TCLAPCustomOutput.h>

Inheritance diagram for BaseLib::TCLAPCustomOutput:
[legend]
Collaboration diagram for BaseLib::TCLAPCustomOutput:
[legend]

Public Member Functions

virtual void usage (TCLAP::CmdLineInterface &cmd_)
 
virtual void failure (TCLAP::CmdLineInterface &cmd_, TCLAP::ArgException &e)
 

Protected Member Functions

void shortUsage_ (TCLAP::CmdLineInterface &cmd_, std::ostream &os) const
 
void longUsage_ (TCLAP::CmdLineInterface &cmd_, std::ostream &os) const
 

Member Function Documentation

◆ failure()

void BaseLib::TCLAPCustomOutput::failure ( TCLAP::CmdLineInterface &  cmd_,
TCLAP::ArgException &  e 
)
inlinevirtual

Prints (to stderr) an error message, short usage Can be overridden to produce alternative behavior.

Parameters
cmd_- The CmdLine object the output is generated for.
e- The ArgException that caused the failure.

Definition at line 78 of file TCLAPCustomOutput.h.

80 {
81  std::string progName = cmd_.getProgramName();
82 
83  std::cerr << "PARSE ERROR: " << e.argId() << std::endl
84  << " " << e.error() << std::endl
85  << std::endl;
86 
87  if (cmd_.hasHelpAndVersion())
88  {
89  std::cerr << "Brief USAGE: " << std::endl;
90 
91  shortUsage_(cmd_, std::cerr);
92 
93  std::cerr << std::endl
94  << "For complete USAGE and HELP type: " << std::endl
95  << " " << progName << " --help" << std::endl
96  << std::endl;
97  }
98  else
99  {
100  usage(cmd_);
101  }
102 
103  throw TCLAP::ExitException(1);
104 }
virtual void usage(TCLAP::CmdLineInterface &cmd_)
void shortUsage_(TCLAP::CmdLineInterface &cmd_, std::ostream &os) const

References shortUsage_(), and usage().

◆ longUsage_()

void BaseLib::TCLAPCustomOutput::longUsage_ ( TCLAP::CmdLineInterface &  cmd_,
std::ostream &  os 
) const
inlineprotected

Writes a longer usage message with long and short args, provides descriptions and prints message.

Parameters
cmd_- The CmdLine object the output is generated for.
os- The stream to write the message to.

Definition at line 149 of file TCLAPCustomOutput.h.

151 {
152  std::list<TCLAP::Arg*> argList = cmd_.getArgList();
153  std::string message = cmd_.getMessage();
154  TCLAP::XorHandler xorHandler = cmd_.getXorHandler();
155  std::vector<std::vector<TCLAP::Arg*>> xorList = xorHandler.getXorList();
156 
157  // first the xor
158  for (int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++)
159  {
160  for (TCLAP::ArgVectorIterator it = xorList[i].begin();
161  it != xorList[i].end();
162  it++)
163  {
164  this->spacePrint(os, (*it)->longID(), 75, 3, 3);
165  spacePrint(os, (*it)->getDescription(), 75, 5, 0);
166 
167  if (it + 1 != xorList[i].end())
168  {
169  spacePrint(os, "-- OR --", 75, 9, 0);
170  }
171  }
172  os << std::endl << std::endl;
173  }
174 
175  // then the rest
176  for (auto it = argList.rbegin(); it != argList.rend(); it++)
177  { // here modified
178  if (!xorHandler.contains((*it)))
179  {
180  spacePrint(os, (*it)->longID(), 75, 3, 3);
181  spacePrint(os, (*it)->getDescription(), 75, 5, 0);
182  os << std::endl;
183  }
184  }
185 
186  os << std::endl;
187 
188  spacePrint(os, message, 75, 3, 0);
189 }

Referenced by usage().

◆ shortUsage_()

void BaseLib::TCLAPCustomOutput::shortUsage_ ( TCLAP::CmdLineInterface &  cmd_,
std::ostream &  os 
) const
inlineprotected

Writes a brief usage message with short args.

Parameters
cmd_- The CmdLine object the output is generated for.
os- The stream to write the message to.

Definition at line 106 of file TCLAPCustomOutput.h.

108 {
109  std::list<TCLAP::Arg*> argList = cmd_.getArgList();
110  std::string progName = cmd_.getProgramName();
111  TCLAP::XorHandler xorHandler = cmd_.getXorHandler();
112  std::vector<std::vector<TCLAP::Arg*>> xorList = xorHandler.getXorList();
113 
114  std::string s = progName + " ";
115 
116  // first the xor
117  for (int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++)
118  {
119  s += " {";
120  for (TCLAP::ArgVectorIterator it = xorList[i].begin();
121  it != xorList[i].end();
122  it++)
123  {
124  s += (*it)->shortID() + "|";
125  }
126 
127  s[s.length() - 1] = '}';
128  }
129 
130  // then the rest
131  for (auto it = argList.rbegin(); it != argList.rend(); ++it)
132  { // here modified
133  if (!xorHandler.contains((*it)))
134  {
135  s += " " + (*it)->shortID();
136  }
137  }
138 
139  // if the program name is too long, then adjust the second line offset
140  int secondLineOffset = static_cast<int>(progName.length()) + 2;
141  if (secondLineOffset > 75 / 2)
142  {
143  secondLineOffset = static_cast<int>(75 / 2);
144  }
145 
146  spacePrint(os, s, 75, 3, secondLineOffset);
147 }

Referenced by failure(), and usage().

◆ usage()

void BaseLib::TCLAPCustomOutput::usage ( TCLAP::CmdLineInterface &  cmd_)
inlinevirtual

Prints the usage to stdout. Can be overridden to produce alternative behavior.

Parameters
cmd_- The CmdLine object the output is generated for.

Definition at line 65 of file TCLAPCustomOutput.h.

66 {
67  std::cout << std::endl << "USAGE: " << std::endl << std::endl;
68 
69  shortUsage_(cmd_, std::cout);
70 
71  std::cout << std::endl << std::endl << "Where: " << std::endl << std::endl;
72 
73  longUsage_(cmd_, std::cout);
74 
75  std::cout << std::endl;
76 }
void longUsage_(TCLAP::CmdLineInterface &cmd_, std::ostream &os) const

References longUsage_(), and shortUsage_().

Referenced by failure().


The documentation for this class was generated from the following file: