MOAB: Mesh Oriented datABase  (version 5.4.1)
CLArgImpl Class Reference
+ Collaboration diagram for CLArgImpl:

Public Member Functions

 CLArgImpl (const char *progname, const char *brief, const char *desc)
void add_req_arg (const char *name)
void add_opt_arg (const char *name)
bool add_parsed_arg (const char *arg)
bool add_flag (CLArgFlag *flag)
CLArgFlagfind_flag (char flag)
const CLArgFlagfind_flag (char flag) const
bool have_required_args () const
void get_args (std::vector< std::string > &result)
void print_help (std::ostream &stream)
void print_brief_help (std::ostream &stream)
void print_man (std::ostream &stream)
void print_arg_names (std::ostream &stream)

Private Attributes

std::vector< CLArgFlag * > mFlags
std::vector< std::string > reqArgNames
std::vector< std::string > optArgNames
std::vector< std::string > reqArg
std::vector< std::string > optArg
std::string progName
std::string shortDesc
std::string longDesc

Detailed Description

Definition at line 44 of file CLArgs.cpp.


Constructor & Destructor Documentation

CLArgImpl::CLArgImpl ( const char *  progname,
const char *  brief,
const char *  desc 
) [inline]

Definition at line 53 of file CLArgs.cpp.

        : progName( progname ), shortDesc( brief ), longDesc( desc )
    {
    }

Member Function Documentation

bool CLArgImpl::add_flag ( CLArgFlag flag)

Definition at line 97 of file CLArgs.cpp.

References find_flag(), CLArgFlag::flag(), and mFlags.

Referenced by CLArgs::double_flag(), CLArgs::double_list_flag(), CLArgs::id_list_flag(), CLArgs::int_flag(), CLArgs::int_list_flag(), CLArgs::long_flag(), CLArgs::str_flag(), and CLArgs::toggle_flag().

{
    if( find_flag( arg->flag() ) ) return false;

    mFlags.push_back( arg );
    return true;
}
void CLArgImpl::add_opt_arg ( const char *  name) [inline]

Definition at line 63 of file CLArgs.cpp.

References optArgNames.

Referenced by CLArgs::add_optional_arg().

    {
        optArgNames.push_back( name );
    }
bool CLArgImpl::add_parsed_arg ( const char *  arg)

Definition at line 105 of file CLArgs.cpp.

References optArg, optArgNames, reqArg, and reqArgNames.

Referenced by CLArgs::parse_options().

{
    if( reqArg.size() < reqArgNames.size() )
        reqArg.push_back( arg );
    else if( optArg.size() < optArgNames.size() )
        optArg.push_back( arg );
    else
        return false;

    return true;
}
void CLArgImpl::add_req_arg ( const char *  name) [inline]

Definition at line 58 of file CLArgs.cpp.

References reqArgNames.

Referenced by CLArgs::add_required_arg().

    {
        reqArgNames.push_back( name );
    }
CLArgFlag * CLArgImpl::find_flag ( char  flag)

Definition at line 117 of file CLArgs.cpp.

References mFlags.

Referenced by add_flag(), find_flag(), CLArgs::is_flag_available(), CLArgs::limit_list_flag(), and CLArgs::parse_options().

{
    for( unsigned i = 0; i < mFlags.size(); ++i )
        if( mFlags[i]->flag() == flag ) return mFlags[i];
    return 0;
}
const CLArgFlag* CLArgImpl::find_flag ( char  flag) const [inline]

Definition at line 73 of file CLArgs.cpp.

References find_flag().

    {
        return const_cast< CLArgImpl* >( this )->find_flag( flag );
    }
void CLArgImpl::get_args ( std::vector< std::string > &  result) [inline]

Definition at line 83 of file CLArgs.cpp.

References optArg, and reqArg.

Referenced by CLArgs::parse_options().

    {
        result = reqArg;
        result.resize( reqArg.size() + optArg.size() );
        std::copy( optArg.begin(), optArg.end(), result.begin() + reqArg.size() );
    }
bool CLArgImpl::have_required_args ( ) const [inline]

Definition at line 78 of file CLArgs.cpp.

References reqArg, and reqArgNames.

Referenced by CLArgs::parse_options().

    {
        return reqArgNames.size() == reqArg.size();
    }
void CLArgImpl::print_arg_names ( std::ostream &  stream)

Definition at line 232 of file CLArgs.cpp.

References optArgNames, and reqArgNames.

Referenced by print_brief_help(), and print_man().

{
    unsigned i;
    for( i = 0; i < reqArgNames.size(); ++i )
        stream << " <" << reqArgNames[i] << ">";
    for( i = 0; i < optArgNames.size(); ++i )
        stream << " [" << optArgNames[i] << "]";
}
void CLArgImpl::print_brief_help ( std::ostream &  stream)

Definition at line 144 of file CLArgs.cpp.

References HELP_FLAG, MAN_FLAG, mFlags, print_arg_names(), and progName.

Referenced by print_help(), and CLArgs::print_usage().

{
    stream << progName;
    for( unsigned i = 0; i < mFlags.size(); ++i )
    {
        std::string str = mFlags[i]->callback()->brief();
        if( !str.empty() )
        {
            stream << "[-" << mFlags[i]->flag() << ' ' << str << "]";
        }
        else
        {
            str = mFlags[i]->brief();
            if( !str.empty() ) stream << " [" << str << "]";
        }
    }
    print_arg_names( stream );
    stream << std::endl;
    stream << progName << " -" << HELP_FLAG << std::endl;
    stream << progName << " -" << MAN_FLAG << std::endl;
}
void CLArgImpl::print_help ( std::ostream &  stream)

