This commit is contained in:
codeboss 2025-08-05 22:00:41 +08:00
parent 22e0dffd1d
commit 50b3563652
10 changed files with 257 additions and 174 deletions

View File

@ -71,10 +71,10 @@ void RuleSetCustom::peersRuleChanged(const QModelIndex& idx)
_view._ruleset->replace(idx.row(), std::make_pair(field_name, new_inst)); _view._ruleset->replace(idx.row(), std::make_pair(field_name, new_inst));
// ¶ÔListUnitÖ´ÐÐÌØÊâ³õʼ»¯²½Öè // ¶ÔListUnitÖ´ÐÐÌØÊâ³õʼ»¯²½Öè
if (typeid(*new_inst.get()) == typeid(BytesAsList)) { if (typeid(*new_inst.get()) == typeid(AsList)) {
auto conv = std::dynamic_pointer_cast<BytesAsList>(new_inst); auto conv = std::dynamic_pointer_cast<AsList>(new_inst);
if (!conv->elementRule()) { if (!conv->elementRule()) {
conv->appendElementRule(this->_view.base->defaultExtractUnit()); conv->setElementRule(this->_view.base->defaultExtractUnit());
} }
if (!conv->sizeProvider()) { if (!conv->sizeProvider()) {
@ -93,7 +93,7 @@ void RuleSetCustom::showEvent(QShowEvent* e)
} }
RuleSetCustom::RuleSetCustom(std::shared_ptr<TranslateBasic> base, RuleSetCustom::RuleSetCustom(std::shared_ptr<TranslateBasic> base,
std::shared_ptr<extract::BytesAsRuleSet> rule_set, QWidget* p /*= nullptr*/) std::shared_ptr<extract::AsRuleSet> rule_set, QWidget* p /*= nullptr*/)
:QTableView(p) :QTableView(p)
{ {
_view._ruleset = rule_set; _view._ruleset = rule_set;
@ -138,7 +138,7 @@ void RuleSetCustom::addTranslateUnit()
QString(u8"rule_%1").arg(_view._ruleset->memberCount()), QString(u8"rule_%1").arg(_view._ruleset->memberCount()),
std::static_pointer_cast<ExtractUnit>(curr_rule)); std::static_pointer_cast<ExtractUnit>(curr_rule));
auto hex_rule = std::static_pointer_cast<BytesAsHex>(curr_rule); auto hex_rule = std::static_pointer_cast<AsHex>(curr_rule);
hex_rule->setCountWithin(1); hex_rule->setCountWithin(1);
membersPresent(this->_view._ruleset, this->_view._seqs_model); membersPresent(this->_view._ruleset, this->_view._seqs_model);
@ -154,7 +154,7 @@ void RuleSetCustom::removeTranslateUnit()
_view._seqs_model->removeRow(idx_curr.row()); _view._seqs_model->removeRow(idx_curr.row());
} }
void RuleSetCustom::membersPresent(std::shared_ptr<extract::BytesAsRuleSet> ruleset, QStandardItemModel* model) void RuleSetCustom::membersPresent(std::shared_ptr<extract::AsRuleSet> ruleset, QStandardItemModel* model)
{ {
model->removeRows(0, model->rowCount()); model->removeRows(0, model->rowCount());

View File

@ -58,7 +58,7 @@ private:
struct __Private { struct __Private {
QStandardItemModel* _seqs_model; QStandardItemModel* _seqs_model;
std::shared_ptr<TranslateBasic> base = nullptr; std::shared_ptr<TranslateBasic> base = nullptr;
std::shared_ptr<extract::BytesAsRuleSet> _ruleset = nullptr; std::shared_ptr<extract::AsRuleSet> _ruleset = nullptr;
} _view; } _view;
signals: signals:
@ -73,12 +73,12 @@ protected:
public: public:
RuleSetCustom(std::shared_ptr<TranslateBasic> base, RuleSetCustom(std::shared_ptr<TranslateBasic> base,
std::shared_ptr<extract::BytesAsRuleSet> rule_set, QWidget* p = nullptr); std::shared_ptr<extract::AsRuleSet> rule_set, QWidget* p = nullptr);
void customTranslateRuleEdit(const QPoint& pos); void customTranslateRuleEdit(const QPoint& pos);
void addTranslateUnit(); void addTranslateUnit();
void removeTranslateUnit(); void removeTranslateUnit();
void membersPresent(std::shared_ptr<extract::BytesAsRuleSet> _bind, QStandardItemModel* model); void membersPresent(std::shared_ptr<extract::AsRuleSet> _bind, QStandardItemModel* model);
}; };

View File

@ -13,7 +13,7 @@ using namespace size_provider;
ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base, ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
std::shared_ptr<extract::BytesAsRuleSet> inst_r, QWidget* p /*= nullptr*/) std::shared_ptr<extract::AsRuleSet> inst_r, QWidget* p /*= nullptr*/)
: QWidget(p), _rule_base(inst_r), : QWidget(p), _rule_base(inst_r),
_sequence_view(new RuleSetCustom(base, inst_r, this)), _sequence_view(new RuleSetCustom(base, inst_r, this)),
_configs_stack(new QStackedWidget(this)) _configs_stack(new QStackedWidget(this))
@ -43,17 +43,19 @@ ExtractRuleView::ExtractRuleView(std::shared_ptr<TranslateBasic> base,
_sequence_view, &RuleSetCustom::targetRuleRefresh); _sequence_view, &RuleSetCustom::targetRuleRefresh);
connect(combine_config, &BitCombineConfiguration::currentRuleChanged, connect(combine_config, &BitCombineConfiguration::currentRuleChanged,
_sequence_view, &RuleSetCustom::targetRuleRefresh); _sequence_view, &RuleSetCustom::targetRuleRefresh);
connect(list_config, &ListUnitConfiguration::currentRuleChanged,
_sequence_view, &RuleSetCustom::targetRuleRefresh);
connect(_sequence_view, &RuleSetCustom::currentRuleChanged, connect(_sequence_view, &RuleSetCustom::currentRuleChanged,
[=](std::shared_ptr<ExtractUnit> u, const QModelIndex& i) { [=](std::shared_ptr<ExtractUnit> u, const QModelIndex& i) {
switch (u->outType()) { switch (u->outType()) {
case DataType::TextString: case DataType::TextString:
if (typeid(*u.get()) == typeid(extract::BytesAsString)) { if (typeid(*u.get()) == typeid(extract::AsString)) {
_configs_stack->setCurrentIndex(2); _configs_stack->setCurrentIndex(2);
encode_config->currentRuleAccept(u, i); encode_config->currentRuleAccept(u, i);
break; break;
} }
else if (typeid(*u.get()) == typeid(extract::BytesAsBitCombine)) { else if (typeid(*u.get()) == typeid(extract::AsBitCombine)) {
_configs_stack->setCurrentIndex(3); _configs_stack->setCurrentIndex(3);
combine_config->currentRuleAccept(u, i); combine_config->currentRuleAccept(u, i);
break; break;
@ -86,7 +88,7 @@ void ExtractRuleView::cacheRefresh(const QModelIndex& curr, ListUnitConfiguratio
this->_current_fields_cache->bindCurrent(field_idx.data(Qt::DisplayRole).toString()); this->_current_fields_cache->bindCurrent(field_idx.data(Qt::DisplayRole).toString());
auto ins = this->_rule_base->operator[](curr.row()); auto ins = this->_rule_base->operator[](curr.row());
auto conv = std::dynamic_pointer_cast<extract::BytesAsList>(ins.second); auto conv = std::dynamic_pointer_cast<extract::AsList>(ins.second);
if (conv) { if (conv) {
t->currentRuleAccept(conv, curr, this->_current_fields_cache); t->currentRuleAccept(conv, curr, this->_current_fields_cache);
} }
@ -160,7 +162,7 @@ EncodingConfiguration::EncodingConfiguration(QWidget* p /*= nullptr*/)
connect(_encoding_set, QOverload<const QString&>::of(&QComboBox::currentIndexChanged), connect(_encoding_set, QOverload<const QString&>::of(&QComboBox::currentIndexChanged),
[=](const QString& value) { [=](const QString& value) {
if (this->_bind_u) { if (this->_bind_u) {
auto ptr = std::dynamic_pointer_cast<extract::BytesAsString>(this->_bind_u); auto ptr = std::dynamic_pointer_cast<extract::AsString>(this->_bind_u);
if (ptr) { if (ptr) {
auto insx = QTextCodec::codecForName(value.toUtf8()); auto insx = QTextCodec::codecForName(value.toUtf8());
ptr->setStrCodec(insx); ptr->setStrCodec(insx);
@ -176,7 +178,7 @@ void EncodingConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, co
this->_bind_index = i; this->_bind_index = i;
_count_input->setValue(u->countWithin()); _count_input->setValue(u->countWithin());
auto codec_name = std::dynamic_pointer_cast<extract::BytesAsString>(u)->codecName(); auto codec_name = std::dynamic_pointer_cast<extract::AsString>(u)->codecName();
QSignalBlocker x(this->_encoding_set); QSignalBlocker x(this->_encoding_set);
this->_encoding_set->setCurrentText(codec_name); this->_encoding_set->setCurrentText(codec_name);
@ -246,13 +248,13 @@ BitCombineConfiguration::BitCombineConfiguration(QWidget* p /*= nullptr*/)
void BitCombineConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i) void BitCombineConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i)
{ {
this->_bind_u = std::dynamic_pointer_cast<extract::BytesAsBitCombine>(u);; this->_bind_u = std::dynamic_pointer_cast<extract::AsBitCombine>(u);;
this->_bind_index = i; this->_bind_index = i;
this->reloadContent(this->_bind_u); this->reloadContent(this->_bind_u);
} }
void BitCombineConfiguration::reloadContent(std::shared_ptr<extract::BytesAsBitCombine> u) void BitCombineConfiguration::reloadContent(std::shared_ptr<extract::AsBitCombine> u)
{ {
this->_count_input->setValue(u->countWithin()); this->_count_input->setValue(u->countWithin());
this->_index_appoint->setRange(0, u->countWithin() * 8); this->_index_appoint->setRange(0, u->countWithin() * 8);
@ -306,7 +308,8 @@ ListUnitConfiguration::ListUnitConfiguration(
for (auto key : this->_bind_core->customRules().keys()) for (auto key : this->_bind_core->customRules().keys())
_rule_select->addItem(key, CUSTOM_RULE); _rule_select->addItem(key, CUSTOM_RULE);
for (auto key : this->_bind_core->extractUnitList().keys()) for (auto key : this->_bind_core->extractUnitList().keys())
_rule_select->addItem(key, BASIC_RULE); if (!QList<QString>{"AsList", "AsUnion", "AsRuleSet"}.contains(key))
_rule_select->addItem(key, BASIC_RULE);
auto keys = this->_bind_core->sizeProviderList().keys(); auto keys = this->_bind_core->sizeProviderList().keys();
std::sort(keys.begin(), keys.end()); std::sort(keys.begin(), keys.end());
@ -316,41 +319,59 @@ ListUnitConfiguration::ListUnitConfiguration(
[=](int idx) { [=](int idx) {
this->_configs_stack->setCurrentIndex(this->_size_layout_select->currentIndex()); this->_configs_stack->setCurrentIndex(this->_size_layout_select->currentIndex());
}); });
connect(this->_rule_select, &QComboBox::currentTextChanged,
this, &ListUnitConfiguration::elmRuleSet);
} }
void ListUnitConfiguration::currentRuleAccept( void ListUnitConfiguration::currentRuleAccept(std::shared_ptr<ExtractUnit> u,
std::shared_ptr<ExtractUnit> u, const QModelIndex& i, const QModelIndex& i, std::shared_ptr<ScopeFieldsGetter> getter)
std::shared_ptr<ScopeFieldsGetter> getter)
{ {
this->_bind_u = std::dynamic_pointer_cast<extract::BytesAsList>(u); this->_bind_u = std::dynamic_pointer_cast<extract::AsList>(u);
this->_bind_index = i; this->_bind_index = i;
reloadContent(this->_bind_u, getter); reloadContent(this->_bind_u, getter);
} }
void ListUnitConfiguration::reloadContent( void ListUnitConfiguration::reloadContent(std::shared_ptr<extract::AsList> u,
std::shared_ptr<extract::BytesAsList> u,
std::shared_ptr<ScopeFieldsGetter> getter) std::shared_ptr<ScopeFieldsGetter> getter)
{ {
QSignalBlocker v(_rule_select); QSignalBlocker v(_rule_select);
_rule_select->setCurrentText(u->elementRule()->name()); _rule_select->setCurrentText(u->elementRule()->name());
QSignalBlocker m(_size_layout_select); QSignalBlocker m(_size_layout_select);
_size_layout_select->setCurrentText(u->sizeProvider()->name()); _size_layout_select->setCurrentText(u->sizeProvider()->name());
QSignalBlocker vll(_prev_field_refer); QSignalBlocker vll(_prev_field_refer);
auto item_list = getter->prevFields(); auto item_list = getter->prevFields();
this->_prev_field_refer->clear(); this->_prev_field_refer->clear();
this->_prev_field_refer->addItems(item_list.keys()); this->_prev_field_refer->addItems(item_list.keys());
if (typeid(*u->sizeProvider().get()) == typeid(ConstNumberProvider)) { auto const_conv = std::dynamic_pointer_cast<ConstNumberProvider>(u->sizeProvider());
if (const_conv) {
_configs_stack->setCurrentIndex(0); _configs_stack->setCurrentIndex(0);
QSignalBlocker v(_const_number_input); QSignalBlocker v(_const_number_input);
auto conv = std::dynamic_pointer_cast<ConstNumberProvider>(u->sizeProvider()); _const_number_input->setValue(const_conv->value(const_conv->expression()));
_const_number_input->setValue(conv->value(conv->expression()));
} }
else if (typeid(*u->sizeProvider().get()) == typeid(InterpretedNumberPrivider)) {
auto runtime_conv = std::dynamic_pointer_cast<InterpretedNumberPrivider>(u->sizeProvider());
if (runtime_conv) {
_configs_stack->setCurrentIndex(1); _configs_stack->setCurrentIndex(1);
auto conv = std::dynamic_pointer_cast<InterpretedNumberPrivider>(u->sizeProvider()); this->_prev_field_refer->setCurrentText(runtime_conv->name());
this->_prev_field_refer->setCurrentText(conv->name());
} }
} }
void ListUnitConfiguration::elmRuleSet(const QString& name)
{
auto type_mark = this->_rule_select->currentData().toInt();
switch (type_mark) {
case CUSTOM_RULE: {
auto target_rule = this->_bind_core->customRules()[name];
_bind_u->setElementRule(target_rule);
}break;
default: {
auto target_unit = this->_bind_core->extractUnitList()[name];
_bind_u->setElementRule(target_unit);
}break;
}
emit this->currentRuleChanged(this->_bind_index);
}

View File

@ -64,7 +64,7 @@ namespace configuration_panel {
class BitCombineConfiguration : public QWidget { class BitCombineConfiguration : public QWidget {
Q_OBJECT Q_OBJECT
private: private:
std::shared_ptr<extract::BytesAsBitCombine> _bind_u; std::shared_ptr<extract::AsBitCombine> _bind_u;
QModelIndex _bind_index; QModelIndex _bind_index;
QSpinBox* const _count_input; QSpinBox* const _count_input;
@ -77,7 +77,7 @@ namespace configuration_panel {
BitCombineConfiguration(QWidget* p = nullptr); BitCombineConfiguration(QWidget* p = nullptr);
void currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i); void currentRuleAccept(std::shared_ptr<ExtractUnit> u, const QModelIndex& i);
void reloadContent(std::shared_ptr<extract::BytesAsBitCombine> u); void reloadContent(std::shared_ptr<extract::AsBitCombine> u);
signals: signals:
void currentRuleChanged(const QModelIndex& idx); void currentRuleChanged(const QModelIndex& idx);
@ -90,7 +90,7 @@ namespace configuration_panel {
Q_OBJECT Q_OBJECT
private: private:
std::shared_ptr<TranslateBasic> _bind_core; std::shared_ptr<TranslateBasic> _bind_core;
std::shared_ptr<extract::BytesAsList> _bind_u; std::shared_ptr<extract::AsList> _bind_u;
QModelIndex _bind_index; QModelIndex _bind_index;
QComboBox* const _rule_select; QComboBox* const _rule_select;
@ -100,6 +100,8 @@ namespace configuration_panel {
QSpinBox* const _const_number_input; QSpinBox* const _const_number_input;
QComboBox* const _prev_field_refer; QComboBox* const _prev_field_refer;
void elmRuleSet(const QString &name);
public: public:
ListUnitConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p = nullptr); ListUnitConfiguration(std::shared_ptr<TranslateBasic> core, QWidget* p = nullptr);
@ -107,7 +109,7 @@ namespace configuration_panel {
std::shared_ptr<ExtractUnit> u, std::shared_ptr<ExtractUnit> u,
const QModelIndex& i, const QModelIndex& i,
std::shared_ptr<ScopeFieldsGetter> getter); std::shared_ptr<ScopeFieldsGetter> getter);
void reloadContent(std::shared_ptr<extract::BytesAsList> u, void reloadContent(std::shared_ptr<extract::AsList> u,
std::shared_ptr<ScopeFieldsGetter> getter); std::shared_ptr<ScopeFieldsGetter> getter);
signals: signals:
@ -121,12 +123,12 @@ private:
RuleSetCustom* const _sequence_view; RuleSetCustom* const _sequence_view;
QStackedWidget* const _configs_stack; QStackedWidget* const _configs_stack;
std::shared_ptr<extract::BytesAsRuleSet> _rule_base; std::shared_ptr<extract::AsRuleSet> _rule_base;
std::shared_ptr<FieldManagerLayer> _current_fields_cache = nullptr; std::shared_ptr<FieldManagerLayer> _current_fields_cache = nullptr;
public: public:
ExtractRuleView(std::shared_ptr<TranslateBasic> base, ExtractRuleView(std::shared_ptr<TranslateBasic> base,
std::shared_ptr<extract::BytesAsRuleSet> inst_r, QWidget* p = nullptr); std::shared_ptr<extract::AsRuleSet> inst_r, QWidget* p = nullptr);
void cacheRefresh(const QModelIndex& curr, configuration_panel::ListUnitConfiguration* t); void cacheRefresh(const QModelIndex& curr, configuration_panel::ListUnitConfiguration* t);
}; };

View File

@ -6,35 +6,35 @@ using namespace size_provider;
TranslateBasic::TranslateBasic() TranslateBasic::TranslateBasic()
{ {
// extractor type-list // extractor type-list
std::shared_ptr<ExtractUnit> u_ptr = std::make_shared<BytesAsBitCombine>(); std::shared_ptr<ExtractUnit> u_ptr = std::make_shared<AsBitCombine>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsInteger>(); u_ptr = std::make_shared<AsInteger>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsUnsigned>(); u_ptr = std::make_shared<AsUnsigned>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsString>(); u_ptr = std::make_shared<AsString>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsHex>(); u_ptr = std::make_shared<AsHex>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
this->_default_translate_rule = u_ptr; this->_default_translate_rule = u_ptr;
u_ptr = std::make_shared<BytesAsFloat>(); u_ptr = std::make_shared<AsFloat>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsDouble>(); u_ptr = std::make_shared<AsDouble>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsList>(); u_ptr = std::make_shared<AsList>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsUnion>(); u_ptr = std::make_shared<AsUnion>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
u_ptr = std::make_shared<BytesAsRuleSet>(); u_ptr = std::make_shared<AsRuleSet>();
_extractor_types[u_ptr->name()] = u_ptr; _extractor_types[u_ptr->name()] = u_ptr;
// size-provider type-list // size-provider type-list
@ -66,11 +66,11 @@ QHash<QString, std::shared_ptr<ExtractUnit>> TranslateBasic::extractUnitList() c
return _extractor_types; return _extractor_types;
} }
void TranslateBasic::setCustomRule(const QString& name, std::shared_ptr<extract::BytesAsRuleSet> inst) void TranslateBasic::setCustomRule(const QString& name, std::shared_ptr<extract::AsRuleSet> inst)
{ {
auto exist = std::count_if( auto exist = std::count_if(
this->_custom_rule_types.begin(), this->_custom_rule_types.end(), this->_custom_rule_types.begin(), this->_custom_rule_types.end(),
[=](std::shared_ptr<extract::BytesAsRuleSet> v) { [=](std::shared_ptr<extract::AsRuleSet> v) {
return v->name() == name; return v->name() == name;
}); });
assert("RuleName²»ÄÜÖØ¸´" && !exist); assert("RuleName²»ÄÜÖØ¸´" && !exist);
@ -92,9 +92,9 @@ void TranslateBasic::removeCustomRule(const QString& name)
assert("Ö¸¶¨RuleName²»ºÏ·¨" && 0); assert("Ö¸¶¨RuleName²»ºÏ·¨" && 0);
} }
QHash<QString, std::shared_ptr<extract::BytesAsRuleSet>> TranslateBasic::customRules() const QHash<QString, std::shared_ptr<extract::AsRuleSet>> TranslateBasic::customRules() const
{ {
QHash<QString, std::shared_ptr<extract::BytesAsRuleSet>> value_set; QHash<QString, std::shared_ptr<extract::AsRuleSet>> value_set;
for (auto instv : this->_custom_rule_types) for (auto instv : this->_custom_rule_types)
value_set[instv->customName()] = instv; value_set[instv->customName()] = instv;
return value_set; return value_set;

View File

@ -113,7 +113,7 @@ private:
QHash<QString, std::shared_ptr<RuleMatch>> _rule_match_types; QHash<QString, std::shared_ptr<RuleMatch>> _rule_match_types;
std::shared_ptr<RuleMatch> _default_rule_match = nullptr; std::shared_ptr<RuleMatch> _default_rule_match = nullptr;
QList<std::shared_ptr<extract::BytesAsRuleSet>> _custom_rule_types; QList<std::shared_ptr<extract::AsRuleSet>> _custom_rule_types;
public: public:
TranslateBasic(); TranslateBasic();
@ -126,9 +126,9 @@ public:
std::shared_ptr<ExtractUnit> defaultExtractUnit() const; std::shared_ptr<ExtractUnit> defaultExtractUnit() const;
QHash<QString, std::shared_ptr<ExtractUnit>> extractUnitList() const; QHash<QString, std::shared_ptr<ExtractUnit>> extractUnitList() const;
void setCustomRule(const QString& name, std::shared_ptr<extract::BytesAsRuleSet> inst); void setCustomRule(const QString& name, std::shared_ptr<extract::AsRuleSet> inst);
void removeCustomRule(const QString& name); void removeCustomRule(const QString& name);
QHash<QString, std::shared_ptr<extract::BytesAsRuleSet>> customRules() const; QHash<QString, std::shared_ptr<extract::AsRuleSet>> customRules() const;
}; };
namespace size_provider { namespace size_provider {

View File

@ -62,7 +62,7 @@ void TranslateUI::addCustomRule()
return; return;
} }
auto new_rule = std::make_shared<extract::BytesAsRuleSet>(); auto new_rule = std::make_shared<extract::AsRuleSet>();
new_rule->setCustomName(name); new_rule->setCustomName(name);
_core._translate_core->setCustomRule(name, new_rule); _core._translate_core->setCustomRule(name, new_rule);

View File

@ -18,7 +18,7 @@ class ViewManager : public QObject {
Q_OBJECT Q_OBJECT
private: private:
std::shared_ptr<TranslateBasic> _translate_core = nullptr; std::shared_ptr<TranslateBasic> _translate_core = nullptr;
QList<std::tuple<std::shared_ptr<extract::BytesAsRuleSet>, QWidget*, ViewType>> content_pages; QList<std::tuple<std::shared_ptr<extract::AsRuleSet>, QWidget*, ViewType>> content_pages;
public: public:
ViewManager(std::shared_ptr<TranslateBasic> base, QObject* p = nullptr); ViewManager(std::shared_ptr<TranslateBasic> base, QObject* p = nullptr);

View File

@ -60,13 +60,12 @@ void AbstractExtractor::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
} }
BytesAsHex::BytesAsHex() AsHex::AsHex(): AbstractExtractor(topic(), DataType::TextString) {
: AbstractExtractor(NAME(BytesAsHex), DataType::TextString) {
setCountWithin(1); setCountWithin(1);
} }
#include "TranslateBasic.h" #include "TranslateBasic.h"
void BytesAsHex::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsHex::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
QString result; QString result;
for (auto char_v : bytes) { for (auto char_v : bytes) {
@ -75,18 +74,23 @@ void BytesAsHex::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContex
out->append(result); out->append(result);
} }
std::shared_ptr<Serializable> BytesAsHex::newDefault() const std::shared_ptr<Serializable> AsHex::newDefault() const
{ {
return std::make_shared<BytesAsHex>(); return std::make_shared<AsHex>();
} }
BytesAsBitCombine::BytesAsBitCombine() QString AsHex::topic()
: AbstractExtractor(NAME(BytesAsBitCombine), DataType::TextString) {
return NAME(AsHex);
}
AsBitCombine::AsBitCombine()
: AbstractExtractor(topic(), DataType::TextString)
{ {
} }
bool BytesAsBitCombine::setSwitchOption(int bit_index, const QString& keyword) bool AsBitCombine::setSwitchOption(int bit_index, const QString& keyword)
{ {
if (bit_index >= 0 && bit_index <= this->countWithin() * 8) { if (bit_index >= 0 && bit_index <= this->countWithin() * 8) {
_combine._switch_options[bit_index] = keyword; _combine._switch_options[bit_index] = keyword;
@ -95,17 +99,17 @@ bool BytesAsBitCombine::setSwitchOption(int bit_index, const QString& keyword)
return false; return false;
} }
QHash<int, QString> BytesAsBitCombine::switchOptions() const QHash<int, QString> AsBitCombine::switchOptions() const
{ {
return _combine._switch_options; return _combine._switch_options;
} }
void BytesAsBitCombine::clearOptions() void AsBitCombine::clearOptions()
{ {
_combine._switch_options.clear(); _combine._switch_options.clear();
} }
void BytesAsBitCombine::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsBitCombine::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
auto keys = _combine._switch_options.keys(); auto keys = _combine._switch_options.keys();
std::sort(keys.begin(), keys.end()); std::sort(keys.begin(), keys.end());
@ -124,7 +128,7 @@ void BytesAsBitCombine::parse(const QByteArray& bytes, std::shared_ptr<DataAcces
} }
#include <QJsonArray> #include <QJsonArray>
void BytesAsBitCombine::loadFrom( void AsBitCombine::loadFrom(
std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
{ {
AbstractExtractor::loadFrom(core, obj); AbstractExtractor::loadFrom(core, obj);
@ -140,7 +144,7 @@ void BytesAsBitCombine::loadFrom(
} }
} }
void BytesAsBitCombine::saveTo(QJsonObject& obj) const void AsBitCombine::saveTo(QJsonObject& obj) const
{ {
AbstractExtractor::saveTo(obj); AbstractExtractor::saveTo(obj);
@ -154,27 +158,32 @@ void BytesAsBitCombine::saveTo(QJsonObject& obj) const
ARRAY_SAVE(arr, obj); ARRAY_SAVE(arr, obj);
} }
std::shared_ptr<Serializable> BytesAsBitCombine::newDefault() const std::shared_ptr<Serializable> AsBitCombine::newDefault() const
{ {
return std::make_shared<BytesAsBitCombine>(); return std::make_shared<AsBitCombine>();
} }
std::shared_ptr<Serializable> BytesAsInteger::newDefault() const QString AsBitCombine::topic()
{ {
return std::make_shared<BytesAsInteger>(); return NAME(AsBitCombine);
} }
BytesAsInteger::BytesAsInteger() std::shared_ptr<Serializable> AsInteger::newDefault() const
:AbstractExtractor(NAME(BytesAsInteger), DataType::Integer) { {
return std::make_shared<AsInteger>();
} }
bool BytesAsInteger::setCountWithin(int bytes) AsInteger::AsInteger()
:AbstractExtractor(topic(), DataType::Integer) {
}
bool AsInteger::setCountWithin(int bytes)
{ {
bytes = std::min(8, std::max(bytes, 0)); bytes = std::min(8, std::max(bytes, 0));
return AbstractExtractor::setCountWithin(bytes); return AbstractExtractor::setCountWithin(bytes);
} }
void BytesAsInteger::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsInteger::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
auto last = bytes[bytes.size() - 1]; auto last = bytes[bytes.size() - 1];
auto mark = last == 0 ? 0 : last / std::abs(last); auto mark = last == 0 ? 0 : last / std::abs(last);
@ -197,30 +206,35 @@ void BytesAsInteger::parse(const QByteArray& bytes, std::shared_ptr<DataAccessCo
out->append(*((long long*)(&value))); out->append(*((long long*)(&value)));
} }
QString AsInteger::topic()
{
return NAME(AsInteger);
}
#include <QTextCodec> #include <QTextCodec>
BytesAsString::BytesAsString() AsString::AsString()
:AbstractExtractor(NAME(BytesAsString), DataType::TextString) { :AbstractExtractor(topic(), DataType::TextString) {
_strings._conv_with = QTextCodec::codecForName("GBK"); _strings._conv_with = QTextCodec::codecForName("GBK");
} }
void BytesAsString::setStrCodec(QTextCodec* ins) void AsString::setStrCodec(QTextCodec* ins)
{ {
this->_strings._conv_with = ins; this->_strings._conv_with = ins;
} }
QString BytesAsString::codecName() const QString AsString::codecName() const
{ {
return this->_strings._conv_with->name(); return this->_strings._conv_with->name();
} }
void BytesAsString::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsString::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
auto v = _strings._conv_with->toUnicode(bytes); auto v = _strings._conv_with->toUnicode(bytes);
out->append(v); out->append(v);
} }
void BytesAsString::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) void AsString::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
{ {
AbstractExtractor::loadFrom(core, obj); AbstractExtractor::loadFrom(core, obj);
@ -229,7 +243,7 @@ void BytesAsString::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonOb
this->_strings._conv_with = QTextCodec::codecForName(codec_name.toLatin1()); this->_strings._conv_with = QTextCodec::codecForName(codec_name.toLatin1());
} }
void BytesAsString::saveTo(QJsonObject& obj) const void AsString::saveTo(QJsonObject& obj) const
{ {
AbstractExtractor::saveTo(obj); AbstractExtractor::saveTo(obj);
@ -237,56 +251,71 @@ void BytesAsString::saveTo(QJsonObject& obj) const
STRING_SAVE(codec_name, obj); STRING_SAVE(codec_name, obj);
} }
std::shared_ptr<Serializable> BytesAsString::newDefault() const std::shared_ptr<Serializable> AsString::newDefault() const
{ {
return std::make_shared<BytesAsString>(); return std::make_shared<AsString>();
} }
void BytesAsFloat::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const QString AsString::topic()
{
return NAME(AsString);
}
void AsFloat::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
out->append(*((float*)bytes.data())); out->append(*((float*)bytes.data()));
} }
std::shared_ptr<Serializable> BytesAsFloat::newDefault() const std::shared_ptr<Serializable> AsFloat::newDefault() const
{ {
return std::make_shared<BytesAsFloat>(); return std::make_shared<AsFloat>();
} }
BytesAsFloat::BytesAsFloat() AsFloat::AsFloat()
:AbstractExtractor(NAME(BytesAsFloat), DataType::Flt32) :AbstractExtractor(topic(), DataType::Flt32)
{ {
this->setCountWithin(4); this->setCountWithin(4);
} }
std::shared_ptr<Serializable> BytesAsDouble::newDefault() const QString AsFloat::topic()
{ {
return std::make_shared<BytesAsDouble>(); return NAME(AsFloat);
} }
void BytesAsDouble::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const std::shared_ptr<Serializable> AsDouble::newDefault() const
{
return std::make_shared<AsDouble>();
}
void AsDouble::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
out->append(*((double*)bytes.data())); out->append(*((double*)bytes.data()));
} }
BytesAsDouble::BytesAsDouble() AsDouble::AsDouble()
:AbstractExtractor(NAME(BytesAsDouble), DataType::Dbl64) :AbstractExtractor(topic(), DataType::Dbl64)
{ {
this->setCountWithin(8); this->setCountWithin(8);
} }
BytesAsUnsigned::BytesAsUnsigned() QString AsDouble::topic()
:AbstractExtractor(NAME(BytesAsUnsigned), DataType::Unsigned) {
return NAME(AsDouble);
}
AsUnsigned::AsUnsigned()
:AbstractExtractor(topic(), DataType::Unsigned)
{ {
} }
bool BytesAsUnsigned::setCountWithin(int bytes) bool AsUnsigned::setCountWithin(int bytes)
{ {
auto count = std::max(1, std::min(8, bytes)); auto count = std::max(1, std::min(8, bytes));
return AbstractExtractor::setCountWithin(count); return AbstractExtractor::setCountWithin(count);
} }
void BytesAsUnsigned::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsUnsigned::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
unsigned long long value = 0; unsigned long long value = 0;
for (auto vidx = bytes.size() - 1; vidx >= 0; vidx--) { for (auto vidx = bytes.size() - 1; vidx >= 0; vidx--) {
@ -297,57 +326,62 @@ void BytesAsUnsigned::parse(const QByteArray& bytes, std::shared_ptr<DataAccessC
out->append(value); out->append(value);
} }
std::shared_ptr<Serializable> BytesAsUnsigned::newDefault() const std::shared_ptr<Serializable> AsUnsigned::newDefault() const
{ {
return std::make_shared<BytesAsUnsigned>(); return std::make_shared<AsUnsigned>();
}
QString AsUnsigned::topic()
{
return NAME(AsUnsigned);
} }
#include <stdexcept> #include <stdexcept>
bool BytesAsList::setOffsetSpan(int value) bool AsList::setOffsetSpan(int value)
{ {
this->_list._bytes_offset = value; this->_list._bytes_offset = value;
return true; return true;
} }
std::shared_ptr<ExtractUnit> BytesAsList::elementRule() const std::shared_ptr<ExtractUnit> AsList::elementRule() const
{ {
return this->_list._bind_unit; return this->_list._bind_unit;
} }
bool BytesAsList::appendElementRule(std::shared_ptr<ExtractUnit> u) bool AsList::setElementRule(std::shared_ptr<ExtractUnit> u)
{ {
this->_list._bind_unit = u; this->_list._bind_unit = u;
return true; return true;
} }
std::shared_ptr<SizeProvider> BytesAsList::sizeProvider() const std::shared_ptr<SizeProvider> AsList::sizeProvider() const
{ {
return this->_list._bind_size_v; return this->_list._bind_size_v;
} }
bool BytesAsList::setSizeProvider(std::shared_ptr<SizeProvider> ins) bool AsList::setSizeProvider(std::shared_ptr<SizeProvider> ins)
{ {
this->_list._bind_size_v = ins; this->_list._bind_size_v = ins;
return true; return true;
} }
QString BytesAsList::name() const QString AsList::name() const
{ {
return NAME(BytesAsList); return topic();
} }
DataType BytesAsList::outType() const DataType AsList::outType() const
{ {
return DataType::LIST_COLLECTION; return DataType::LIST_COLLECTION;
} }
int BytesAsList::offsetSpan() const int AsList::offsetSpan() const
{ {
return _list._bytes_offset; return _list._bytes_offset;
} }
int BytesAsList::countWithin() const int AsList::countWithin() const
{ {
auto expr = this->_list._bind_size_v->expression(); auto expr = this->_list._bind_size_v->expression();
if (this->_list._bind_size_v->value(expr) < 0) { if (this->_list._bind_size_v->value(expr) < 0) {
@ -359,7 +393,7 @@ int BytesAsList::countWithin() const
} }
#include "TranslateBasic.h" #include "TranslateBasic.h"
void BytesAsList::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) void AsList::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
{ {
INT32_PEAK(_list._bytes_offset, obj); INT32_PEAK(_list._bytes_offset, obj);
@ -386,7 +420,7 @@ void BytesAsList::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObje
} }
#include <QJsonArray> #include <QJsonArray>
void BytesAsList::saveTo(QJsonObject& obj) const void AsList::saveTo(QJsonObject& obj) const
{ {
INT32_SAVE(_list._bytes_offset, obj); INT32_SAVE(_list._bytes_offset, obj);
@ -412,7 +446,7 @@ void BytesAsList::saveTo(QJsonObject& obj) const
OBJECT_SAVE(size_provider_obj, obj); OBJECT_SAVE(size_provider_obj, obj);
} }
void BytesAsList::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsList::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
auto expr = this->_list._bind_size_v->expression(); auto expr = this->_list._bind_size_v->expression();
auto size_value = this->_list._bind_size_v->value(expr); auto size_value = this->_list._bind_size_v->value(expr);
@ -427,39 +461,44 @@ void BytesAsList::parse(const QByteArray& bytes, std::shared_ptr<DataAccessConte
} }
} }
std::shared_ptr<Serializable> BytesAsList::newDefault() const std::shared_ptr<Serializable> AsList::newDefault() const
{ {
return std::make_shared<BytesAsList>(); return std::make_shared<AsList>();
} }
void BytesAsList::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) void AsList::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
{ {
inst->setField("ls", this->_list._bind_unit->outType()); inst->setField("ls", this->_list._bind_unit->outType());
auto layer = std::make_shared<FieldManagerLayer>("ls", inst); auto layer = std::make_shared<FieldManagerLayer>("ls", inst);
this->_list._bind_unit->registSubField(layer); this->_list._bind_unit->registSubField(layer);
} }
QString BytesAsUnion::name() const QString AsList::topic()
{ {
return NAME(BytesAsUnion); return NAME(AsList);
} }
DataType BytesAsUnion::outType() const QString AsUnion::name() const
{
return topic();
}
DataType AsUnion::outType() const
{ {
return DataType::UNION_COMBINATE; return DataType::UNION_COMBINATE;
} }
int BytesAsUnion::offsetSpan() const int AsUnion::offsetSpan() const
{ {
return _union.byte_offset; return _union.byte_offset;
} }
int BytesAsUnion::countWithin() const int AsUnion::countWithin() const
{ {
return _union.byte_count; return _union.byte_count;
} }
void BytesAsUnion::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsUnion::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
for (auto u : this->elementRules()) for (auto u : this->elementRules())
if (u->checkpass(bytes)) { if (u->checkpass(bytes)) {
@ -469,7 +508,7 @@ void BytesAsUnion::parse(const QByteArray& bytes, std::shared_ptr<DataAccessCont
} }
} }
void BytesAsUnion::loadFrom( void AsUnion::loadFrom(
std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
{ {
INT32_PEAK(_union.byte_count, obj); INT32_PEAK(_union.byte_count, obj);
@ -495,7 +534,7 @@ void BytesAsUnion::loadFrom(
} }
} }
void BytesAsUnion::saveTo(QJsonObject& obj) const void AsUnion::saveTo(QJsonObject& obj) const
{ {
INT32_SAVE(_union.byte_count, obj); INT32_SAVE(_union.byte_count, obj);
INT32_SAVE(_union.byte_offset, obj); INT32_SAVE(_union.byte_offset, obj);
@ -515,40 +554,40 @@ void BytesAsUnion::saveTo(QJsonObject& obj) const
ARRAY_SAVE(array, obj); ARRAY_SAVE(array, obj);
} }
std::shared_ptr<Serializable> BytesAsUnion::newDefault() const std::shared_ptr<Serializable> AsUnion::newDefault() const
{ {
return std::make_shared<BytesAsUnion>(); return std::make_shared<AsUnion>();
} }
QList<std::shared_ptr<RuleMatch>> BytesAsUnion::elementRules() const QList<std::shared_ptr<RuleMatch>> AsUnion::elementRules() const
{ {
return _union._rule_list; return _union._rule_list;
} }
bool BytesAsUnion::appendElementRule(std::shared_ptr<RuleMatch> u) bool AsUnion::appendElementRule(std::shared_ptr<RuleMatch> u)
{ {
this->_union._rule_list << u; this->_union._rule_list << u;
return true; return true;
} }
void BytesAsUnion::clearRules() void AsUnion::clearRules()
{ {
this->_union._rule_list.clear(); this->_union._rule_list.clear();
} }
bool BytesAsUnion::setCountWithin(int bytes) bool AsUnion::setCountWithin(int bytes)
{ {
this->_union.byte_count = bytes; this->_union.byte_count = bytes;
return true; return true;
} }
bool BytesAsUnion::setOffsetSpan(int value) bool AsUnion::setOffsetSpan(int value)
{ {
this->_union.byte_offset = value; this->_union.byte_offset = value;
return true; return true;
} }
void BytesAsUnion::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) void AsUnion::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
{ {
for (auto rl : this->_union._rule_list) { for (auto rl : this->_union._rule_list) {
inst->setField(rl->name(), rl->bindRule()->outType()); inst->setField(rl->name(), rl->bindRule()->outType());
@ -557,7 +596,12 @@ void BytesAsUnion::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
} }
} }
void BytesAsRuleSet::registSubField(std::shared_ptr<ScopeFieldsSetter> inst) QString AsUnion::topic()
{
return NAME(AsUnion);
}
void AsRuleSet::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
{ {
for (auto rl_key : this->fieldNames()){ for (auto rl_key : this->fieldNames()){
auto rlinst = (*this)[rl_key]; auto rlinst = (*this)[rl_key];
@ -567,7 +611,7 @@ void BytesAsRuleSet::registSubField(std::shared_ptr<ScopeFieldsSetter> inst)
} }
} }
void BytesAsRuleSet::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const void AsRuleSet::parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const
{ {
auto bufx = bytes; auto bufx = bytes;
for (auto keym : this->fieldNames()) { for (auto keym : this->fieldNames()) {
@ -583,33 +627,33 @@ void BytesAsRuleSet::parse(const QByteArray& bytes, std::shared_ptr<DataAccessCo
} }
} }
QString BytesAsRuleSet::name() const QString AsRuleSet::name() const
{ {
return NAME(BytesAsRuleSet); return topic();
} }
DataType BytesAsRuleSet::outType() const DataType AsRuleSet::outType() const
{ {
return DataType::SUB_RULE; return DataType::SUB_RULE;
} }
bool BytesAsRuleSet::setOffsetSpan(int bytes) bool AsRuleSet::setOffsetSpan(int bytes)
{ {
this->_bind._byte_offset = bytes; this->_bind._byte_offset = bytes;
return true; return true;
} }
int BytesAsRuleSet::offsetSpan() const int AsRuleSet::offsetSpan() const
{ {
return this->_bind._byte_offset; return this->_bind._byte_offset;
} }
int BytesAsRuleSet::countWithin() const int AsRuleSet::countWithin() const
{ {
return this->_bind._byte_count; return this->_bind._byte_count;
} }
void BytesAsRuleSet::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj) void AsRuleSet::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonObject& obj)
{ {
INT32_PEAK(_bind._byte_count, obj); INT32_PEAK(_bind._byte_count, obj);
INT32_PEAK(_bind._byte_offset, obj); INT32_PEAK(_bind._byte_offset, obj);
@ -631,7 +675,7 @@ void BytesAsRuleSet::loadFrom(std::shared_ptr<TranslateBasic> core, const QJsonO
} }
} }
void BytesAsRuleSet::saveTo(QJsonObject& obj) const void AsRuleSet::saveTo(QJsonObject& obj) const
{ {
INT32_SAVE(_bind._byte_count, obj); INT32_SAVE(_bind._byte_count, obj);
INT32_SAVE(_bind._byte_offset, obj); INT32_SAVE(_bind._byte_offset, obj);
@ -653,33 +697,33 @@ void BytesAsRuleSet::saveTo(QJsonObject& obj) const
ARRAY_SAVE(array, obj); ARRAY_SAVE(array, obj);
} }
std::shared_ptr<Serializable> BytesAsRuleSet::newDefault() const std::shared_ptr<Serializable> AsRuleSet::newDefault() const
{ {
return std::make_shared<BytesAsRuleSet>(); return std::make_shared<AsRuleSet>();
} }
std::pair<QString, std::shared_ptr<ExtractUnit>> BytesAsRuleSet::operator[](int index) const std::pair<QString, std::shared_ptr<ExtractUnit>> AsRuleSet::operator[](int index) const
{ {
return this->_bind.sub_units[index]; return this->_bind.sub_units[index];
} }
void BytesAsRuleSet::replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst) void AsRuleSet::replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst)
{ {
this->_bind.sub_units.replace(index, inst); this->_bind.sub_units.replace(index, inst);
} }
extract::BytesAsRuleSet& BytesAsRuleSet::append(const QString& nm, std::shared_ptr<ExtractUnit> u) extract::AsRuleSet& AsRuleSet::append(const QString& nm, std::shared_ptr<ExtractUnit> u)
{ {
this->_bind.sub_units.append(std::make_pair(nm, u)); this->_bind.sub_units.append(std::make_pair(nm, u));
return *this; return *this;
} }
void BytesAsRuleSet::removeAt(int index) void AsRuleSet::removeAt(int index)
{ {
this->_bind.sub_units.removeAt(index); this->_bind.sub_units.removeAt(index);
} }
QList<QString> BytesAsRuleSet::fieldNames() const QList<QString> AsRuleSet::fieldNames() const
{ {
QList<QString> fields_store; QList<QString> fields_store;
for (auto fpair : this->_bind.sub_units) { for (auto fpair : this->_bind.sub_units) {
@ -688,7 +732,7 @@ QList<QString> BytesAsRuleSet::fieldNames() const
return fields_store;; return fields_store;;
} }
std::shared_ptr<ExtractUnit> BytesAsRuleSet::operator[](const QString& field) const std::shared_ptr<ExtractUnit> AsRuleSet::operator[](const QString& field) const
{ {
for (auto pair : this->_bind.sub_units) { for (auto pair : this->_bind.sub_units) {
if(pair.first == field) if(pair.first == field)
@ -698,17 +742,22 @@ std::shared_ptr<ExtractUnit> BytesAsRuleSet::operator[](const QString& field) co
return std::shared_ptr<ExtractUnit>(); return std::shared_ptr<ExtractUnit>();
} }
void BytesAsRuleSet::setCustomName(const QString& name) void AsRuleSet::setCustomName(const QString& name)
{ {
_bind._name_store = name; _bind._name_store = name;
} }
QString BytesAsRuleSet::customName() const QString AsRuleSet::customName() const
{ {
return _bind._name_store; return _bind._name_store;
} }
int BytesAsRuleSet::memberCount() const int AsRuleSet::memberCount() const
{ {
return _bind.sub_units.size(); return _bind.sub_units.size();
} }
QString AsRuleSet::topic()
{
return NAME(AsRuleSet);
}

View File

@ -88,9 +88,10 @@ namespace extract {
/// <summary> /// <summary>
/// 转换源数值未16进制数值默认分割方式 /// 转换源数值未16进制数值默认分割方式
/// </summary> /// </summary>
class BytesAsHex : public AbstractExtractor { class AsHex : public AbstractExtractor {
public: public:
BytesAsHex(); static QString topic();
AsHex();
void parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const override; void parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const override;
std::shared_ptr<Serializable> newDefault() const override; std::shared_ptr<Serializable> newDefault() const override;
@ -99,13 +100,14 @@ namespace extract {
/// <summary> /// <summary>
/// 转换源数值为位联合 /// 转换源数值为位联合
/// </summary> /// </summary>
class BytesAsBitCombine : public AbstractExtractor { class AsBitCombine : public AbstractExtractor {
public: public:
struct __Private { struct __Private {
QHash<int, QString> _switch_options; QHash<int, QString> _switch_options;
} _combine; } _combine;
BytesAsBitCombine(); static QString topic();
AsBitCombine();
bool setSwitchOption(int bit_index, const QString& keyword); bool setSwitchOption(int bit_index, const QString& keyword);
QHash<int, QString> switchOptions() const; QHash<int, QString> switchOptions() const;
@ -123,9 +125,10 @@ namespace extract {
/// <summary> /// <summary>
/// 转换源数据为整形 /// 转换源数据为整形
/// </summary> /// </summary>
class BytesAsInteger : public AbstractExtractor { class AsInteger : public AbstractExtractor {
public: public:
BytesAsInteger(); static QString topic();
AsInteger();
// ExtractUnit ============================ // ExtractUnit ============================
bool setCountWithin(int bytes) override; bool setCountWithin(int bytes) override;
@ -138,9 +141,10 @@ namespace extract {
/// <summary> /// <summary>
/// 转换源数据为整形 /// 转换源数据为整形
/// </summary> /// </summary>
class BytesAsUnsigned : public AbstractExtractor { class AsUnsigned : public AbstractExtractor {
public: public:
BytesAsUnsigned(); static QString topic();
AsUnsigned();
// ExtractUnit ============================ // ExtractUnit ============================
bool setCountWithin(int bytes) override; bool setCountWithin(int bytes) override;
@ -153,14 +157,15 @@ namespace extract {
/// <summary> /// <summary>
/// 转换源数据为字符串 /// 转换源数据为字符串
/// </summary> /// </summary>
class BytesAsString : public AbstractExtractor { class AsString : public AbstractExtractor {
public: public:
struct __Private { struct __Private {
QTextCodec* _conv_with = nullptr; QTextCodec* _conv_with = nullptr;
} _strings; } _strings;
public: public:
BytesAsString(); static QString topic();
AsString();
void setStrCodec(QTextCodec* ins); void setStrCodec(QTextCodec* ins);
QString codecName() const; QString codecName() const;
@ -174,24 +179,26 @@ namespace extract {
std::shared_ptr<Serializable> newDefault() const override; std::shared_ptr<Serializable> newDefault() const override;
}; };
class BytesAsFloat : public AbstractExtractor { class AsFloat : public AbstractExtractor {
public: public:
BytesAsFloat(); static QString topic();
AsFloat();
void parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const override; void parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const override;
std::shared_ptr<Serializable> newDefault() const override; std::shared_ptr<Serializable> newDefault() const override;
}; };
class BytesAsDouble : public AbstractExtractor { class AsDouble : public AbstractExtractor {
public: public:
BytesAsDouble(); static QString topic();
AsDouble();
void parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const override; void parse(const QByteArray& bytes, std::shared_ptr<DataAccessContext> out) const override;
std::shared_ptr<Serializable> newDefault() const override; std::shared_ptr<Serializable> newDefault() const override;
}; };
class BytesAsList : public ExtractUnit { class AsList : public ExtractUnit {
public: public:
struct __Private { struct __Private {
std::shared_ptr<ExtractUnit> _bind_unit = nullptr; std::shared_ptr<ExtractUnit> _bind_unit = nullptr;
@ -200,9 +207,10 @@ namespace extract {
} _list; } _list;
public: public:
static QString topic();
bool setOffsetSpan(int value); bool setOffsetSpan(int value);
std::shared_ptr<ExtractUnit> elementRule() const; std::shared_ptr<ExtractUnit> elementRule() const;
bool appendElementRule(std::shared_ptr<ExtractUnit> u); bool setElementRule(std::shared_ptr<ExtractUnit> u);
std::shared_ptr<SizeProvider> sizeProvider() const; std::shared_ptr<SizeProvider> sizeProvider() const;
bool setSizeProvider(std::shared_ptr<SizeProvider> ins); bool setSizeProvider(std::shared_ptr<SizeProvider> ins);
@ -221,7 +229,7 @@ namespace extract {
}; };
class BytesAsUnion : public ExtractUnit { class AsUnion : public ExtractUnit {
public: public:
struct __Private { struct __Private {
int byte_offset = 0, byte_count = 1; int byte_offset = 0, byte_count = 1;
@ -229,6 +237,7 @@ namespace extract {
} _union; } _union;
public: public:
static QString topic();
bool setCountWithin(int bytes); bool setCountWithin(int bytes);
void clearRules(); void clearRules();
@ -251,7 +260,7 @@ namespace extract {
}; };
class BytesAsRuleSet : public ExtractUnit { class AsRuleSet : public ExtractUnit {
private: private:
struct __Private { struct __Private {
int _byte_offset = 0, _byte_count = 1; int _byte_offset = 0, _byte_count = 1;
@ -261,6 +270,8 @@ namespace extract {
}_bind; }_bind;
public: public:
static QString topic();
void setCustomName(const QString& name); void setCustomName(const QString& name);
QString customName() const; QString customName() const;
@ -271,7 +282,7 @@ namespace extract {
std::pair<QString, std::shared_ptr<ExtractUnit>> operator[](int index) const; std::pair<QString, std::shared_ptr<ExtractUnit>> operator[](int index) const;
void replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst); void replace(int index, std::pair<QString, std::shared_ptr<ExtractUnit>> inst);
void removeAt(int index); void removeAt(int index);
BytesAsRuleSet& append(const QString& nm, std::shared_ptr<ExtractUnit> u); AsRuleSet& append(const QString& nm, std::shared_ptr<ExtractUnit> u);
public: public:
QString name() const override; QString name() const override;