2025-07-14 17:35:53 +00:00
|
|
|
#include "TranslateBasic.h"
|
2025-08-02 02:42:39 +00:00
|
|
|
|
|
|
|
using namespace extract;
|
|
|
|
|
|
|
|
|
|
|
|
TranslateBasic::TranslateBasic()
|
|
|
|
{
|
|
|
|
// extractor type-list
|
|
|
|
std::shared_ptr<ExtractUnit> u_ptr = std::make_shared<BytesAsBitCombine>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsInteger>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsUnsigned>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsString>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsHex>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
this->_default_translate_rule = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsFloat>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsDouble>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsList>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
2025-08-03 00:04:12 +00:00
|
|
|
u_ptr = std::make_shared<BytesAsUnion>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
|
|
|
u_ptr = std::make_shared<BytesAsRuleSet>();
|
|
|
|
_extractor_types[u_ptr->name()] = u_ptr;
|
|
|
|
|
2025-08-02 02:42:39 +00:00
|
|
|
// size-provider type-list
|
|
|
|
auto sz_ptr = std::make_shared<ConstNumberProvider>();
|
|
|
|
this->_default_size_provider = sz_ptr;
|
|
|
|
_size_provider_types[sz_ptr->name()] = sz_ptr;
|
|
|
|
}
|
|
|
|
|
2025-08-02 07:02:35 +00:00
|
|
|
std::shared_ptr<ExtractUnit> TranslateBasic::defaultExtractUnit() const
|
2025-08-02 02:42:39 +00:00
|
|
|
{
|
|
|
|
return _default_translate_rule;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<QString, std::shared_ptr<ExtractUnit>> TranslateBasic::extractUnitList() const
|
2025-08-02 02:42:39 +00:00
|
|
|
{
|
|
|
|
return _extractor_types;
|
|
|
|
}
|
|
|
|
|
2025-08-03 00:04:12 +00:00
|
|
|
void TranslateBasic::setCustomRule(const QString& name, std::shared_ptr<ExtractUnit> inst)
|
|
|
|
{
|
|
|
|
this->_extractor_types[name] = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TranslateBasic::removeCustomRule(const QString& name)
|
|
|
|
{
|
|
|
|
_extractor_types.remove(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<QString, std::shared_ptr<RuleMatch>> TranslateBasic::customRules() const
|
|
|
|
{
|
|
|
|
return this->_custom_rule_types;
|
|
|
|
}
|
|
|
|
|
2025-08-02 07:02:35 +00:00
|
|
|
QHash<QString, std::shared_ptr<SizeProvider>> TranslateBasic::sizeProviderList() const
|
2025-08-02 02:42:39 +00:00
|
|
|
{
|
|
|
|
return _size_provider_types;
|
|
|
|
}
|
|
|
|
|
2025-08-02 07:02:35 +00:00
|
|
|
QHash<QString, std::shared_ptr<RuleMatch>> TranslateBasic::ruleMatchList() const
|
|
|
|
{
|
|
|
|
return _rule_match_types;
|
|
|
|
}
|
|
|
|
|
2025-08-03 00:04:12 +00:00
|
|
|
void ConstNumberProvider::bindInput(std::shared_ptr<DataAccessContext> inst)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-08-02 02:42:39 +00:00
|
|
|
QString ConstNumberProvider::name() const
|
|
|
|
{
|
|
|
|
return NAME(ConstNumberProvider);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void InterpretedNumberPrivider::bindInput(std::shared_ptr<DataAccessContext> inst)
|
|
|
|
{
|
|
|
|
this->_refer._context_inst = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString InterpretedNumberPrivider::name() const
|
|
|
|
{
|
|
|
|
return NAME(InterpretedNumberPrivider);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <QMetaType>
|
|
|
|
int32_t InterpretedNumberPrivider::value(const QString& expr) const
|
|
|
|
{
|
|
|
|
auto value = this->_refer._context_inst->get(expr);
|
|
|
|
if (value.userType() == QMetaType::Int)
|
|
|
|
return value.toInt();
|
|
|
|
|
|
|
|
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>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValueAccess::init(const QString& field, std::shared_ptr<DataAccessContext> parent)
|
|
|
|
{
|
|
|
|
this->_cascade._current_field = field;
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
parent->setChild(field, this->shared_from_this());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValueAccess::setChild(const QString& field, std::shared_ptr<DataAccessContext> inst)
|
|
|
|
{
|
|
|
|
this->_cascade._children_context[field] = inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValueAccess::append(const QVariant& value)
|
|
|
|
{
|
|
|
|
this->_cascade._current_value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ValueAccess::get(const QString& unique_key) const
|
|
|
|
{
|
|
|
|
if (_cascade._current_field == unique_key)
|
|
|
|
return _cascade._current_value;
|
|
|
|
|
|
|
|
for (auto unit : _cascade._children_context)
|
|
|
|
{
|
|
|
|
auto value = unit->get(unique_key);
|
|
|
|
if (value.isValid())
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldSetterLayer::FieldSetterLayer(const QString& self, std::shared_ptr<ScopeFieldsSetter> instp)
|
|
|
|
{
|
|
|
|
_setter._rule_name = self;
|
|
|
|
_setter._parent_setter = instp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FieldSetterLayer::setField(const QString& name, DataType type)
|
|
|
|
{
|
|
|
|
_setter._parent_setter->setField(QString("%1.%2").arg(_setter._rule_name, name), type);
|
|
|
|
}
|