Files
parameter/include/Order.h

100 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 版权所有 (c) ling 保留所有权利。
// 除非另行说明否则仅允许在parameter中使用此文件中的代码。
//
// 由 ling 创建于 24-2-4.
//
#ifndef ORDER_H
#define ORDER_H
#include <Options.h>
#include <unordered_map>
#include <cstdint>
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;
//用来生成帮助的数据
std::vector<DataStruct> helpData;
//匿名参数数量
int anonymityNumber = 0;
int nextID = 1;
std::string nullstr;
std::string err;
protected:
int64_t getInt64(int id) const;
double getDouble(int id) const;
const std::string &getString(int id) const;
bool getOption(int id);
bool isExistence(int id) const;
public:
explicit Order(const std::vector<std::string> &temp);
Order(int argc, const char *const argv[]);
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();
const std::string &getError() const;
/// 生成help内容
std::string generateHelp(const std::string &title) const;
friend class Options;
};
} // ling
#endif //ORDER_H