为了规避NDK的Bug,停用异常处理

This commit is contained in:
2024-02-04 21:11:30 +08:00
parent ad6865feef
commit f994bae5cb
3 changed files with 94 additions and 98 deletions

View File

@@ -6,6 +6,8 @@
#include <stdexcept>
#define THROW(errStr) do{ this->err = errStr; return false; } while(false)
namespace ling {
Order::DataStruct::DataStruct(const std::vector<std::string> &option, const int id, const Type type, const std::string &memage) {
this->options = option;
@@ -35,15 +37,15 @@ namespace ling {
const std::string &Order::getString(const int id) const {
const auto it = opt_str.find(id);
if (it == opt_str.end()) {
return errStr;
return nullstr;
}
return it->second;
}
bool Order::getOption(const int id) const {
bool Order::getOption(const int id) {
const auto it = options.find(id);
if (it == options.end())
throw std::runtime_error("无效键");
THROW("无效键");
return it->second;
}
@@ -86,55 +88,60 @@ namespace ling {
return anonymity;
}
void Order::analysis() {
bool Order::analysis() {
for (auto it = cmd.begin(); it != cmd.end(); ++it) {
auto rules = data.find(*it);
if (rules == data.end()) {
//检查匿名参数数量
if (anonymity.size() >= anonymityNumber)
throw std::runtime_error("无法解析的参数:" + *it);
THROW("无法解析的参数:" + *it);
anonymity.push_back(*it);
continue;
}
if (it->at(0) != '-')
throw std::runtime_error("无法解析的参数:" + *it);
THROW("无法解析的参数:" + *it);
switch (rules->second.type) {
case OPT:
if (options[rules->second.id])
throw std::runtime_error("重复提供参数:" + *it);
THROW("重复提供参数:" + *it);
options[rules->second.id] = true;
break;
case STRING:
if (opt_str.find(rules->second.id) != opt_str.end())
throw std::runtime_error("重复提供参数:" + *it);
THROW("重复提供参数:" + *it);
if (std::next(it) == cmd.end())
throw std::runtime_error("参数不足!" + *it + " 需要提供参数");
THROW("参数不足!" + *it + " 需要提供参数");
if (std::next(it)->at(0) == '-')
throw std::runtime_error("参数不足!" + *it + " 需要提供参数");
THROW("参数不足!" + *it + " 需要提供参数");
++it;
opt_str[rules->second.id] = *it;
break;
case INT:
if (opt_int.find(rules->second.id) != opt_int.end())
throw std::runtime_error("重复提供参数:" + *it);
THROW("重复提供参数:" + *it);
if (std::next(it) == cmd.end())
throw std::runtime_error("参数不足!" + *it + " 需要提供参数");
THROW("参数不足!" + *it + " 需要提供参数");
if (std::next(it)->at(0) == '-')
throw std::runtime_error("参数不足!" + *it + " 需要提供参数");
THROW("参数不足!" + *it + " 需要提供参数");
++it;
opt_int[rules->second.id] = std::stoll(*it);
break;
case DOUBLE:
if (opt_double.find(rules->second.id) != opt_double.end())
throw std::runtime_error("重复提供参数:" + *it);
THROW("重复提供参数:" + *it);
if (std::next(it) == cmd.end())
throw std::runtime_error("参数不足!" + *it + " 需要提供参数");
THROW("参数不足!" + *it + " 需要提供参数");
if (std::next(it)->at(0) == '-')
throw std::runtime_error("参数不足!" + *it + " 需要提供参数");
THROW("参数不足!" + *it + " 需要提供参数");
++it;
opt_double[rules->second.id] = std::stod(*it);
break;
}
}
return true;
}
const std::string &Order::getError() const {
return err;
}
} // ling