📄 ofcmdln.h
字号:
/* * * Copyright (C) 1998-2005, OFFIS * * This software and supporting documentation were developed by * * Kuratorium OFFIS e.V. * Healthcare Information and Communication Systems * Escherweg 2 * D-26121 Oldenburg, Germany * * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. * * Module: ofstd * * Author: Joerg Riesmeier * * Purpose: Handle command line arguments (Header) * * Last Update: $Author: meichel $ * Update Date: $Date: 2005/12/08 16:05:48 $ * CVS/RCS Revision: $Revision: 1.37 $ * Status: $State: Exp $ * * CVS/RCS Log at end of file * */#ifndef OFCMDLN_H#define OFCMDLN_H#include "dcmtk/config/osconfig.h"#include "dcmtk/ofstd/oftypes.h"#include "dcmtk/ofstd/oflist.h"#include "dcmtk/ofstd/ofstring.h"#include "dcmtk/ofstd/ofconsol.h"#define INCLUDE_CSTDIO#include "dcmtk/ofstd/ofstdinc.h"/*--------------------* * type declaration * *--------------------*//// signed integer valuetypedef signed long OFCmdSignedInt;/// unsigned integer valuetypedef unsigned long OFCmdUnsignedInt;/// floating point valuetypedef double OFCmdFloat;/// dynamic string valuetypedef OFString OFCmdString;// necessary for MSVC5 :-/typedef OFListIterator(OFString) OFListIterator_OFString;/*------------------------* * forward declarations * *------------------------*/struct OFCmdOption;struct OFCmdParamPos;/*----------------------* * struct declaration * *----------------------*//** Internal structure to store valid command line parameters. * Parameters are all command line arguments which are no options (e.g. file names). */struct OFCmdParam{ /** mode specifying parameter's cardinality */ enum E_ParamMode { /// parameter is required (# = 1), "option" PM_Mandatory, /// parameter is optional (# = 0..1), "[option]" PM_Optional, /// parameter is required, more than one value is allowed (# = 1..n), "option..." PM_MultiMandatory, /// parameter is optional, more than one value is allowed (# = 0..n), "[option...]" PM_MultiOptional }; /** constructor * ** @param param parameter name * @param descr parameter description * @param mode parameter's cardinality mode */ OFCmdParam(const char *param, const char *descr, const E_ParamMode mode) : ParamName(param), ParamDescription(descr), ParamMode(mode) { } /// parameter name const OFString ParamName; /// parameter description const OFString ParamDescription; /// parameter's cardinality mode const E_ParamMode ParamMode;private: /// private undefined copy assignment operator OFCmdParam& operator=(const OFCmdParam& arg);};/*---------------------* * class declaration * *---------------------*//** handles command line arguments. * This class is the interface to this module. * All methods which can be used from outside are defined here. */class OFCommandLine{ public: // --- enumerations /** status of command line parsing */ enum E_ParseStatus { /// normal, no errors PS_Normal, /// no arguments to be parsed PS_NoArguments, /// unknown option detected PS_UnknownOption, /// missing value(s) for an option PS_MissingValue, /// missing parameter PS_MissingParameter, /// too many parameters PS_TooManyParameters, /// cannot open command file PS_CannotOpenCommandFile }; /** status of converting string option value to value field */ enum E_ValueStatus { /// normal, no errors VS_Normal, /// argument contains invalid char(s) VS_Invalid, /// no more arguments to be converted VS_NoMore, /// empty string argument VS_Empty, /// converted value falls below minimum VS_Underflow, /// converted value exceeds maximum VS_Overflow }; /** status of converting string parameter to value field */ enum E_ParamValueStatus { /// normal, no errors PVS_Normal, /// argument contains invalid char(s) PVS_Invalid, /// specified parameter doesn't exist PVS_CantFind, /// empty string argument PVS_Empty, /// converted value falls below minimum PVS_Underflow, /// converted value exceeds maximum PVS_Overflow }; /** mode for findOption method */ enum E_FindOptionMode { /// normal find FOM_Normal, /// find first option FOM_First, /// find next option FOM_Next }; // --- constructor and destructor /** constructor */ OFCommandLine(); /** destructor */ virtual ~OFCommandLine(); // --- initialization /** sets characters used to detect options * ** @param chars string containing all valid option characters (default: "+-") */ void setOptionChars(const char *chars); /** sets default width of option columns * * @param longCols minimum width of the long option column * @param shortCols minimum width of the short option column */ void setOptionColumns(const int longCols, const int shortCols); /** sets default width of parameter column * * @param column minimum width of the long option column */ void setParamColumn(const int column); /** adds an item to the list of valid options * (full version) * ** @param longOpt long option name * @param shortOpt short option name * @param valueCount number of additional values * @param valueDescr description of optional values * @param optDescr description of command line option (use '\n' for line break) * @param exclusive exclusive option which cannot be combined with any other command * line argument (if OFTrue). "--help" is always considered an * exclusive option. * ** @return OFTrue if succesfully added */ OFBool addOption(const char *longOpt, const char *shortOpt, const int valueCount, const char *valueDescr, const char *optDescr, const OFBool exclusive = OFFalse); /** adds an item to the list of valid options * (without additional values) * ** @param longOpt long option name * @param shortOpt short option name * @param optDescr description of command line option (use '\n' for line break) * @param exclusive exclusive option which cannot be combined with any other command * line argument (if OFTrue). "--help" is always considered an * exclusive option. * ** @return OFTrue if succesfully added */ OFBool addOption(const char *longOpt, const char *shortOpt, const char *optDescr, const OFBool exclusive = OFFalse); /** adds an item to the list of valid options * (without short name) * ** @param longOpt long option name * @param valueCount number of additional values * @param valueDescr description of optional values * @param optDescr description of command line option (use '\n' for line break) * @param exclusive exclusive option which cannot be combined with any other command * line argument (if OFTrue). "--help" is always considered an * exclusive option. * ** @return OFTrue if succesfully added */ OFBool addOption(const char *longOpt, const int valueCount, const char *valueDescr, const char *optDescr, const OFBool exclusive = OFFalse); /** adds an item to the list of valid options * (without short name and additional values) * ** @param longOpt long option name * @param optDescr description of command line option (use '\n' for line break) * @param exclusive exclusive option which cannot be combined with any other command * line argument (if OFTrue). "--help" is always considered an * exclusive option. * ** @return OFTrue if succesfully added */ OFBool addOption(const char *longOpt, const char *optDescr, const OFBool exclusive = OFFalse); /** adds a new group (top-level). * all following options belong to this group * ** @param name name of the group * @param longCols minimum width of the long option column * @param shortCols minimum width of the short option column */ void addGroup(const char *name, const int longCols = 0, const int shortCols = 0); /** adds a new subgroup (beyond group-level). * all following options belong to this subgroup * ** @param name name of the subgroup * @param longCols minimum width of the long option column * @param shortCols minimum width of the short option column */ void addSubGroup(const char *name, const int longCols = 0, const int shortCols = 0); /** adds an item to the list of valid parameters * (full version) * ** @param param parameter name * @param descr parameter description (use '\n' for line break) * @param mode parameter's cardinality (see above) * ** @return OFTrue if successful, OFFalse otherwise */ OFBool addParam(const char *param, const char *descr, const OFCmdParam::E_ParamMode mode = OFCmdParam::PM_Mandatory); /** adds an item to the list of valid parameters * (without description) * ** @param param parameter name * @param mode parameter's cardinality (see above) * ** @return OFTrue if successful, OFFalse otherwise */ OFBool addParam(const char *param, const OFCmdParam::E_ParamMode mode = OFCmdParam::PM_Mandatory); // --- get information /** gets number of command line arguments. * (options and parameters) * ** @return number of command line arguments */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -