2023-03-30 23:44:03 +08:00
|
|
|
#ifndef CMDLINEPARSER_H
|
|
|
|
#define CMDLINEPARSER_H
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <getopt.h>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
string name;
|
|
|
|
int shortName;
|
|
|
|
int needParam;
|
|
|
|
string desc;
|
|
|
|
} OptDefine;
|
|
|
|
|
|
|
|
class CmdLineParser
|
|
|
|
{
|
|
|
|
public:
|
2023-03-31 18:32:46 +08:00
|
|
|
CmdLineParser(string name,string desc);
|
2023-03-30 23:44:03 +08:00
|
|
|
void regOpt(OptDefine optdef);
|
2023-03-31 18:32:46 +08:00
|
|
|
void regOpt(string name,int shorName, int needParam, string desc);
|
2023-03-30 23:44:03 +08:00
|
|
|
string getOpt(string key);
|
|
|
|
void parseArgs(int argc, char *argv[]);
|
2023-04-02 10:34:59 +08:00
|
|
|
void help();
|
2023-03-30 23:44:03 +08:00
|
|
|
private:
|
2023-03-31 18:32:46 +08:00
|
|
|
string appName;
|
|
|
|
string appDesc;
|
2023-03-30 23:44:03 +08:00
|
|
|
map<int, OptDefine> optMap;
|
|
|
|
map<string, string> paraMap;
|
|
|
|
bool hasOptSet(string key);
|
2023-04-02 10:34:59 +08:00
|
|
|
|
2023-03-30 23:44:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CMDLINEPARSER_H
|