📄 ncbiargs.hpp
字号:
////// CArgAllow_Symbols --////// Define constraint to describe exactly one symbol.////// Argument to be exactly one symbol from the specified set of symbols.////// Examples:/// - To allow only symbols 'a', 'b' and 'Z' for argument "MyArg":/// SetConstraint("MyArg", new CArgAllow_Symbols("abZ"))/// - To allow only printable symbols (according to "isprint()" from <ctype.h>):/// SetConstraint("MyArg", new CArgAllow_Symbols(CArgAllow_Symbols::ePrint))class NCBI_XNCBI_EXPORT CArgAllow_Symbols : public CArgAllow{public: /// Symbol class for defining sets of characters. /// /// Symbol character classes patterned after those defined in <ctype.h>. enum ESymbolClass { // Standard character class from <ctype.h>: isalpha(), isdigit(), etc. eAlnum, ///< Alphanumeric characters eAlpha, ///< Alphabet characters eCntrl, ///< Control characters eDigit, ///< Digit characters eGraph, ///< Graphical characters eLower, ///< Lowercase characters ePrint, ///< Printable characters ePunct, ///< Punctuation characters eSpace, ///< Space characters eUpper, ///< Uppercase characters eXdigit, ///< Hexadecimal characters eUser ///< User defined characters using constructor with string& }; /// Constructor. CArgAllow_Symbols(ESymbolClass symbol_class); /// Constructor for user defined eUser class. CArgAllow_Symbols(const string& symbol_set);protected: /// Verify if specified value is allowed. virtual bool Verify(const string& value) const; /// Get usage information. virtual string GetUsage(void) const; /// Protected destructor. virtual ~CArgAllow_Symbols(void); ESymbolClass m_SymbolClass; ///< Symbol class for constraint string m_SymbolSet; ///< Use if m_SymbolClass == eUser};/////////////////////////////////////////////////////////////////////////////////// CArgAllow_String --////// Define constraint to describe string argument.////// Argument to be a string containing only allowed symbols.////// Examples:/// - To allow string containing only symbols 'a', 'b' and 'Z' for arg MyArg:/// SetConstraint("MyArg", new CArgAllow_String("abZ"))/// - To allow only numeric symbols (according to "isdigit()" from <ctype.h>):/// SetConstraint("MyArg", new CArgAllow_String(CArgAllow_String::eDigit))class NCBI_XNCBI_EXPORT CArgAllow_String : public CArgAllow_Symbols{public: /// Constructor. CArgAllow_String(ESymbolClass symbol_class); /// Constructor for user defined eUser class. CArgAllow_String(const string& symbol_set);protected: /// Verify if specified value is allowed. virtual bool Verify(const string& value) const; /// Get usage information. virtual string GetUsage(void) const;};/////////////////////////////////////////////////////////////////////////////////// CArgAllow_Strings --////// Define constraint to describe set of string values.////// Argument to have only particular string values. Use the Allow() method to/// add the allowed string values, which can be daisy-chained.////// Examples:/// - SetConstraint("a", (new CArgAllow_Strings)->/// Allow("foo")->Allow("bar")->Allow("etc"))/// - You can use "operator,()" to shorten the notation:/// SetConstraint("b", &(*new CArgAllow_Strings, "foo", "bar", "etc"))class NCBI_XNCBI_EXPORT CArgAllow_Strings : public CArgAllow{public: /// Constructor. CArgAllow_Strings(void); /// Add allowed string values. CArgAllow_Strings* Allow(const string& value); /// Short notation operator for adding allowed string values. /// @sa /// Allow() CArgAllow_Strings& operator,(const string& value) { return *Allow(value); }protected: /// Verify if specified value is allowed. virtual bool Verify(const string& value) const; /// Get usage information. virtual string GetUsage(void) const; /// Protected destructor. virtual ~CArgAllow_Strings(void);private: set<string> m_Strings; ///< Set of allowed string values};/////////////////////////////////////////////////////////////////////////////////// CArgAllow_Integers --////// Define constraint to describe range of integer values.////// Argument to have only integer values falling within given interval.////// Example:/// - SetConstraint("a2", new CArgAllow_Integers(-3, 34))class NCBI_XNCBI_EXPORT CArgAllow_Integers : public CArgAllow{public: /// Constructor specifying range of allowed integer values. CArgAllow_Integers(int x_min, int x_max);protected: /// Verify if specified value is allowed. virtual bool Verify(const string& value) const; /// Get usage information. virtual string GetUsage(void) const;private: int m_Min; ///< Minimum value of range int m_Max; ///< Maximum value of range };/////////////////////////////////////////////////////////////////////////////////// CArgAllow_Doubles --////// Define constraint to describe range of double values.////// Argument to have only double values falling within given interval.////// Example:/// - SetConstraint("a2", new CArgAllow_Doubles(0.01, 0.99))class NCBI_XNCBI_EXPORT CArgAllow_Doubles : public CArgAllow{public: /// Constructor specifying range of allowed double values. CArgAllow_Doubles(double x_min, double x_max);protected: /// Verify if specified value is allowed. virtual bool Verify(const string& value) const; /// Get usage information. virtual string GetUsage(void) const;private: double m_Min; ///< Minimum value of range double m_Max; ///< Maximum value of range };/////////////////////////////////////////////////////////////////////////////////// CArgDesc --////// Base class for the description of various types of argument.////// This was a pre-declaration; in MSVC, a predeclaration here causes a heap/// corruption on termination because this class's virtual destructor isn't/// defined at the moment the compiler instantiates the destructor of/// AutoPtr<CArgDesc>.class CArgDesc{public: /// Constructor. CArgDesc(const string& name, ///< Argument name const string& comment ///< Argument description ); /// Destructor. virtual ~CArgDesc(void); /// Get argument name. const string& GetName (void) const { return m_Name; } /// Get arument description. const string& GetComment(void) const { return m_Comment; } /// Get usage synopis. virtual string GetUsageSynopsis(bool name_only = false) const = 0; /// Get usage comment attribute. virtual string GetUsageCommentAttr(void) const = 0; /// Process argument with specified value. virtual CArgValue* ProcessArgument(const string& value) const = 0; /// Process argument default. virtual CArgValue* ProcessDefault(void) const = 0; /// Verify argument default value. virtual void VerifyDefault (void) const; /// Set argument constraint. virtual void SetConstraint(CArgAllow* constraint); /// Get argument constraint. virtual const CArgAllow* GetConstraint(void) const; /// Get usage constraint. string GetUsageConstraint(void) const;private: string m_Name; ///< Argument name string m_Comment; ///< Argument description};END_NCBI_SCOPE/* @} *//* * =========================================================================== * $Log: ncbiargs.hpp,v $ * Revision 1000.0 2003/10/29 15:02:47 gouriano * PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.33 * * Revision 1.33 2003/07/30 16:14:01 siyan * Added explicit documentation for operators () and !() * * Revision 1.32 2003/07/24 11:48:02 siyan * Made @sa text indentation consistent. * * Revision 1.31 2003/07/10 14:59:09 siyan * Documentation changes. * * Revision 1.30 2003/05/28 18:00:11 kuznets * CArgDescription::PrintUsage declared virtual to enable custom help screens * * Revision 1.29 2003/05/16 16:00:39 vakatov * + CArgs::IsEmpty() * + CArgDescriptions::PrintUsageIfNoArgs() * * Revision 1.28 2003/03/31 13:36:39 siyan * Added doxygen support * * Revision 1.27 2003/02/10 18:06:15 kuznets * Fixed problem with mandatory extra args * * Revision 1.26 2002/12/26 12:51:41 dicuccio * Fixed some minor niggling errors with export specifiers in the wrong places. * * Revision 1.25 2002/12/18 22:53:21 dicuccio * Added export specifier for building DLLs in windows. Added global list of * all such specifiers in mswin_exports.hpp, included through ncbistl.hpp * * Revision 1.24 2002/07/15 18:17:50 gouriano * renamed CNcbiException and its descendents * * Revision 1.23 2002/07/11 14:17:53 gouriano * exceptions replaced by CNcbiException-type ones * * Revision 1.22 2002/04/24 04:02:43 vakatov * Do not use #NO_INCLASS_TMPL anymore -- apparently all modern * compilers seem to be supporting in-class template methods. * * Revision 1.21 2002/04/11 20:39:16 ivanov * CVS log moved to end of the file * * Revision 1.20 2001/05/17 14:50:34 lavr * Typos corrected * * Revision 1.19 2001/03/16 16:39:13 vakatov * + <corelib/ncbi_limits.h> * * Revision 1.18 2001/01/22 23:07:12 vakatov * CArgValue::AsInteger() to return "int" (rather than "long") * * Revision 1.17 2000/12/24 00:12:59 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.15 2000/11/29 00:07:25 vakatov * Flag and key args not to be sorted in alphabetical order by default; see * "usage_sort_args" in SetUsageContext(). * * Revision 1.14 2000/11/24 23:28:31 vakatov * CArgValue:: added CloseFile() * CArgValue:: get rid of "change_mode" feature in AsInput/OutputFile() * * Revision 1.13 2000/11/22 22:04:29 vakatov * Added special flag "-h" and special exception CArgHelpException to * force USAGE printout in a standard manner * * Revision 1.12 2000/11/17 22:04:28 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.11 2000/11/13 20:31:05 vakatov * Wrote new test, fixed multiple bugs, ugly "features", and the USAGE. * * Revision 1.10 2000/10/20 22:23:26 vakatov * CArgAllow_Strings customization; MSVC++ fixes; better diagnostic messages * * Revision 1.9 2000/10/20 20:25:53 vakatov * Redesigned/reimplemented the user-defined arg.value constraints * mechanism (CArgAllow-related classes and methods). +Generic clean-up. * * Revision 1.8 2000/10/06 21:57:51 butanaev * Added Allow() function. Added classes CArgAllowValue, CArgAllowIntInterval. * * Revision 1.7 2000/09/29 17:11:22 butanaev * Got rid of IsDefaultValue(), added IsProvided(). * * Revision 1.6 2000/09/28 21:01:58 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.5 2000/09/22 21:27:13 butanaev * Fixed buf in handling default arg values. * * Revision 1.4 2000/09/19 21:18:11 butanaev * Added possibility to change file open mode on the fly * * Revision 1.3 2000/09/18 19:38:59 vasilche * Added CreateArgs() from CNcbiArguments. * * Revision 1.2 2000/09/06 18:56:56 butanaev * Added stdin, stdout support. Fixed bug in PrintOut. * * Revision 1.1 2000/08/31 23:54:47 vakatov * Initial revision * * =========================================================================== */#endif /* NCBIARGS__HPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -