2025-07-14 17:35:53 +00:00
|
|
|
|
#include "TranslateBasic.h"
|
2025-08-02 02:42:39 +00:00
|
|
|
|
|
|
|
|
|
using namespace extract;
|
2025-08-05 11:26:19 +00:00
|
|
|
|
using namespace size_provider;
|
2025-08-02 02:42:39 +00:00
|
|
|
|
|
|
|
|
|
TranslateBasic::TranslateBasic()
|
|
|
|
|
{
|
|
|
|
|
// extractor type-list
|
2025-08-10 10:03:02 +00:00
|
|
|
|
std::shared_ptr<ExtractDelegate> u_ptr = std::make_shared<AsInteger>();
|
2025-08-10 09:02:18 +00:00
|
|
|
|
_basic_extractor_types[u_ptr->unitType()] = u_ptr;
|
|
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<AsUnsigned>();
|
|
|
|
|
_basic_extractor_types[u_ptr->unitType()] = u_ptr;
|
2025-08-02 02:42:39 +00:00
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
u_ptr = std::make_shared<AsFloat>();
|
|
|
|
|
_basic_extractor_types[u_ptr->unitType()] = u_ptr;
|
2025-08-02 02:42:39 +00:00
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
u_ptr = std::make_shared<AsDouble>();
|
|
|
|
|
_basic_extractor_types[u_ptr->unitType()] = u_ptr;
|
|
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<AsBitCombine>();
|
|
|
|
|
_basic_extractor_types[u_ptr->unitType()] = u_ptr;
|
2025-08-02 02:42:39 +00:00
|
|
|
|
|
2025-08-05 14:00:41 +00:00
|
|
|
|
u_ptr = std::make_shared<AsString>();
|
2025-08-10 09:02:18 +00:00
|
|
|
|
_basic_extractor_types[u_ptr->unitType()] = u_ptr;
|
2025-08-02 02:42:39 +00:00
|
|
|
|
|
2025-08-05 14:00:41 +00:00
|
|
|
|
u_ptr = std::make_shared<AsHex>();
|
2025-08-10 09:02:18 +00:00
|
|
|
|
_basic_extractor_types[u_ptr->unitType()] = u_ptr;
|
2025-08-02 02:42:39 +00:00
|
|
|
|
this->_default_translate_rule = u_ptr;
|
|
|
|
|
|
|
|
|
|
// size-provider type-list
|
2025-08-03 09:26:53 +00:00
|
|
|
|
std::shared_ptr<SizeProvider> sz_ptr = std::make_shared<ConstNumberProvider>();
|
2025-08-02 02:42:39 +00:00
|
|
|
|
this->_default_size_provider = sz_ptr;
|
|
|
|
|
_size_provider_types[sz_ptr->name()] = sz_ptr;
|
2025-08-03 09:26:53 +00:00
|
|
|
|
|
|
|
|
|
sz_ptr = std::make_shared<InterpretedNumberPrivider>();
|
|
|
|
|
_size_provider_types[sz_ptr->name()] = sz_ptr;
|
2025-08-10 12:32:42 +00:00
|
|
|
|
|
|
|
|
|
// extract-unit type-list
|
|
|
|
|
std::shared_ptr<ExtractUnit> x_ptr = std::make_shared<SingleBasedUnit>();
|
|
|
|
|
_process_unit_types[x_ptr->baseType()] = x_ptr;
|
|
|
|
|
_default_process_unit = x_ptr;
|
|
|
|
|
|
|
|
|
|
x_ptr = std::make_shared<ListBasedUnit>();
|
|
|
|
|
_process_unit_types[x_ptr->baseType()] = x_ptr;
|
|
|
|
|
|
|
|
|
|
x_ptr = std::make_shared<UnionBasedUnit>();
|
|
|
|
|
_process_unit_types[x_ptr->baseType()] = x_ptr;
|
|
|
|
|
|
2025-08-02 02:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-11 14:11:20 +00:00
|
|
|
|
std::shared_ptr<ExtractDelegate> TranslateBasic::defaultExtractDelegateType() const
|
2025-08-02 02:42:39 +00:00
|
|
|
|
{
|
|
|
|
|
return _default_translate_rule;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-11 14:11:20 +00:00
|
|
|
|
QHash<QString, std::shared_ptr<ExtractDelegate>> TranslateBasic::extractDelegateTypeMap() const
|
2025-08-10 09:02:18 +00:00
|
|
|
|
{
|
|
|
|
|
return _basic_extractor_types;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-02 02:42:39 +00:00
|
|
|
|
std::shared_ptr<SizeProvider> TranslateBasic::defaultSizeProvider() const
|
|
|
|
|
{
|
|
|
|
|
return _default_size_provider;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-02 07:02:35 +00:00
|
|
|
|
std::shared_ptr<RuleMatch> TranslateBasic::defaultRuleMatch() const
|
|
|
|
|
{
|
|
|
|
|
return _default_rule_match;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 10:03:02 +00:00
|
|
|
|
void TranslateBasic::addDelegate(std::shared_ptr<ExtractDelegate> inst)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
2025-08-10 09:07:28 +00:00
|
|
|
|
auto repeat_name_count = std::count_if(
|
2025-08-05 03:50:14 +00:00
|
|
|
|
this->_custom_rule_types.begin(), this->_custom_rule_types.end(),
|
2025-08-10 10:03:02 +00:00
|
|
|
|
[=](std::shared_ptr<ExtractDelegate> v) {
|
2025-08-10 09:02:18 +00:00
|
|
|
|
return v->aliasName() == inst->aliasName();
|
2025-08-05 03:50:14 +00:00
|
|
|
|
});
|
|
|
|
|
|
2025-08-10 09:07:28 +00:00
|
|
|
|
if(repeat_name_count)
|
|
|
|
|
throw new BaseException(u8"RuleName<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>");
|
|
|
|
|
|
|
|
|
|
switch (inst->outType()) {
|
|
|
|
|
case DataType::LIST_COLLECTION:
|
|
|
|
|
case DataType::UNION_COMBINATE:
|
|
|
|
|
throw new BaseException(u8"<EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><EFBFBD>ܵ<EFBFBD>ί<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>");
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 03:50:14 +00:00
|
|
|
|
this->_custom_rule_types << inst;
|
2025-08-03 00:04:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
void TranslateBasic::removeDelegate(const QString& typeAlias)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
2025-08-05 03:50:14 +00:00
|
|
|
|
for (auto idxp = 0; idxp< this->_custom_rule_types.size(); idxp++) {
|
|
|
|
|
auto rule = this->_custom_rule_types.at(idxp);
|
2025-08-10 09:02:18 +00:00
|
|
|
|
if (rule->aliasName() == typeAlias) {
|
2025-08-05 03:50:14 +00:00
|
|
|
|
this->_custom_rule_types.removeAt(idxp--);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 12:36:29 +00:00
|
|
|
|
throw new BaseException("ָ<EFBFBD><EFBFBD>RuleName<EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD>");
|
2025-08-03 00:04:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
QList<QString> TranslateBasic::delegateAlias() const
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
2025-08-10 09:02:18 +00:00
|
|
|
|
QList<QString> values;
|
|
|
|
|
std::transform(_custom_rule_types.begin(), _custom_rule_types.end(),
|
2025-08-10 10:03:02 +00:00
|
|
|
|
std::back_inserter(values), [](std::shared_ptr<ExtractDelegate> impl){
|
2025-08-10 09:02:18 +00:00
|
|
|
|
return impl->aliasName();
|
|
|
|
|
});
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 10:03:02 +00:00
|
|
|
|
std::shared_ptr<ExtractDelegate> TranslateBasic::operator[](const QString& name) const
|
2025-08-10 09:02:18 +00:00
|
|
|
|
{
|
|
|
|
|
for(auto ins : _custom_rule_types)
|
|
|
|
|
if(ins->aliasName() == name)
|
|
|
|
|
return ins;
|
|
|
|
|
|
2025-08-10 12:36:29 +00:00
|
|
|
|
throw new BaseException(u8"ָ<EFBFBD><EFBFBD>Name<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
2025-08-10 09:02:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 10:03:02 +00:00
|
|
|
|
void TranslateBasic::replaceDelegate(const QString& name, std::shared_ptr<ExtractDelegate> inst)
|
2025-08-10 09:02:18 +00:00
|
|
|
|
{
|
|
|
|
|
for (auto idx = 0; _custom_rule_types.size(); ++idx) {
|
|
|
|
|
auto rule_inst = _custom_rule_types.at(idx);
|
|
|
|
|
if (rule_inst->aliasName() == name) {
|
|
|
|
|
_custom_rule_types.replace(idx, inst);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 12:36:29 +00:00
|
|
|
|
throw new BaseException(u8"ָ<EFBFBD><EFBFBD>Name<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
2025-08-03 00:04:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 12:32:42 +00:00
|
|
|
|
QHash<QString, std::shared_ptr<SizeProvider>> TranslateBasic::sizeProviderMap() const
|
2025-08-02 02:42:39 +00:00
|
|
|
|
{
|
|
|
|
|
return _size_provider_types;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 12:32:42 +00:00
|
|
|
|
QHash<QString, std::shared_ptr<RuleMatch>> TranslateBasic::ruleMatchMap() const
|
2025-08-02 07:02:35 +00:00
|
|
|
|
{
|
|
|
|
|
return _rule_match_types;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-11 14:11:20 +00:00
|
|
|
|
std::shared_ptr<ExtractUnit> TranslateBasic::defaultExtractUnitType() const
|
2025-08-10 12:32:42 +00:00
|
|
|
|
{
|
|
|
|
|
return _default_process_unit;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-11 14:11:20 +00:00
|
|
|
|
QHash<QString, std::shared_ptr<ExtractUnit>> TranslateBasic::extractUnitTypeMap() const
|
2025-08-10 12:32:42 +00:00
|
|
|
|
{
|
|
|
|
|
return _process_unit_types;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
void ConstNumberProvider::bindInput(std::shared_ptr<DataContext> inst)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
2025-08-04 01:27:04 +00:00
|
|
|
|
|
2025-08-03 00:04:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-02 02:42:39 +00:00
|
|
|
|
QString ConstNumberProvider::name() const
|
|
|
|
|
{
|
2025-08-12 14:47:19 +00:00
|
|
|
|
return topic();
|
2025-08-02 02:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t ConstNumberProvider::value(const QString& expr) const
|
|
|
|
|
{
|
|
|
|
|
return expr.toInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConstNumberProvider::setExpression(const QString& expr)
|
|
|
|
|
{
|
2025-08-02 07:02:35 +00:00
|
|
|
|
this->_number._value_string = expr;
|
2025-08-02 02:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ConstNumberProvider::expression() const
|
|
|
|
|
{
|
2025-08-02 07:02:35 +00:00
|
|
|
|
return this->_number._value_string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConstNumberProvider::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
|
|
|
|
{
|
|
|
|
|
STRING_PEAK(_number._value_string, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConstNumberProvider::saveTo(QJsonObject& obj) const
|
|
|
|
|
{
|
|
|
|
|
STRING_SAVE(_number._value_string, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Serializable> ConstNumberProvider::newDefault() const
|
|
|
|
|
{
|
|
|
|
|
return std::make_shared<ConstNumberProvider>();
|
2025-08-02 02:42:39 +00:00
|
|
|
|
}
|
2025-08-03 00:04:12 +00:00
|
|
|
|
|
2025-08-12 14:47:19 +00:00
|
|
|
|
QString ConstNumberProvider::topic()
|
|
|
|
|
{
|
|
|
|
|
return NAME(ConstNumberProvider);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
void InterpretedNumberPrivider::bindInput(std::shared_ptr<DataContext> inst)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
|
|
|
|
this->_refer._context_inst = inst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString InterpretedNumberPrivider::name() const
|
|
|
|
|
{
|
2025-08-12 14:47:19 +00:00
|
|
|
|
return topic();
|
2025-08-03 00:04:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include <QMetaType>
|
|
|
|
|
int32_t InterpretedNumberPrivider::value(const QString& expr) const
|
|
|
|
|
{
|
2025-08-05 14:48:54 +00:00
|
|
|
|
if (this->_refer._context_inst) {
|
|
|
|
|
auto value = this->_refer._context_inst->get(expr);
|
|
|
|
|
if (value.userType() == QMetaType::Int)
|
|
|
|
|
return value.toInt();
|
|
|
|
|
}
|
2025-08-03 00:04:12 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterpretedNumberPrivider::setExpression(const QString& expr)
|
|
|
|
|
{
|
|
|
|
|
this->_refer._field_refer = expr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString InterpretedNumberPrivider::expression() const
|
|
|
|
|
{
|
|
|
|
|
return this->_refer._field_refer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterpretedNumberPrivider::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
|
|
|
|
|
{
|
|
|
|
|
STRING_PEAK(this->_refer._field_refer, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterpretedNumberPrivider::saveTo(QJsonObject& obj) const
|
|
|
|
|
{
|
|
|
|
|
STRING_SAVE(this->_refer._field_refer, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Serializable> InterpretedNumberPrivider::newDefault() const
|
|
|
|
|
{
|
|
|
|
|
return std::make_shared<InterpretedNumberPrivider>();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-12 14:47:19 +00:00
|
|
|
|
QString InterpretedNumberPrivider::topic()
|
|
|
|
|
{
|
|
|
|
|
return NAME(InterpretedNumberPrivider);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
void ValueAccessContext::init(const QString& field, std::shared_ptr<DataContext> parent)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
|
|
|
|
this->_cascade._current_field = field;
|
|
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
|
parent->setChild(field, this->shared_from_this());
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
void ValueAccessContext::setChild(const QString& field, std::shared_ptr<DataContext> inst)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
2025-08-10 09:02:18 +00:00
|
|
|
|
this->_cascade._children_context << std::make_pair(field, inst);
|
2025-08-03 00:04:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:51:12 +00:00
|
|
|
|
void ValueAccessContext::append(const QVariant& value)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
|
|
|
|
this->_cascade._current_value = value;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 12:32:42 +00:00
|
|
|
|
QList<std::pair<QString, QVariant>> ValueAccessContext::dataSeqs() const
|
2025-08-10 09:02:18 +00:00
|
|
|
|
{
|
2025-08-10 12:32:42 +00:00
|
|
|
|
QList<std::pair<QString, QVariant>> values;
|
|
|
|
|
values << std::make_pair(_cascade._current_field, _cascade._current_value);
|
2025-08-10 09:02:18 +00:00
|
|
|
|
for (auto pair : _cascade._children_context) {
|
|
|
|
|
values << pair.second->dataSeqs();
|
|
|
|
|
}
|
|
|
|
|
return values;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:51:12 +00:00
|
|
|
|
QVariant ValueAccessContext::get(const QString& unique_key) const
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (_cascade._current_field == unique_key)
|
|
|
|
|
return _cascade._current_value;
|
|
|
|
|
|
2025-08-10 09:02:18 +00:00
|
|
|
|
for (auto unit : _cascade._children_context) {
|
|
|
|
|
auto value = unit.second->get(unique_key);
|
2025-08-03 00:04:12 +00:00
|
|
|
|
if (value.isValid())
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 01:27:04 +00:00
|
|
|
|
bool FieldManagerLayer::bindCurrent(const QString& unique_key)
|
|
|
|
|
{
|
|
|
|
|
for (auto index = 0; index < __Private::_fields_map.size(); ++index) {
|
|
|
|
|
auto pair = __Private::_fields_map[index];
|
|
|
|
|
if (pair.first == unique_key) {
|
|
|
|
|
__Private::_fields_map = __Private::_fields_map.mid(0, index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QHash<QString, DataType> FieldManagerLayer::prevFields() const
|
|
|
|
|
{
|
|
|
|
|
QHash<QString, DataType> fields;
|
2025-08-05 03:50:14 +00:00
|
|
|
|
for (auto pair : __Private::_fields_map)
|
2025-08-04 01:27:04 +00:00
|
|
|
|
fields[pair.first] = pair.second;
|
|
|
|
|
|
|
|
|
|
return fields;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FieldManagerLayer::clear()
|
|
|
|
|
{
|
|
|
|
|
__Private::_fields_map.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FieldManagerLayer::FieldManagerLayer(const QString& self, std::shared_ptr<ScopeFieldsSetter> instp)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
|
|
|
|
_setter._rule_name = self;
|
|
|
|
|
_setter._parent_setter = instp;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 01:27:04 +00:00
|
|
|
|
#include <stdexcept>
|
2025-08-10 09:02:18 +00:00
|
|
|
|
void FieldManagerLayer::setField(const QString& fieldName, DataType type)
|
2025-08-03 00:04:12 +00:00
|
|
|
|
{
|
2025-08-04 01:27:04 +00:00
|
|
|
|
if (_setter._parent_setter)
|
2025-08-10 09:02:18 +00:00
|
|
|
|
_setter._parent_setter->setField(QString("%1.%2").arg(_setter._rule_name, fieldName), type);
|
2025-08-04 01:27:04 +00:00
|
|
|
|
else {
|
|
|
|
|
for (auto pair : __Private::_fields_map) {
|
2025-08-10 09:02:18 +00:00
|
|
|
|
if (pair.first == fieldName)
|
2025-08-04 01:27:04 +00:00
|
|
|
|
throw new std::invalid_argument("<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>");
|
|
|
|
|
}
|
2025-08-10 09:02:18 +00:00
|
|
|
|
__Private::_fields_map << std::make_pair(fieldName, type);
|
2025-08-04 01:27:04 +00:00
|
|
|
|
}
|
2025-08-03 00:04:12 +00:00
|
|
|
|
}
|
2025-08-04 01:27:04 +00:00
|
|
|
|
QList<std::pair<QString, DataType>> FieldManagerLayer::__Private::_fields_map;
|