Files
parameter/include/Order.h
2024-02-04 20:14:31 +08:00

87 lines
2.0 KiB
C++

//
// Created by ling on 24-2-4.
//
#ifndef ORDER_H
#define ORDER_H
#include <Options.h>
#include <unordered_map>
namespace ling {
class Options;
class Order {
public:
enum Type {
OPT,
STRING,
INT,
DOUBLE,
};
private:
struct DataStruct {
std::vector<std::string> options;
int id = 0;
Type type;
std::string memage;
DataStruct(const std::vector<std::string> &option, int id, Type type, const std::string &memage);
DataStruct();
};
std::vector<std::string> cmd;
//选项
std::unordered_map<int, bool> options;
//各种类型的参数
std::unordered_map<int, std::string> opt_str;
std::unordered_map<int, int64_t> opt_int;
std::unordered_map<int, double> opt_double;
//参数类型索引
std::unordered_map<int, Type> type;
//匿名参数
std::vector<std::string> anonymity;
//预定义参数规则
std::unordered_map<std::string, DataStruct> data;
//匿名参数数量
int anonymityNumber = 0;
int nextID = 1;
std::string errStr;
protected:
int64_t getInt64(int id) const;
double getDouble(int id) const;
const std::string &getString(int id) const;
bool getOption(int id) const;
bool isExistence(int id) const;
public:
explicit Order(const std::vector<std::string> &temp);
Options addOption(const std::vector<std::string> &opt, const std::string &message = "");
Options addOption(const std::vector<std::string> &opt, Type type, const std::string &message = "");
/// 添加匿名参数
void addAnonymity(int number);
/// 获取匿名参数列表
const std::vector<std::string> &getAnonymity() const;
/// 解析
void analysis();
friend class Options;
};
} // ling
#endif //ORDER_H