incron 0.5.10

- Main Page
- Classes
- Files

- File List
- File Members

appargs.h
Go to the documentation of this file.

    00001
    00003
    00023 #ifndef APPARGS_H_
    00024 #define APPARGS_H_
    00025
    00026 #include <cstring>
    00027 #include <map>
    00028 #include <deque>
    00029
    00030
    00031
    00033 typedef enum
    00034 {
    00035   AAT_NO_VALUE,
    00036   AAT_OPTIONAL_VALUE,
    00037   AAT_MANDATORY_VALUE
    00038 } AppArgType_t;
    00039
    00040
    00041 #define APPARGS_NOLIMIT 0x7fffffff ///< value count has no limit
    00042
    00044 typedef struct
    00045 {
    00046   AppArgType_t type;
    00047   bool mand;
    00048   bool found;
    00049   std::string val;
    00050   bool hasVal;
    00051 } AppArgOption_t;
    00052
    00053
    00055 typedef std::map<std::string, AppArgOption_t*> AA_LONG_MAP;
    00056
    00058 typedef std::map<char, AppArgOption_t*> AA_SHORT_MAP;
    00059
    00061 typedef std::deque<std::string> AA_VAL_LIST;
    00062
    00063
    00065
    00088 class AppArgs
    00089 {
    00090 public:
    00092
    00096   static void Init(size_t valMinCnt = 0, size_t valMaxCnt = APPARGS_NOLIMIT);
    00097
    00099
    00103   static void Destroy();
    00104
    00106
    00112   static void Parse(int argc, const char* const* argv);
    00113
    00115
    00124   static bool IsValid();
    00125
    00127
    00131   static bool ExistsOption(const std::string& rArg);
    00132
    00134
    00139   static bool GetOption(const std::string& rArg, std::string& rVal);
    00140
    00142
    00153   static bool AddOption(const std::string& rName, char cShort, AppArgType_t type, bool fMandatory);
    00154
    00156
    00159   static size_t GetValueCount();
    00160
    00162
    00167   static bool GetValue(size_t index, std::string& rVal);
    00168
    00170
    00173   static void Dump();
    00174
    00175 protected:
    00177
    00181   static bool IsOption(const char* pchStr);
    00182
    00184
    00191   static bool IsLongOption(const char* pchStr);
    00192
    00194
    00201   static bool ParseLong(const char* pchStr, std::string& rName, std::string& rVal, bool& rfHasVal);
    00202
    00204
    00212   static void ParseShort(const char* pchStr, char& rcName, std::string& rVal, bool& rfHasVal);
    00213
    00215
    00220   static void DumpOption(const std::string& rName, char cShort, AppArgOption_t* pOpt);
    00221
    00222
    00223 private:
    00224   static size_t s_minCnt;
    00225   static size_t s_maxCnt;
    00226
    00227   static AA_LONG_MAP s_longMap;
    00228   static AA_SHORT_MAP s_shortMap;
    00229   static AA_VAL_LIST s_valList;
    00230
    00231 };
    00232
    00233
    00234 #endif /*APPARGS_H_*/