15 #ifndef TCLAP_STDCMDLINEOUTPUT_H 16 #define TCLAP_STDCMDLINEOUTPUT_H 38 class StdOutput :
public CmdLineOutput
48 virtual void usage(CmdLineInterface& c);
55 virtual void version(CmdLineInterface& c);
63 virtual void failure(CmdLineInterface& c,
73 void _shortUsage( CmdLineInterface& c, std::ostream& os )
const;
81 void _longUsage( CmdLineInterface& c, std::ostream& os )
const;
98 int secondLineOffset )
const;
105 std::string progName = _cmd.getProgramName();
106 std::string interface_version = _cmd.getVersion();
108 std::cout <<
std::endl << progName <<
" version: " 118 std::cout << std::endl << std::endl <<
"Where: " << std::endl <<
std::endl;
129 std::string progName = _cmd.getProgramName();
131 std::cerr <<
"PARSE ERROR: " << e.argId() <<
std::endl 134 if ( _cmd.hasHelpAndVersion() )
136 std::cerr <<
"Brief USAGE: " <<
std::endl;
140 std::cerr << std::endl <<
"For complete USAGE and HELP type: " 141 << std::endl <<
" " << progName <<
" --help" 150 std::ostream& os )
const 152 std::list<Arg*> argList = _cmd.getArgList();
153 std::string progName = _cmd.getProgramName();
154 XorHandler xorHandler = _cmd.getXorHandler();
155 std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
157 std::string s = progName +
" ";
160 for (
int i = 0;
static_cast<unsigned int>(i) < xorList.size(); i++ )
164 it != xorList[i].end(); it++ )
165 s += (*it)->shortID() +
"|";
167 s[s.length()-1] =
'}';
172 if ( !xorHandler.contains( (*it) ) )
173 s +=
" " + (*it)->shortID();
176 int secondLineOffset =
static_cast<int>(progName.length()) + 2;
177 if ( secondLineOffset > 75/2 )
178 secondLineOffset =
static_cast<int>(75/2);
185 std::ostream& os )
const 187 std::list<Arg*> argList = _cmd.getArgList();
188 std::string message = _cmd.getMessage();
189 XorHandler xorHandler = _cmd.getXorHandler();
190 std::vector< std::vector<Arg*> > xorList = xorHandler.getXorList();
193 for (
int i = 0;
static_cast<unsigned int>(i) < xorList.size(); i++ )
196 it != xorList[i].end();
200 spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
202 if ( it+1 != xorList[i].end() )
210 if ( !xorHandler.contains( (*it) ) )
213 spacePrint( os, (*it)->getDescription(), 75, 5, 0 );
223 const std::string& s,
226 int secondLineOffset )
const 228 int len =
static_cast<int>(s.length());
230 if ( (len + indentSpaces > maxWidth) && maxWidth > 0 )
232 int allowedLen = maxWidth - indentSpaces;
234 while ( start < len )
237 int stringLen = std::min<int>( len - start, allowedLen );
240 if ( stringLen == allowedLen )
241 while ( s[stringLen+start] !=
' ' &&
242 s[stringLen+start] !=
',' &&
243 s[stringLen+start] !=
'|' &&
249 if ( stringLen <= 0 )
250 stringLen = allowedLen;
253 for (
int i = 0; i < stringLen; i++ )
254 if ( s[start+i] ==
'\n' )
258 for (
int i = 0; i < indentSpaces; i++ )
264 indentSpaces += secondLineOffset;
267 allowedLen -= secondLineOffset;
270 os << s.substr(start,stringLen) <<
std::endl;
273 while ( s[stringLen+start] ==
' ' && start < len )
281 for (
int i = 0; i < indentSpaces; i++ )
void spacePrint(std::ostream &os, const std::string &s, int maxWidth, int indentSpaces, int secondLineOffset) const
virtual void usage(CmdLineInterface &c)
void _longUsage(CmdLineInterface &c, std::ostream &os) const
std::list< Arg * >::iterator ArgListIterator
void _shortUsage(CmdLineInterface &c, std::ostream &os) const
std::vector< Arg * >::iterator ArgVectorIterator
virtual void version(CmdLineInterface &c)
virtual void failure(CmdLineInterface &c, ArgException &e)