Definition at line 124 of file CLArgs.cpp.

References HELP_FLAG, longDesc, MAN_FLAG, mFlags, print_brief_help(), progName, and shortDesc.

Referenced by CLArgs::print_help().

{
    stream << progName << " : " << shortDesc << std::endl;
    stream << std::endl << longDesc << std::endl << std::endl;
    print_brief_help( stream );
    stream << '-' << HELP_FLAG << " : Print this help text." << std::endl;
    stream << '-' << MAN_FLAG << " : Print man page text to standard output stream." << std::endl;
    stream << "--"
           << " : Treat all subsequent arguments as non-flag arguments." << std::endl;
    for( unsigned i = 0; i < mFlags.size(); ++i )
    {
        stream << '-' << mFlags[i]->flag() << " : " << mFlags[i]->desc();
        std::string extra = mFlags[i]->callback()->desc_append();
        if( !extra.empty() ) stream << " " << extra;
        std::string defval = mFlags[i]->callback()->default_str();
        if( !defval.empty() ) stream << " (default: " << defval << ")";
        stream << std::endl;
    }
}
void CLArgImpl::print_man ( std::ostream &  stream)

Definition at line 166 of file CLArgs.cpp.

References ManPage::begin_bold(), ManPage::begin_hanging_paragraph(), ManPage::begin_indent(), ManPage::begin_manpage(), ManPage::begin_paragraph(), ManPage::begin_section(), ManPage::bold(), ManPage::end_bold(), ManPage::end_indent(), longDesc, mFlags, print_arg_names(), progName, shortDesc, and ManPage::write_text().

Referenced by CLArgs::print_man_page().

{
    ManPage::begin_manpage( stream, progName, 1 );

    ManPage::begin_section( stream, "NAME" );
    ManPage::begin_paragraph( stream );
    stream << progName << " - " << shortDesc << std::endl << std::endl;

    ManPage::begin_section( stream, "SYNOPSIS" );
    ManPage::begin_hanging_paragraph( stream );
    ManPage::bold( stream, progName );
    for( unsigned i = 0; i < mFlags.size(); ++i )
    {
        std::string s = mFlags[i]->callback()->manstr();
        if( !s.empty() )
        {
            stream << '[';
            ManPage::begin_bold( stream );
            stream << '-' << mFlags[i]->flag();
            ManPage::end_bold( stream );
            stream << s << ']';
        }
        else
        {
            s = mFlags[i]->manstr();
            if( !s.empty() ) stream << " [" << s << "]";
        }
    }
    print_arg_names( stream );
    stream << std::endl;
    ManPage::begin_hanging_paragraph( stream );
    ManPage::bold( stream, progName + " -h" );
    ManPage::begin_hanging_paragraph( stream );
    ManPage::bold( stream, progName + " -M" );

    ManPage::begin_section( stream, "DESCRIPTION" );
    ManPage::write_text( stream, false, longDesc );

    ManPage::begin_section( stream, "OPTIONS" );
    for( unsigned i = 0; i < mFlags.size(); ++i )
    {
        std::string s = mFlags[i]->callback()->manstr();
        if( !s.empty() )
        {
            char tmp[] = { '-', mFlags[i]->flag(), ' ', '\0' };
            s          = std::string( tmp ) + s;
        }
        else
        {
            s = mFlags[i]->manstr();
            if( s.empty() ) continue;
        }

        ManPage::begin_hanging_paragraph( stream );
        stream << s;
        ManPage::begin_indent( stream );
        ManPage::begin_paragraph( stream );
        stream << mFlags[i]->desc();
        s = mFlags[i]->callback()->desc_append();
        if( !s.empty() ) stream << " " << s;
        std::string defval = mFlags[i]->callback()->default_str();
        if( !defval.empty() ) stream << " (default: " << defval << ")";
        ManPage::end_indent( stream );
    }
}

Member Data Documentation

std::string CLArgImpl::longDesc [private]

Definition at line 50 of file CLArgs.cpp.

Referenced by print_help(), and print_man().

std::vector< CLArgFlag* > CLArgImpl::mFlags [private]

Definition at line 47 of file CLArgs.cpp.

Referenced by add_flag(), find_flag(), print_brief_help(), print_help(), and print_man().

std::vector< std::string > CLArgImpl::optArg [private]

Definition at line 49 of file CLArgs.cpp.

Referenced by add_parsed_arg(), and get_args().

std::vector< std::string > CLArgImpl::optArgNames [private]

Definition at line 48 of file CLArgs.cpp.

Referenced by add_opt_arg(), add_parsed_arg(), and print_arg_names().

std::string CLArgImpl::progName [private]

Definition at line 50 of file CLArgs.cpp.

Referenced by print_brief_help(), print_help(), and print_man().

std::vector< std::string > CLArgImpl::reqArg [private]

Definition at line 49 of file CLArgs.cpp.

Referenced by add_parsed_arg(), get_args(), and have_required_args().

std::vector< std::string > CLArgImpl::reqArgNames [private]

Definition at line 48 of file CLArgs.cpp.

Referenced by add_parsed_arg(), add_req_arg(), have_required_args(), and print_arg_names().

std::string CLArgImpl::shortDesc [private]

Definition at line 50 of file CLArgs.cpp.

Referenced by print_help(), and print_man().

List of all members.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines