1 #ifndef CORELIB___NCBIARGS__HPP
2 #define CORELIB___NCBIARGS__HPP
187 const string&
GetName(
void)
const {
return m_Name; }
266 fTruncate = (1 << 12),
268 fCreatePath = (1 << 8)
312 fArgValue_HasDefault = (1 << 0),
313 fArgValue_FromDefault = (1 << 1)
344 void x_SetDefault(
const string& def_value,
bool from_def);
405 bool Exist(
const string& name)
const;
419 const CArgValue& operator[] (
const string& name)
const;
425 const CArgValue& operator[] (
size_t idx)
const;
428 vector< CRef<CArgValue> > GetAll(
void)
const;
452 bool add_value =
false);
455 bool IsEmpty(
void)
const;
458 void Remove(
const string& name);
489 TArgsCI x_Find(
const string& name)
const;
490 TArgsI x_Find(
const string& name);
518 const string&
value)
const;
567 void SetArgsType(EArgSetType args_type);
578 ePositionalMode_Loose
583 { m_PositionalMode = positional_mode; }
608 static const char* GetTypeName(EType
type);
624 fTruncate = (1 << 12),
628 fCreatePath = (1 << 8),
631 fFileFlags = fPreOpen | fBinary | fAppend | fTruncate |
fNoCreate | fCreatePath,
635 fAllowMultiple = (1 << 3),
641 fIgnoreInvalidValue = (1 << 4),
644 fWarnOnInvalidValue = (1 << 5),
653 fOptionalSeparator = (1 << 6),
656 fOptionalSeparatorAllowConflict = (1 << 9),
659 fMandatorySeparator = (1 << 7),
674 fConfidential = (1 << 13)
692 void AddKey(
const string& name,
693 const string& synopsis,
694 const string& comment,
713 void AddOptionalKey(
const string& name,
714 const string& synopsis,
715 const string& comment,
734 void AddDefaultKey(
const string& name,
735 const string& synopsis,
736 const string& comment,
738 const string& default_value,
744 const char* display_value =
nullptr
750 eFlagHasValueIfMissed = 0,
751 eFlagHasValueIfSet = 1
769 void AddFlag(
const string& name,
770 const string& comment,
792 void AddOpening(
const string& name,
793 const string& comment,
817 void AddPositional(
const string& name,
818 const string& comment,
840 void AddOptionalPositional(
const string& name,
841 const string& comment,
861 void AddDefaultPositional(
const string& name,
862 const string& comment,
864 const string& default_value,
870 const char* display_value =
nullptr
885 void AddExtra(
unsigned n_mandatory,
887 const string& comment,
900 void AddAlias(
const string& alias,
const string& arg_name);
907 void AddNegatedFlagAlias(
const string& alias,
908 const string& arg_name,
944 void SetConstraint(
const string& name,
946 EConstraintNegate negate = eConstraint);
950 void SetConstraint(
const string& name,
952 EConstraintNegate negate = eConstraint);
965 void SetDependency(
const string& arg1,
973 void SetCurrentGroup(
const string& group);
985 void SetErrorHandler(
const string& name,
989 bool Exist(
const string& name)
const;
996 void Delete(
const string& name);
1002 void SetUsageContext(
const string& usage_name,
1003 const string& usage_description,
1004 bool usage_sort_args =
false,
1017 void SetDetailedDescription(
const string& usage_description);
1029 fUsageIfNoArgs = 1 << 1,
1031 fUsageSortArgs = 1 << 2,
1032 fDupErrToCerr = 1 << 3,
1041 m_MiscFlags |=
flags;
1047 m_MiscFlags &= ~
flags;
1053 return (m_MiscFlags & flag) != 0;
1064 fHideLogfile = 0x01,
1065 fHideConffile = 0x02,
1066 fHideVersion = 0x04,
1067 fHideFullVersion = 0x08,
1070 fHideFullHelp = 0x40,
1071 fHideXmlHelp = 0x80,
1082 virtual string& PrintUsage(
string&
str,
bool detailed =
false)
const;
1096 static bool VerifyName(
const string& name,
bool extended =
false);
1108 virtual void AddStdArguments(THideStdArgs
mask);
1110 void AddDefaultFileArguments(
const string& default_config);
1124 : m_Arg(arg), m_Dep(dep) {}
1165 bool negated=
false)
const;
1212 unsigned int n_plain,
1214 bool update =
false,
1224 unsigned int n_plain,
1243 void AddSynopsis(list<string>&
arr,
const string& intro,
const string&
prefix)
const;
1244 void AddDescription(list<string>&
arr,
bool detailed)
const;
1245 void AddCommandDescription(list<string>&
arr,
const string&
cmd,
1247 void AddDetails(list<string>&
arr)
const;
1278 template<
class TSize,
class TArray>
1285 unique_ptr<CArgs> args(
new CArgs());
1288 if (GetArgsType() == eCgiArgs && argc == 2) {
1289 x_CheckAutoHelp(argv[1]);
1290 return args.release();
1295 for (TSize
i = 1;
i < argc;
i++) {
1296 bool have_arg2 = (
i + 1 < argc);
1297 if ( x_CreateArg(argv[
i], have_arg2,
1299 &n_plain, *args) ) {
1310 x_PostCheck(*args, n_plain, eCreateArgs);
1311 return args.release();
1327 const string& param_name = *it;
1330 typename T::const_iterator vit = arg_map.find(param_name);
1331 typename T::const_iterator vend = arg_map.end();
1335 x_CreateArg(param_name, param_name,
1343 if (new_arg_value && x_IsMultiArg(param_name)) {
1348 for (++vit; vit != vend; ++vit) {
1349 if (vit->first != param_name)
1351 varr.push_back(vit->second);
1358 x_PostCheck(*args, 0, eConvertKeys);
1362 return list<CArgDescriptions*>({
this});
1385 eCommandMandatory = 0,
1386 eCommandOptional = 1,
1387 eNoSortCommands = (1<<1),
1388 eNoSortGroups = (1<<2)
1407 void SetCurrentCommandGroup(
const string& group);
1430 virtual void AddStdArguments(THideStdArgs
mask);
1438 virtual string& PrintUsage(
string&
str,
bool detailed =
false)
const;
1446 virtual list<CArgDescriptions*> GetAllDescriptions(
void);
1452 bool x_IsCommandMandatory(
void)
const;
1453 size_t x_GetCommandGroupIndex(
const string& group)
const;
1454 string x_IdentifyCommand(
const string&
command)
const;
1568 virtual bool Verify(
const string&
value)
const;
1571 virtual string GetUsage(
void)
const;
1610 virtual bool Verify(
const string&
value)
const;
1613 virtual string GetUsage(
void)
const;
1671 return AllowValue(
value);
1676 virtual bool Verify(
const string&
value)
const;
1679 virtual string GetUsage(
void)
const;
1720 virtual bool Verify(
const string&
value)
const;
1723 virtual string GetUsage(
void)
const;
1760 virtual string GetUsage(
void)
const;
1795 virtual bool Verify(
const string&
value)
const;
1798 virtual string GetUsage(
void)
const;
1829 const string& comment,
1837 const string&
GetName (
void)
const {
return m_Name; }
1860 virtual void VerifyDefault (
void)
const;
1868 void SetConstraint(
const CArgAllow* constraint,
1877 virtual const CArgAllow* GetConstraint(
void)
const;
1880 string GetUsageConstraint(
void)
const;
1911 const string& name,
const string& description =
kEmptyStr);
1950 EInstantSet instant_set = eNoInstantSet);
1961 EInstantSet instant_set = eNoInstantSet);
1964 bool x_Evaluate(
const CArgs& args,
string* arg_set,
string* arg_unset)
const;
1978 void PrintUsage(list<string>&
arr,
size_t offset)
const;
1980 void Evaluate(
const CArgs& args)
const;
Template used to replace bool type arguments with some strict equivalent.
CCommandArgDescriptions –.
container_type::const_iterator const_iterator
parent_type::iterator iterator
parent_type::const_iterator const_iterator
void Print(const CCompactSAMApplication::AlignInfo &ai)
static vector< string > arr
static int err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
std::ofstream out("events_result.xml")
main entry point for tests
#define NCBI_DEPRECATED_CTOR(decl)
Macro used to mark a constructor as deprecated.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
virtual list< CArgDescriptions * > GetAllDescriptions(void)
EFlags
Additional flags, the first group is file related flags.
size_t GetOrdinalPosition(void) const
Get ordinal position of the value.
unsigned int TCommandArgFlags
Bitwise OR of ECommandArgFlags.
TArgs::const_iterator TArgsCI
Type for const iterator.
virtual bool AsBoolean(void) const =0
Get the argument's boolean value.
TArgGroups m_ArgGroups
Argument groups.
virtual CArgValue * ProcessDefault(void) const =0
Process argument default.
CArgs * CreateArgs(TSize argc, TArray argv) const
Create parsed arguments in CArgs object.
CArgDescriptions::TFlags GetFlags(void) const
Get argument flags.
void x_CheckAutoHelp(const string &arg) const
Helper method for checking if auto help requested and throw CArgHelpException if help requested.
map< string, EInstantSet > m_Arguments
TArgsI x_Find(const string &name, bool *negative=NULL)
Helper method to find named parameter.
set< string, PNocase_Conditional > TStrings
Type of the container that contains the allowed string values.
string m_Name
Argument name.
virtual const string & AsString(void) const =0
Get the argument's string value.
list< const CArgDesc * > m_args
virtual double AsDouble(void) const =0
Get the argument's double value.
void x_PrintAliasesAsXml(CNcbiOstream &out, const string &name, bool negated=false) const
string m_Command
current command
map< CConstRef< CArgDependencyGroup >, EInstantSet > m_Groups
TArgs m_Args
Assoc.map of arguments' name/descr.
string m_Name
Argument name.
CRef< CArgErrorHandler > m_ErrorHandler
Global error handler or NULL.
size_t x_GetGroupIndex(const string &group) const
Get group index.
const string & GetName(void) const
Get argument name.
virtual string GetUsageSynopsis(bool name_only=false) const =0
Get usage synopsis.
TPosArgs m_OpeningArgs
Opening args, ordered by position in cmd.-line.
CArgDependencyGroup(const CArgDependencyGroup &dep_group)
set< AutoPtr< CArgDesc > > TArgs
Argument descr. type.
set< CRef< CArgValue > > TArgs
Type for arguments.
EMiscFlags
Miscellaneous flags.
void SetMiscFlags(TMiscFlags flags)
Set the selected flags.
SIZE_TYPE m_UsageWidth
Maximum length of a usage line.
multimap< string, SArgDependency > TDependencies
virtual const CDir & AsDirectory(void) const =0
Get the argument as a directory.
void SetArgsType(EArgSetType)
bool IsAutoHelpEnabled(void) const
See if special flag "-h" is activated.
TStrings m_Strings
Set of allowed string values.
list< string > m_CmdGroups
group names, and order
virtual const CArgErrorHandler * GetErrorHandler(void) const
Get error handler for the argument.
string m_Comment
Argument description.
TDependencies::const_iterator TDependency_CI
bool operator<(const CRef< CArgValue > &x, const CRef< CArgValue > &y)
virtual void SetErrorHandler(CArgErrorHandler *)
Set error handler for the argument.
void SetPositionalMode(EArgPositionalMode positional_mode)
Select mode for processing positional arguments.
virtual bool IsConstraintInverted() const
Returns TRUE if associated constraint is inverted (NOT)
unsigned int TFileFlags
Bitwise OR of "EFileFlags".
EErrCode
Error types for improperly formatted arguments.
vector< string > TArgGroups
Argument groups.
void x_PreCheck(void) const
Helper method for doing pre-processing consistency checks.
EArgSetType GetArgsType() const
virtual CNcbiIostream & AsIOFile(TFileFlags flags=0) const =0
Get the argument as a file stream.
virtual string GetUsage(void) const =0
Get usage information.
CArgAllow_Strings & operator,(const string &value)
Short notation operator for adding allowed string values.
EArgPositionalMode GetPositionalMode() const
void x_PrintComment(list< string > &arr, const CArgDesc &arg, SIZE_TYPE width) const
CArgs * SetCommand(const string &command)
Set current command.
virtual CNcbiIstream & AsInputFile(TFileFlags flags=0) const =0
Get the argument as an input file stream.
TArgs::iterator TArgsI
Type for iterator.
bool x_CreateArg(const string &arg1, bool have_arg2, const string &arg2, unsigned *n_plain, CArgs &args) const
Process arguments.
void ResetMiscFlags(TMiscFlags flags)
Clear the selected usage flags.
virtual string GetUsageCommentAttr(void) const =0
Get usage comment attribute.
string m_UsageName
Program name.
SArgDependency(const string arg, EDependency dep)
NCBI_EXCEPTION_DEFAULT(CArgException, CCoreException)
EArgSetType m_ArgsType
Type of arguments.
const string & GetName(void) const
Get argument name.
void SetOrdinalPosition(size_t pos)
set< TSymClass > m_SymClass
CArgDescriptions::TFlags m_Flags
string GetCommand(void) const
Get current command.
EArgValueFlags
Whether the argument:
size_t m_CurrentCmdGroup
current group #
pair< double, double > TInterval
set< CConstRef< CArgDependencyGroup > > m_DependencyGroups
virtual void SetGroup(size_t)
Set argument group.
map< string, AutoPtr< CArgDescriptions > > TDescriptions
virtual bool Verify(const string &value) const =0
Verify if specified value is allowed.
list< string > m_Commands
command names, and order
TArgs::iterator TArgsI
Arguments iterator.
EArgSetType
Type of CArgDescriptions For a CGI application positional arguments and flags does not make sense (th...
bool m_HasHidden
Has hidden arguments.
TDependencies m_Dependencies
Arguments' dependencies.
map< string, string > m_Aliases
command to alias; one alias only
virtual CNcbiOstream & AsOutputFile(TFileFlags flags=0) const =0
Get the argument as an output file stream.
unsigned int TFlags
Bitwise OR of "EFlags".
virtual bool HasValue(void) const =0
Check if argument holds a value.
DECLARE_OPERATOR_BOOL(HasValue())
Synonym for HasValue().
TArgs m_Args
Assoc. map of arguments' name/value.
size_t m_nExtra
Cached # of unnamed positional arguments.
void ConvertKeys(CArgs *args, const T &arg_map, bool update) const
Convert argument map (key-value pairs) into arguments in accordance with the argument descriptions.
set< TInterval > m_MinMax
EFlagValue
Define how flag presence affect CArgValue::HasValue().
list< string > TKeyFlagArgs
List of flag arguments.
virtual CArgValue * ProcessArgument(const string &value) const =0
Process argument with specified value.
EDependency
Dependencies between arguments.
void x_AddDesc(CArgDesc &arg)
Helper method for adding description.
virtual size_t GetGroup(void) const
Get argument group.
EInstantSet
Control whether the "setting" of this particular member marks the whole group as "set" regardless of ...
size_t m_CurrentGroup
Currently selected group (0 = no group)
virtual void CloseFile(void) const =0
Close the file.
string m_DetailedDescription
Program long description.
EType
Available argument types.
TMiscFlags m_MiscFlags
Flags for USAGE, error handling etc.
string m_UsageDescription
Program description.
TDescriptions m_Description
command to ArgDescriptions
virtual int AsInteger(void) const =0
Get the argument's integer value.
const string & GetComment(void) const
Get argument description.
EHideStdArgs
Which standard flag's descriptions should not be displayed in the usage message.
string m_NoSeparator
Arguments allowed to use no separator.
virtual TStringArray & SetStringList()
Get reference on value list for further modification.
int THideStdArgs
Binary OR of "EHideStdArgs".
unsigned int TArgValueFlags
Bitwise OR of "EArgValueFlags".
virtual const CTime & AsDateTime(void) const =0
Get the argument as a DateTime.
bool m_AutoHelp
Special flag "-h" activated.
EArgPositionalMode
Processing of positional arguments.
TArgs::const_iterator TArgsCI
Const arguments iterator.
pair< ESymbolClass, string > TSymClass
vector< string > TStringArray
Some values types can contain several value lists.
set< TInterval > m_MinMax
vector< string > TPosArgs
Positional arg. vector.
ESymbolClass
Symbol class for defining sets of characters.
const CArgDescriptions & m_desc
const CArgDescriptions & m_desc
EArgPositionalMode m_PositionalMode
Processing of positional args.
virtual Int8 AsInt8(void) const =0
Get the argument's integer (8-byte long) value.
unsigned m_nExtraOpt
> # of mandatory extra args
virtual TIntId AsIntId(void) const =0
Get the argument's value as an integer id (TIntId).
TKeyFlagArgs m_KeyFlagArgs
Key/flag args, in order of insertion.
EConstraintNegate
Flag to invert constraint logically.
size_t GetNExtra(void) const
Get the number of unnamed positional (a.k.a. extra) args.
map< string, size_t > m_Groups
command to group #
bool x_CreateArg(const string &arg1, const string &name, bool have_arg2, const string &arg2, unsigned int n_plain, CArgs &args, bool update=false, CArgValue **new_value=0) const
TPosArgs m_PosArgs
Pos. args, ordered by position in cmd.-line.
bool x_IsMultiArg(const string &name) const
Returns TRUE if parameter supports multiple arguments.
pair< Int8, Int8 > TInterval
int TMiscFlags
Bitwise OR of "EMiscFlags".
TCommandArgFlags m_Cmd_req
void x_PostCheck(CArgs &args, unsigned int n_plain, EPostCheckCaller caller) const
Helper method for doing post-processing consistency checks.
bool IsSetMiscFlag(EMiscFlags flag) const
Check if the flag is set.
NCBI_EXCEPTION_DEFAULT(CArgHelpException, CArgException)
@ eConvertKeys
called by ConvertKeys()
@ eCreateArgs
called by CreateArgs()
@ eHelpShowAll
Error code for detailed help message which includes hidden arguments.
@ eHelp
Error code for short help message.
@ eHelpXml
Error code for XML formatted help message.
@ eHelpFull
Error code for detailed help message.
@ eExcludedValue
The value is excluded by another argument.
@ eNoFile
Expecting a file.
@ eNoValue
Expecting an argument value.
@ eWrongCast
Incorrect cast for an argument.
@ eArgType
Wrong argument type.
@ eConvert
Conversion problem.
@ eConstraint
Argument value outside constraints.
@ eInvalidArg
Invalid argument.
@ eRegularArgs
Regular application.
@ eRequires
One argument requires another.
@ eInt8
Convertible into an integer number (Int8 only)
@ eInputFile
Name of file (must exist and be readable)
@ eBoolean
{'true', 't', 'false', 'f'}, case-insensitive
@ eDouble
Convertible into a floating point number (double)
@ eDataSize
Integer number with possible "software" qualifiers (KB, KiB, et al)
@ eIntId
Convertible to TIntId (int or Int8 depending on NCBI_INT8_GI)
@ eIOFile
Name of file (must be writable)
@ eOutputFile
Name of file (must be writable)
@ eInteger
Convertible into an integer number (int or Int8)
@ eDirectory
Name of file directory.
@ ePositionalMode_Strict
Strict mode (default)
@ eLower
Lowercase characters.
@ eAlnum
Alphanumeric characters.
@ eGraph
Graphical characters.
@ ePrint
Printable characters.
@ eSpace
Space characters.
@ eDigit
Digit characters.
@ eUpper
Uppercase characters.
@ eXdigit
Hexadecimal characters.
@ eCntrl
Control characters.
@ ePunct
Punctuation characters.
@ eAlpha
Alphabet characters.
@ eConstraintInvert
Logical NOT.
@ eConstraint
Constraint is not inverted (taken as is)
CException & operator=(const CException &)
Private assignment operator to prohibit assignment.
TFlags m_Flags
Flags, hints, attributes.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
int64_t Int8
8-byte (64-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::iostream CNcbiIostream
Portable alias for iostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
NCBI_NS_STD::string::size_type SIZE_TYPE
ECase
Which type of string comparison.
@ eCase
Case sensitive compare.
#define NCBI_XNCBI_EXPORT
@ fNoCreate
Command does not create blob if it does not exist.
Miscellaneous common-use basic types and functionality.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Defines: CTimeFormat - storage class for time format.
static const char * prefix[]
static const char * str(char *buf, int n)