30 #ifndef TCLAP_STDCMDLINEOUTPUT_H 31 #define TCLAP_STDCMDLINEOUTPUT_H 61 StdOutput( std::ostream &desired_out = std::cout ) :
62 m_my_output(desired_out)
118 const std::string& s,
121 int secondLineOffset )
const;
131 m_my_output << std::endl << progName <<
" version: " 132 << version << std::endl << std::endl;
137 m_my_output << std::endl <<
"USAGE: " << std::endl << std::endl;
141 m_my_output << std::endl << std::endl <<
"Where: " << std::endl << std::endl;
154 std::cerr <<
"PARSE ERROR: " << e.
argId() << std::endl
155 <<
" " << e.
error() << std::endl << std::endl;
159 std::cerr <<
"Brief USAGE: " << std::endl;
163 std::cerr << std::endl <<
"For complete USAGE and HELP type: " 164 << std::endl <<
" " << progName <<
" --help" 165 << std::endl << std::endl;
173 std::ostream& )
const 178 std::vector< std::vector<Arg*> > xorList = xorHandler.
getXorList();
180 std::string s = progName +
" ";
183 for (
int i = 0;
static_cast<unsigned int>(i) < xorList.size(); i++ )
187 it != xorList[i].end(); it++ )
188 s += (*it)->shortID() +
"|";
190 s[s.length()-1] =
'}';
195 if ( !xorHandler.
contains( (*it) ) )
196 s +=
" " + (*it)->shortID();
199 int secondLineOffset =
static_cast<int>(progName.length()) + 2;
200 if ( secondLineOffset > 75/2 )
201 secondLineOffset =
static_cast<int>(75/2);
207 std::ostream& os )
const 212 std::vector< std::vector<Arg*> > xorList = xorHandler.
getXorList();
215 for (
int i = 0;
static_cast<unsigned int>(i) < xorList.size(); i++ )
218 it != xorList[i].end();
222 spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
224 if ( it+1 != xorList[i].
end() )
227 os << std::endl << std::endl;
232 if ( !xorHandler.
contains( (*it) ) )
235 spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
245 const std::string& s,
248 int secondLineOffset )
const 250 int len =
static_cast<int>(s.length());
252 if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
254 int allowedLen = maxWidth - indentSpaces;
256 while ( start < len )
259 int stringLen =
std::min( len - start, allowedLen );
262 if ( stringLen == allowedLen )
263 while ( stringLen >= 0 &&
264 s[stringLen+start] !=
' ' &&
265 s[stringLen+start] !=
',' &&
266 s[stringLen+start] !=
'|' 272 if ( stringLen <= 0 )
273 stringLen = allowedLen;
276 for (
int i = 0; i < stringLen; i++ )
277 if ( s[start+i] ==
'\n' )
281 for (
int i = 0; i < indentSpaces; i++ )
287 indentSpaces += secondLineOffset;
290 allowedLen -= secondLineOffset;
293 os << s.substr(start,stringLen) << std::endl;
296 while ( s[stringLen+start] ==
' ' && start < len )
304 for (
int i = 0; i < indentSpaces; i++ )
306 os << s << std::endl;
virtual void usage(CmdLineInterface &c)
Prints the usage to stdout.
virtual XorHandler & getXorHandler()=0
Returns the XorHandler.
The interface that any output object must implement.
EIGEN_STRONG_INLINE iterator end()
virtual void failure(CmdLineInterface &c, ArgException &e)
Prints (to stderr) an error message, short usage Can be overridden to produce alternative behavior...
std::list< Arg * >::iterator ArgListIterator
Typedef of an Arg list iterator.
EIGEN_STRONG_INLINE iterator begin()
This class handles lists of Arg's that are to be XOR'd on the command line.
std::ostream & m_my_output
By JLBC for MRPT.
std::string argId() const
Returns the argument id.
std::vector< std::vector< Arg * > > & getXorList()
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.
virtual std::string & getMessage()=0
Returns the message string.
virtual bool hasHelpAndVersion()=0
Indicates whether or not the help and version switches were created automatically.
virtual std::string & getVersion()=0
Returns the version string.
A class that isolates any output from the CmdLine object so that it may be easily modified...
std::vector< Arg * >::iterator ArgVectorIterator
Typedef of an Arg vector iterator.
void _longUsage(CmdLineInterface &c, std::ostream &os) const
Writes a longer usage message with long and short args, provides descriptions and prints message...
T min(const T v0, const T v1)
StdOutput(std::ostream &desired_out=std::cout)
Prints the usage to stdout.
virtual std::string & getProgramName()=0
Returns the program name string.
virtual void version(CmdLineInterface &c)
Prints the version to stdout.
std::string error() const
Returns the error text.
bool contains(const Arg *a)
Simply checks whether the Arg is contained in one of the arg lists.
void _shortUsage(CmdLineInterface &c, std::ostream &os) const
Writes a brief usage message with short args.
virtual std::list< Arg * > & getArgList()=0
Returns the argList.
A simple class that defines and argument exception.
The base class that manages the command line definition and passes along the parsing to the appropria...