Brief description of class still missing. More...
#include <ApplicationHelp.h>
Classes | |
struct | Example |
struct | Option |
struct | OptionGroup |
Public Member Functions | |
void | addExample (const char *command, const char *comments) |
void | addGroup (const char *title, const char *section) |
void | addOption (const char *option, const char *comments) |
ApplicationHelp () | |
void | exec (const char *group=0) |
std::list< const char * > | sections () |
void | setComments (const char *comments) |
void | setOptionSummary (const char *optionSummary) |
void | setSeeAlso (const char *seeAlso) |
~ApplicationHelp () | |
Static Public Member Functions | |
static std::string | getLine (std::string &text, int maxLength, bool *newLine=0) |
static void | print (std::string p, const std::string &linePrefix="", int indent=0) |
Brief description of class still missing.
Full description of class still missing
Description of constructor still missing
{ }
Description of destructor still missing
{ }
void GpCoreTools::ApplicationHelp::addExample | ( | const char * | command, |
const char * | comments | ||
) |
{ Example o; o.command=command; o.comments=comments; _examples.push_back(o); }
void GpCoreTools::ApplicationHelp::addGroup | ( | const char * | title, |
const char * | section | ||
) |
Referenced by help(), and GpCoreTools::CoreApplication::setHelp().
{ OptionGroup g; g.title=title; g.section=section; _options.push_back(g); }
void GpCoreTools::ApplicationHelp::addOption | ( | const char * | option, |
const char * | comments | ||
) |
Referenced by help(), and GpCoreTools::CoreApplication::setHelp().
{ OptionGroup& g=_options.back(); Option o; o.option=option; o.comments=comments; g.options.push_back(o); }
void GpCoreTools::ApplicationHelp::exec | ( | const char * | group = 0 | ) |
References GpCoreTools::CoreApplication::authors(), GpCoreTools::CoreApplication::instance(), and print().
Referenced by GpCoreTools::CoreApplication::showHelp().
{ if(group) { if(strcmp(group,"html")==0) { execHtml(); return; } } printf("\nUsage: %s %s\n\n", CoreApplication::instance()->applicationName(), _optionSummary.data()); print(_comments, "", 0); if(group) { if(strcmp(group, "all")==0) { for(std::list<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) { print( *it); } } else if(strncmp(group, "no-", 3)==0) { group+=3; for(std::list<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) { if(strcmp(group, it->section.data())!=0) { print( *it); } } } else { for(std::list<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) { if(strcmp(group, it->section.data())==0) { print( *it); } } } } else if(!_options.empty()) { print(_options.front()); if(_options.size()>1) print(_options.back()); } if( !_examples.empty()) { printf("\nExamples:\n"); for(std::list<Example>::iterator it=_examples.begin(); it!=_examples.end(); it++ ) { Example& o=*it; printf("\n"); print(o.command, "", 9); printf("\n"); print(o.comments, "", 2); } } printf("\nSee also:\n"); if( !_seeAlso.empty()) { print(_seeAlso, "", 2); } print("More information at http://www.geopsy.org", "", 2); printf("\nAuthors:\n"); print(CoreApplication::authors()+"\n", "", 2); }
std::string GpCoreTools::ApplicationHelp::getLine | ( | std::string & | text, |
int | maxLength, | ||
bool * | newLine = 0 |
||
) | [static] |
Returns the first line of text. The first line is removed from text. newLine is set to true if a '
' is encountered else it is set to false.
Referenced by print().
{ if(maxLength<10) { std::string line=text; text=""; return line; } std::string line=text; int index=text.find_first_of("\n"); if(index>-1) { if(index<=maxLength) { text=text.substr(index+1); line=line.substr(0, index); if(newLine) *newLine=true; return line; } } if((int)text.length()<=maxLength) { text.clear(); if(newLine) *newLine=false; return line; } line=line.substr(0, maxLength); index=line.find_last_of(" "); if(maxLength>20 && index>maxLength-20) { text=text.substr(index+1); // skip the blank line=line.substr(0, index); if(newLine) *newLine=false; return line; } text=text.substr(0, maxLength); if(newLine) *newLine=false; return line; }
void GpCoreTools::ApplicationHelp::print | ( | std::string | p, |
const std::string & | linePrefix = "" , |
||
int | indent = 0 |
||
) | [static] |
Print string p to stdout. Prefix linePrefix and indent indent are inserted before each line. app.terminalCols() is the maximum number of characters per line.
References getLine(), and GpCoreTools::CoreApplication::instance().
Referenced by exec().
{ std::string line; std::string mainIndentStr, customIndentStr; bool newLine=true; mainIndentStr.assign(indent, ' '); while(!p.empty()) { bool lastNewLine=newLine; line=getLine(p, CoreApplication::instance()->terminalCols()-indent-linePrefix.size()-customIndentStr.size(), &newLine); printf("%s%s%s%s\n", linePrefix.data(), mainIndentStr.data(), customIndentStr.data(), line.data()); if(lastNewLine && !newLine) { // Set indent by the position of the last double space customIndentStr=getCustomIndent(line); newLine=false; } else if(newLine) { customIndentStr=""; } } }
std::list< const char * > GpCoreTools::ApplicationHelp::sections | ( | ) |
Returns the list of sections
Referenced by GpCoreTools::CoreApplication::setHelp().
{ std::list<const char *> l; for(std::list<OptionGroup>::iterator it=_options.begin(); it!=_options.end(); it++ ) { l.push_back(it->section.data()); } if( !_examples.empty()) { l.push_back("examples"); } return l; }
void GpCoreTools::ApplicationHelp::setComments | ( | const char * | comments | ) | [inline] |
Referenced by help().
{_comments=comments;}
void GpCoreTools::ApplicationHelp::setOptionSummary | ( | const char * | optionSummary | ) | [inline] |
Referenced by help().
{_optionSummary=optionSummary;}
void GpCoreTools::ApplicationHelp::setSeeAlso | ( | const char * | seeAlso | ) | [inline] |
{_seeAlso=seeAlso;}