⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncbiargs.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        string str_extra = "NOTE:  Specify ";        if ( m_nExtra ) {            str_extra += "at least ";            str_extra += NStr::UIntToString(m_nExtra);            if (m_nExtraOpt != kMax_UInt) {                str_extra += ", and ";            }        }        if (m_nExtraOpt != kMax_UInt) {            str_extra += "no more than ";            str_extra += NStr::UIntToString(m_nExtra + m_nExtraOpt);        }        str_extra += " arguments in \"....\"";        s_PrintCommentBody(arr, str_extra, m_UsageWidth);    }    if ( m_nExtra  &&  !opt.empty() ) {        arr.push_back(kEmptyStr);        arr.push_back("OPTIONAL ARGUMENTS");        arr.splice(arr.end(), opt);    }    str += NStr::Join(arr, "\n");    str += "\n";    return str;}//////////////////////////////////////////////////////////////////////////////////////////////////////////////// CArgAllow:://   CArgAllow_Symbols:://   CArgAllow_String:://   CArgAllow_Strings:://   CArgAllow_Integers:://   CArgAllow_Doubles::///////////////////////////////////////////////////////////  CArgAllow:://CArgAllow::~CArgAllow(void){    return;}/////////////////////////////////////////////////////////  s_IsSymbol() -- check if the symbol belongs to one of standard character//                  classes from <ctype.h>, or to user-defined symbol set//inline bool s_IsAllowedSymbol(unsigned char                   ch,                              CArgAllow_Symbols::ESymbolClass symbol_class,                              const string&                   symbol_set){    switch ( symbol_class ) {    case CArgAllow_Symbols::eAlnum:   return isalnum(ch) != 0;    case CArgAllow_Symbols::eAlpha:   return isalpha(ch) != 0;    case CArgAllow_Symbols::eCntrl:   return iscntrl(ch) != 0;    case CArgAllow_Symbols::eDigit:   return isdigit(ch) != 0;    case CArgAllow_Symbols::eGraph:   return isgraph(ch) != 0;    case CArgAllow_Symbols::eLower:   return islower(ch) != 0;    case CArgAllow_Symbols::ePrint:   return isprint(ch) != 0;    case CArgAllow_Symbols::ePunct:   return ispunct(ch) != 0;    case CArgAllow_Symbols::eSpace:   return isspace(ch) != 0;    case CArgAllow_Symbols::eUpper:   return isupper(ch) != 0;    case CArgAllow_Symbols::eXdigit:  return isxdigit(ch) != 0;    case CArgAllow_Symbols::eUser:        return symbol_set.find_first_of(ch) != NPOS;    }    _TROUBLE;  return false;}static string s_GetUsageSymbol(CArgAllow_Symbols::ESymbolClass symbol_class,                               const string&                   symbol_set){    switch ( symbol_class ) {    case CArgAllow_Symbols::eAlnum:   return "alphanumeric";    case CArgAllow_Symbols::eAlpha:   return "alphabetic";    case CArgAllow_Symbols::eCntrl:   return "control symbol";    case CArgAllow_Symbols::eDigit:   return "decimal";    case CArgAllow_Symbols::eGraph:   return "graphical symbol";    case CArgAllow_Symbols::eLower:   return "lower case";    case CArgAllow_Symbols::ePrint:   return "printable";    case CArgAllow_Symbols::ePunct:   return "punctuation";    case CArgAllow_Symbols::eSpace:   return "space";    case CArgAllow_Symbols::eUpper:   return "upper case";    case CArgAllow_Symbols::eXdigit:  return "hexadecimal";    case CArgAllow_Symbols::eUser:        return "'" + NStr::PrintableString(symbol_set) + "'";    }    _TROUBLE;  return kEmptyStr;}/////////////////////////////////////////////////////////  CArgAllow_Symbols:://CArgAllow_Symbols::CArgAllow_Symbols(ESymbolClass symbol_class)    : CArgAllow(),      m_SymbolClass(symbol_class){    return;}CArgAllow_Symbols::CArgAllow_Symbols(const string& symbol_set)    : CArgAllow(),      m_SymbolClass(eUser), m_SymbolSet(symbol_set){    return;}bool CArgAllow_Symbols::Verify(const string& value) const{    if (value.length() != 1)        return false;    return s_IsAllowedSymbol(value[0], m_SymbolClass, m_SymbolSet);}string CArgAllow_Symbols::GetUsage(void) const{    return "one symbol: " + s_GetUsageSymbol(m_SymbolClass, m_SymbolSet);}CArgAllow_Symbols::~CArgAllow_Symbols(void){    return;}/////////////////////////////////////////////////////////  CArgAllow_String:://CArgAllow_String::CArgAllow_String(ESymbolClass symbol_class)    : CArgAllow_Symbols(symbol_class){    return;}CArgAllow_String::CArgAllow_String(const string& symbol_set)    : CArgAllow_Symbols(symbol_set){    return;}bool CArgAllow_String::Verify(const string& value) const{    for (string::const_iterator it = value.begin();  it != value.end(); ++it) {        if ( !s_IsAllowedSymbol(*it, m_SymbolClass, m_SymbolSet) )            return false;    }    return true;}string CArgAllow_String::GetUsage(void) const{    return "to contain only symbols: " +        s_GetUsageSymbol(m_SymbolClass, m_SymbolSet);}/////////////////////////////////////////////////////////  CArgAllow_Strings:://CArgAllow_Strings::CArgAllow_Strings(void)    : CArgAllow(){    return;}CArgAllow_Strings* CArgAllow_Strings::Allow(const string& value){    m_Strings.insert(value);    return this;}bool CArgAllow_Strings::Verify(const string& value) const{    return (m_Strings.find(value) != m_Strings.end());}string CArgAllow_Strings::GetUsage(void) const{    if ( m_Strings.empty() ) {        return "ERROR:  Constraint with no values allowed(?!)";    }    string str;    set<string>::const_iterator it = m_Strings.begin();    for (;;) {        str += "`";        str += *it;        ++it;        if (it == m_Strings.end()) {            str += "'";            break;        }        str += "', ";    }    return str;}CArgAllow_Strings::~CArgAllow_Strings(void){    return;}/////////////////////////////////////////////////////////  CArgAllow_Integers:://CArgAllow_Integers::CArgAllow_Integers(int x_min, int x_max)    : CArgAllow(){    if (x_min <= x_max) {        m_Min = x_min;        m_Max = x_max;    } else {        m_Min = x_max;        m_Max = x_min;    }}bool CArgAllow_Integers::Verify(const string& value) const{    int val = NStr::StringToInt(value);    return (m_Min <= val  &&  val <= m_Max);}string CArgAllow_Integers::GetUsage(void) const{    return NStr::IntToString(m_Min) + ".." + NStr::IntToString(m_Max);}/////////////////////////////////////////////////////////  CArgAllow_Doubles:://CArgAllow_Doubles::CArgAllow_Doubles(double x_min, double x_max)    : CArgAllow(){    if (x_min <= x_max) {        m_Min = x_min;        m_Max = x_max;    } else {        m_Min = x_max;        m_Max = x_min;    }}bool CArgAllow_Doubles::Verify(const string& value) const{    double val = NStr::StringToDouble(value);    return (m_Min <= val  &&  val <= m_Max);}string CArgAllow_Doubles::GetUsage(void) const{    return NStr::DoubleToString(m_Min) + ".." + NStr::DoubleToString(m_Max);}END_NCBI_SCOPE/* * =========================================================================== * $Log: ncbiargs.cpp,v $ * Revision 1000.1  2004/06/01 19:08:48  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.48 * * Revision 1.48  2004/05/14 13:59:26  gorelenk * Added include of ncbi_pch.hpp * * Revision 1.47  2003/09/16 19:51:36  rsmith * move CreateArgs definition to avoid new Codewarrior compiler bug. * * Revision 1.46  2003/05/28 18:01:58  kuznets * Changed program help (usage section). Now prints flags as optional argument in [] * * Revision 1.45  2003/05/16 16:00:41  vakatov * + CArgs::IsEmpty() * + CArgDescriptions::PrintUsageIfNoArgs() * * Revision 1.44  2003/03/10 18:57:07  kuznets * iterate->ITERATE * * Revision 1.43  2003/02/10 18:07:07  kuznets * Fixed problem with mandatory extra args * * Revision 1.42  2002/11/04 21:29:04  grichenk * Fixed usage of const CRef<> and CRef<> constructor * * Revision 1.41  2002/10/03 14:44:34  ucko * Tweak the interfaces to NStr::Wrap* to avoid publicly depending on * kEmptyStr, removing the need for fWrap_UsePrefix1 in the process; also * drop fWrap_FavorPunct, as WrapList should be a better choice for such * situations. * * Revision 1.40  2002/10/02 20:16:46  ucko * Take advantage of the new wrapping-related code in NStr:: when * formatting usage messages. * Move the note about "...." up if there are required extra arguments. * * Revision 1.39  2002/08/08 18:37:32  gouriano * corrected CArgDescriptions::Delete * * Revision 1.38  2002/07/15 18:17:23  gouriano * renamed CNcbiException and its descendents * * Revision 1.37  2002/07/11 14:18:25  gouriano * exceptions replaced by CNcbiException-type ones * * Revision 1.36  2002/06/13 20:41:57  ucko * Improve usage formatting for long choice lists. * * Revision 1.35  2002/04/24 04:02:45  vakatov * Do not use #NO_INCLASS_TMPL anymore -- apparently all modern * compilers seem to be supporting in-class template methods. * * Revision 1.34  2002/04/11 21:08:01  ivanov * CVS log moved to end of the file * * Revision 1.33  2001/07/24 23:33:14  vakatov * Use _DEBUG_ARG() to get rid of the compiler warnings in Release mode * * Revision 1.32  2001/03/16 16:40:18  vakatov * Moved <corelib/ncbi_limits.h> to the header * * Revision 1.31  2001/01/22 23:07:14  vakatov * CArgValue::AsInteger() to return "int" (rather than "long") * * Revision 1.30  2001/01/03 17:45:35  vakatov * + <ncbi_limits.h> * * Revision 1.29  2000/12/24 00:13:00  vakatov * Radically revamped NCBIARGS. * Introduced optional key and posit. args without default value. * Added new arg.value constraint classes. * Passed flags to be detected by HasValue() rather than AsBoolean. * Simplified constraints on the number of mandatory and optional extra args. * Improved USAGE info and diagnostic messages. Etc... * * Revision 1.26  2000/11/29 00:18:13  vakatov * s_ProcessArgument() -- avoid nested quotes in the exception message * * Revision 1.25  2000/11/29 00:07:28  vakatov * Flag and key args not to be sorted in alphabetical order by default; see * "usage_sort_args" in SetUsageContext(). * * Revision 1.24  2000/11/24 23:28:33  vakatov * CArgValue::  added CloseFile() * CArgValue::  get rid of "change_mode" feature in AsInput/OutputFile() * * Revision 1.23  2000/11/22 22:04:31  vakatov * Added special flag "-h" and special exception CArgHelpException to * force USAGE printout in a standard manner * * Revision 1.22  2000/11/17 22:04:30  vakatov * CArgDescriptions::  Switch the order of optional args in methods * AddOptionalKey() and AddPlain(). Also, enforce the default value to * match arg. description (and constraints, if any) at all times. * * Revision 1.21  2000/11/13 20:31:07  vakatov * Wrote new test, fixed multiple bugs, ugly "features", and the USAGE. * * Revision 1.20  2000/11/09 21:02:58  vakatov * USAGE to show default value for optional arguments * * Revision 1.19  2000/11/08 17:48:37  butanaev * There was no minus in optional key synopsis, fixed. * * Revision 1.18  2000/11/01 20:37:15  vasilche * Fixed detection of heap objects. * Removed ECanDelete enum and related constructors. * Disabled sync_with_stdio ad the beginning of AppMain. * * Revision 1.17  2000/10/30 22:26:29  vakatov * Get rid of "s_IsAvailableExtra()" -- not used anymore * * Revision 1.16  2000/10/20 22:33:37  vakatov * CArgAllow_Integers, CArgAllow_Doubles:  swap min/max, if necessary * * Revision 1.15  2000/10/20 22:23:28  vakatov * CArgAllow_Strings customization;  MSVC++ fixes;  better diagnostic messages * * Revision 1.14  2000/10/20 20:25:55  vakatov * Redesigned/reimplemented the user-defined arg.value constraints * mechanism (CArgAllow-related classes and methods). +Generic clean-up. * * Revision 1.13  2000/10/13 16:26:30  vasilche * Added heuristic for detection of CObject allocation in heap. * * Revision 1.12  2000/10/11 21:03:49  vakatov * Cleanup to avoid 64-bit to 32-bit values truncation, etc. * (reported by Forte6 Patch 109490-01) * * Revision 1.11  2000/10/06 21:56:45  butanaev * Added Allow() function. Added classes CArgAllowValue, CArgAllowIntInterval. * * Revision 1.10  2000/09/29 17:10:54  butanaev * Got rid of IsDefaultValue(), added IsProvided(). * * Revision 1.9  2000/09/28 21:00:14  butanaev * fPreOpen with opposite meaning took over fDelayOpen. * IsDefaultValue() added which returns true if no * value for an optional argument was provided in cmd. line. * * * Revision 1.7  2000/09/28 19:38:00  butanaev * stdin and stdout now referenced as '-' Example: ./test_ncbiargs -if - -of - * * Revision 1.6  2000/09/22 21:25:59  butanaev * Fixed bug in handling default arg values. * * Revision 1.5  2000/09/19 21:19:58  butanaev * Added possibility to change file open mode on the fly * * Revision 1.4  2000/09/18 19:39:02  vasilche * Added CreateArgs() from CNcbiArguments. * * Revision 1.3  2000/09/12 15:00:30  butanaev * Fixed bug with stdin, stdout caused compilation errors on IRIX. * * Revision 1.2  2000/09/06 18:56:04  butanaev * Added stdin, stdout support. Fixed bug in PrintOut. * * Revision 1.1  2000/08/31 23:54:49  vakatov * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -