重构名称
This commit is contained in:
parent
e39e9a1b1c
commit
0de21ee189
|
@ -3,41 +3,41 @@
|
||||||
using namespace args_parse;
|
using namespace args_parse;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ArgvPackImpl::ArgvPackImpl(const QString& means, ParamType t) : means_store(means), type_store(t) { }
|
__ArgvPackImpls::__ArgvPackImpls(const QString& means, ParamType t) : means_store(means), type_store(t) { }
|
||||||
|
|
||||||
// ͨ¹ý ArgvPack ¼Ì³Ð
|
// ͨ¹ý IArgvPack ¼Ì³Ð
|
||||||
ParamType ArgvPackImpl::paramType() const {
|
ParamType __ArgvPackImpls::paramType() const {
|
||||||
return type_store;
|
return type_store;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ArgvPackImpl::means() const {
|
QString __ArgvPackImpls::means() const {
|
||||||
return means_store;
|
return means_store;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgvPackImpl::setValue(const QString& v) {
|
void __ArgvPackImpls::setValue(const QString& v) {
|
||||||
this->value_store = v;
|
this->value_store = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ArgvPackImpl::value() const {
|
QString __ArgvPackImpls::value() const {
|
||||||
return value_store;
|
return value_store;
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatArgvPack::FloatArgvPack(const QString& key, const QString& means, bool optional) :
|
FloatKeyValue::FloatKeyValue(const QString& key, const QString& means, bool optional) :
|
||||||
FloatArgvImpl(key, means, optional) { }
|
__FloatArgvImpl(key, means, optional) { }
|
||||||
|
|
||||||
QString FloatArgvImpl::bindKey() const {
|
QString __FloatArgvImpl::bindKey() const {
|
||||||
return key_name;
|
return key_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloatArgvImpl::optional() const {
|
bool __FloatArgvImpl::optional() const {
|
||||||
return optional_value;
|
return optional_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FloatArgvPack::matchLenth() const {
|
int FloatKeyValue::matchLenth() const {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FloatArgvPack::parse(const QList<QString> args, int start) {
|
bool FloatKeyValue::parse(const QList<QString> args, int start) {
|
||||||
auto args_t = args[start];
|
auto args_t = args[start];
|
||||||
auto args_v = args[start + 1];
|
auto args_v = args[start + 1];
|
||||||
if (args_t == bindKey())
|
if (args_t == bindKey())
|
||||||
|
@ -45,7 +45,7 @@ bool FloatArgvPack::parse(const QList<QString> args, int start) {
|
||||||
return args_t == bindKey();
|
return args_t == bindKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexParam::IndexParam(const QString& means) : ArgvPackImpl(means, ParamType::IndexParam) { }
|
IndexParam::IndexParam(const QString& means) : __ArgvPackImpls(means, ParamType::IndexParam) { }
|
||||||
|
|
||||||
int IndexParam::matchLenth() const {
|
int IndexParam::matchLenth() const {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -56,11 +56,11 @@ bool IndexParam::parse(const QList<QString> args, int start) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FloatArgvImpl::FloatArgvImpl(const QString& key, const QString& means, bool optional)
|
__FloatArgvImpl::__FloatArgvImpl(const QString& key, const QString& means, bool optional)
|
||||||
: ArgvPackImpl(means, ParamType::FloatParam), key_name(key), optional_value(optional) { }
|
: __ArgvPackImpls(means, ParamType::FloatParam), key_name(key), optional_value(optional) { }
|
||||||
|
|
||||||
FloatOption::FloatOption(const QString& key, const QString& means, bool opt)
|
FloatOption::FloatOption(const QString& key, const QString& means, bool opt)
|
||||||
: FloatArgvImpl(key, means, opt) {
|
: __FloatArgvImpl(key, means, opt) {
|
||||||
setValue(u8"0");
|
setValue(u8"0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,11 +77,11 @@ bool FloatOption::parse(const QList<QString> args, int start) {
|
||||||
namespace args_parse {
|
namespace args_parse {
|
||||||
class MatchMode {
|
class MatchMode {
|
||||||
private:
|
private:
|
||||||
QList<shared_ptr<ArgvPack>> args_mode;
|
QList<shared_ptr<IArgvPack>> args_mode;
|
||||||
int code_store;
|
int code_store;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MatchMode(const QList<shared_ptr<ArgvPack>> mode, int mode_code)
|
explicit MatchMode(const QList<shared_ptr<IArgvPack>> mode, int mode_code)
|
||||||
:args_mode(mode), code_store(mode_code) { }
|
:args_mode(mode), code_store(mode_code) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,7 +95,7 @@ namespace args_parse {
|
||||||
* @brief 获取模式匹配结果
|
* @brief 获取模式匹配结果
|
||||||
* @return 模式匹配结果
|
* @return 模式匹配结果
|
||||||
*/
|
*/
|
||||||
QList<shared_ptr<ArgvPack>> result() const {
|
QList<shared_ptr<IArgvPack>> result() const {
|
||||||
return args_mode;
|
return args_mode;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -116,11 +116,11 @@ namespace args_parse {
|
||||||
}break;
|
}break;
|
||||||
case ParamType::FloatParam:// 浮动参数匹配
|
case ParamType::FloatParam:// 浮动参数匹配
|
||||||
{
|
{
|
||||||
QList<shared_ptr<FloatArgvImpl>> float_parsers;
|
QList<shared_ptr<__FloatArgvImpl>> float_parsers;
|
||||||
|
|
||||||
for (auto& unit : args_mode) {
|
for (auto& unit : args_mode) {
|
||||||
if (unit->paramType() == ParamType::FloatParam)
|
if (unit->paramType() == ParamType::FloatParam)
|
||||||
float_parsers << dynamic_pointer_cast<FloatArgvImpl>(unit);
|
float_parsers << dynamic_pointer_cast<__FloatArgvImpl>(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& unit : float_parsers) {
|
for (auto& unit : float_parsers) {
|
||||||
|
@ -142,11 +142,11 @@ namespace args_parse {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void ArgsParser::loadMode(int mode_code, const QList<shared_ptr<ArgvPack>>& args_model) {
|
void ArgsParser::loadMode(int mode_code, const QList<shared_ptr<IArgvPack>>& args_model) {
|
||||||
this->match_modes.append(make_shared<MatchMode>(args_model, mode_code));
|
this->match_modes.append(make_shared<MatchMode>(args_model, mode_code));
|
||||||
}
|
}
|
||||||
|
|
||||||
tuple<int, QList<shared_ptr<ArgvPack>>> ArgsParser::parse(int argc, char* argv[]) {
|
tuple<int, QList<shared_ptr<IArgvPack>>> ArgsParser::parse(int argc, char* argv[]) {
|
||||||
// 聚合参数数组
|
// 聚合参数数组
|
||||||
QList<QString> args_list;
|
QList<QString> args_list;
|
||||||
for (int idx = 0; idx < argc; idx++) {
|
for (int idx = 0; idx < argc; idx++) {
|
||||||
|
@ -157,8 +157,8 @@ tuple<int, QList<shared_ptr<ArgvPack>>> ArgsParser::parse(int argc, char* argv[]
|
||||||
// 枚举模式匹配
|
// 枚举模式匹配
|
||||||
for (auto& minst : this->match_modes) {
|
for (auto& minst : this->match_modes) {
|
||||||
if (minst->parse(args_list, 0, 0))
|
if (minst->parse(args_list, 0, 0))
|
||||||
return tuple<int, QList<shared_ptr<ArgvPack>>>(minst->modeCode(), minst->result());
|
return tuple<int, QList<shared_ptr<IArgvPack>>>(minst->modeCode(), minst->result());
|
||||||
}
|
}
|
||||||
|
|
||||||
return tuple<int, QList<shared_ptr<ArgvPack>>>(0, QList<shared_ptr<ArgvPack>>());
|
return tuple<int, QList<shared_ptr<IArgvPack>>>(0, QList<shared_ptr<IArgvPack>>());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@ namespace args_parse {
|
||||||
/**
|
/**
|
||||||
* @brief 命令行参数包.
|
* @brief 命令行参数包.
|
||||||
*/
|
*/
|
||||||
class ArgvPack {
|
class IArgvPack {
|
||||||
public:
|
public:
|
||||||
virtual ~ArgvPack() = default;
|
virtual ~IArgvPack() = default;
|
||||||
|
|
||||||
virtual ParamType paramType() const = 0;
|
virtual ParamType paramType() const = 0;
|
||||||
virtual QString means() const = 0;
|
virtual QString means() const = 0;
|
||||||
|
@ -42,30 +42,30 @@ namespace args_parse {
|
||||||
virtual bool parse(const QList<QString> args, int start) = 0;
|
virtual bool parse(const QList<QString> args, int start) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ARGSPARSER_EXPORT ArgvPackImpl : public ArgvPack {
|
class ARGSPARSER_EXPORT __ArgvPackImpls : public IArgvPack {
|
||||||
private:
|
private:
|
||||||
QString means_store;
|
QString means_store;
|
||||||
QString value_store;
|
QString value_store;
|
||||||
ParamType type_store;
|
ParamType type_store;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ArgvPackImpl(const QString &means, ParamType t);
|
__ArgvPackImpls(const QString &means, ParamType t);
|
||||||
|
|
||||||
void setValue(const QString &v);
|
void setValue(const QString &v);
|
||||||
|
|
||||||
// ͨ¹ý ArgvPack ¼Ì³Ð
|
// ͨ¹ý IArgvPack ¼Ì³Ð
|
||||||
ParamType paramType() const override;
|
ParamType paramType() const override;
|
||||||
QString means() const override;
|
QString means() const override;
|
||||||
QString value() const override;
|
QString value() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ARGSPARSER_EXPORT FloatArgvImpl : public ArgvPackImpl {
|
class ARGSPARSER_EXPORT __FloatArgvImpl : public __ArgvPackImpls {
|
||||||
private:
|
private:
|
||||||
QString key_name;
|
QString key_name;
|
||||||
bool optional_value;
|
bool optional_value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FloatArgvImpl(const QString& key, const QString& means, bool optional);
|
explicit __FloatArgvImpl(const QString& key, const QString& means, bool optional);
|
||||||
|
|
||||||
QString bindKey() const;
|
QString bindKey() const;
|
||||||
virtual bool optional() const;
|
virtual bool optional() const;
|
||||||
|
@ -75,10 +75,10 @@ namespace args_parse {
|
||||||
* @brief 命令行key-value解析匹配模式.
|
* @brief 命令行key-value解析匹配模式.
|
||||||
* --key value
|
* --key value
|
||||||
*/
|
*/
|
||||||
class ARGSPARSER_EXPORT FloatArgvPack : public FloatArgvImpl {
|
class ARGSPARSER_EXPORT FloatKeyValue : public __FloatArgvImpl {
|
||||||
public:
|
public:
|
||||||
explicit FloatArgvPack(const QString& key, const QString &means, bool optional = false);
|
explicit FloatKeyValue(const QString& key, const QString &means, bool optional = false);
|
||||||
virtual ~FloatArgvPack() = default;
|
virtual ~FloatKeyValue() = default;
|
||||||
|
|
||||||
virtual int matchLenth() const override;
|
virtual int matchLenth() const override;
|
||||||
bool parse(const QList<QString> args, int start) override;
|
bool parse(const QList<QString> args, int start) override;
|
||||||
|
@ -88,7 +88,7 @@ namespace args_parse {
|
||||||
* @brief 命令行key解析匹配模式.
|
* @brief 命令行key解析匹配模式.
|
||||||
* --key
|
* --key
|
||||||
*/
|
*/
|
||||||
class ARGSPARSER_EXPORT FloatOption : public FloatArgvImpl {
|
class ARGSPARSER_EXPORT FloatOption : public __FloatArgvImpl {
|
||||||
public:
|
public:
|
||||||
explicit FloatOption(const QString& key, const QString& means, bool optional = false);
|
explicit FloatOption(const QString& key, const QString& means, bool optional = false);
|
||||||
virtual ~FloatOption() = default;
|
virtual ~FloatOption() = default;
|
||||||
|
@ -100,12 +100,12 @@ namespace args_parse {
|
||||||
/**
|
/**
|
||||||
* 序列索引参数.
|
* 序列索引参数.
|
||||||
*/
|
*/
|
||||||
class ARGSPARSER_EXPORT IndexParam : public ArgvPackImpl {
|
class ARGSPARSER_EXPORT IndexParam : public __ArgvPackImpls {
|
||||||
public:
|
public:
|
||||||
explicit IndexParam(const QString &means);
|
explicit IndexParam(const QString &means);
|
||||||
virtual ~IndexParam() = default;
|
virtual ~IndexParam() = default;
|
||||||
|
|
||||||
// ͨ¹ý ArgvPackImpl ¼Ì³Ð
|
// ͨ¹ý __ArgvPackImpls ¼Ì³Ð
|
||||||
int matchLenth() const override;
|
int matchLenth() const override;
|
||||||
bool parse(const QList<QString> args, int start) override;
|
bool parse(const QList<QString> args, int start) override;
|
||||||
};
|
};
|
||||||
|
@ -116,9 +116,9 @@ namespace args_parse {
|
||||||
QList<std::shared_ptr<MatchMode>> match_modes;
|
QList<std::shared_ptr<MatchMode>> match_modes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void loadMode(int mode_code, const QList<std::shared_ptr<ArgvPack>> &args_model);
|
void loadMode(int mode_code, const QList<std::shared_ptr<IArgvPack>> &args_model);
|
||||||
|
|
||||||
std::tuple<int, QList<std::shared_ptr<ArgvPack>>> parse(int argc, char* argv[]);
|
std::tuple<int, QList<std::shared_ptr<IArgvPack>>> parse(int argc, char* argv[]);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,16 +11,16 @@ int main(int argc, char* argv[]) {
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
args_parse::ArgsParser entry_parser;
|
args_parse::ArgsParser entry_parser;
|
||||||
QList<std::shared_ptr<args_parse::ArgvPack>> args_mode;
|
QList<std::shared_ptr<args_parse::IArgvPack>> args_mode;
|
||||||
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
||||||
args_mode << std::make_shared<args_parse::FloatArgvPack>(u8"--help", "帮助选项");
|
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--help", "帮助选项");
|
||||||
entry_parser.loadMode(0x000au, args_mode);
|
entry_parser.loadMode(0x000au, args_mode);
|
||||||
args_mode.clear();
|
args_mode.clear();
|
||||||
|
|
||||||
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
||||||
args_mode << std::make_shared<args_parse::FloatOption>(u8"--nsc", u8"调用编译功能");
|
args_mode << std::make_shared<args_parse::FloatOption>(u8"--nsc", u8"调用编译功能");
|
||||||
args_mode << std::make_shared<args_parse::FloatArgvPack>(u8"--path", u8"源码目录路径", true);
|
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--path", u8"源码目录路径", true);
|
||||||
args_mode << std::make_shared<args_parse::FloatArgvPack>(u8"--dest", u8"生成目标目录");
|
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--dest", u8"生成目标目录");
|
||||||
entry_parser.loadMode(0x000bu, args_mode);
|
entry_parser.loadMode(0x000bu, args_mode);
|
||||||
args_mode.clear();
|
args_mode.clear();
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,15 @@ int main(int argc, char* argv[]) {
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
args_parse::ArgsParser args_parser;
|
args_parse::ArgsParser args_parser;
|
||||||
QList<std::shared_ptr<args_parse::ArgvPack>> args_mode;
|
QList<std::shared_ptr<args_parse::IArgvPack>> args_mode;
|
||||||
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
||||||
args_mode << std::make_shared<args_parse::FloatOption>(u8"--help", u8"帮助");
|
args_mode << std::make_shared<args_parse::FloatOption>(u8"--help", u8"帮助");
|
||||||
args_parser.loadMode(0x000Au, args_mode);
|
args_parser.loadMode(0x000Au, args_mode);
|
||||||
|
|
||||||
args_mode.clear();
|
args_mode.clear();
|
||||||
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
|
||||||
args_mode << std::make_shared<args_parse::FloatArgvPack>(u8"--path", u8"源代码目录");
|
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--path", u8"源代码目录");
|
||||||
args_mode << std::make_shared<args_parse::FloatArgvPack>(u8"--dest", u8"生成目录");
|
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--dest", u8"生成目录");
|
||||||
args_mode << std::make_shared<args_parse::FloatOption>(u8"--html", u8"生成html文件格式取代AST", true);
|
args_mode << std::make_shared<args_parse::FloatOption>(u8"--html", u8"生成html文件格式取代AST", true);
|
||||||
args_parser.loadMode(0x000Bu, args_mode);
|
args_parser.loadMode(0x000Bu, args_mode);
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ int main(int argc, char* argv[]) {
|
||||||
switch (std::get<0>(parse_result)) {
|
switch (std::get<0>(parse_result)) {
|
||||||
case 0xBu: {
|
case 0xBu: {
|
||||||
auto args = std::get<1>(parse_result);
|
auto args = std::get<1>(parse_result);
|
||||||
auto src_dir = std::dynamic_pointer_cast<args_parse::FloatArgvPack>(args_mode[1]);
|
auto src_dir = std::dynamic_pointer_cast<args_parse::FloatKeyValue>(args_mode[1]);
|
||||||
auto dst_dir = std::dynamic_pointer_cast<args_parse::FloatArgvPack>(args_mode[2]);
|
auto dst_dir = std::dynamic_pointer_cast<args_parse::FloatKeyValue>(args_mode[2]);
|
||||||
auto html_opt = std::dynamic_pointer_cast<args_parse::FloatOption>(args_mode[3]);
|
auto html_opt = std::dynamic_pointer_cast<args_parse::FloatOption>(args_mode[3]);
|
||||||
|
|
||||||
auto source_dir = QDir(src_dir->value());
|
auto source_dir = QDir(src_dir->value());
|
||||||
|
|
Loading…
Reference in New Issue