SimsWorld/ComponentBasic/BehaviorPerform.cpp

843 lines
18 KiB
C++
Raw Normal View History

2025-06-25 14:34:26 +00:00
#include "BehaviorPerform.h"
2025-06-28 17:38:37 +00:00
void BehaviorPerformPlugin::mapReset(const QString& path)
{
}
void BehaviorPerformPlugin::execute(std::shared_ptr<const EntityInitialRequest> in, QList<std::shared_ptr<RespondDefault>>& out)
{
}
void BehaviorPerformPlugin::execute(std::shared_ptr<const EntityPreparedRequest> in, QList<std::shared_ptr<RespondDefault>>& out)
{
}
void BehaviorPerformPlugin::execute(std::shared_ptr<const SyncRequest> in, QList<std::shared_ptr<RespondDefault>>& out)
{
}
void BehaviorPerformPlugin::execute(std::shared_ptr<const DeduceRequest> in, QList<std::shared_ptr<RespondDefault>>& out)
{
}
2025-06-25 14:34:26 +00:00
void BehaviorPerformPlugin::recoveryFrom(const QJsonObject& obj)
{
}
void BehaviorPerformPlugin::saveTo(QJsonObject& obj) const
{
}
2025-06-28 17:38:37 +00:00
std::shared_ptr<Serializable> BehaviorPerformPlugin::newDefault() const
2025-06-25 14:34:26 +00:00
{
2025-06-28 17:38:37 +00:00
return std::make_shared<BehaviorPerformPlugin>();
2025-06-25 14:34:26 +00:00
}
void BehaviorPerformPlugin::bindEntity(std::weak_ptr<WsEntity> host)
{
2025-06-28 17:38:37 +00:00
this->_bind_entity = host;
2025-06-25 14:34:26 +00:00
}
QString BehaviorPerformPlugin::name() const
{
2025-06-28 17:38:37 +00:00
return NAME(BehaviorPerformPlugin);
2025-06-25 14:34:26 +00:00
}
2025-06-28 17:38:37 +00:00
#include <MessageLoader.h>
MapKernal::MapKernal(std::shared_ptr<MessageLoader> ins)
: _bind_loader(ins) {
}
QList<QString> MapKernal::compareTypes() const
{
return _compare_types.keys();
}
2025-06-30 05:49:36 +00:00
void MapKernal::registCompare(std::shared_ptr<CompareDelegate> ins)
2025-06-25 14:34:26 +00:00
{
2025-06-28 17:38:37 +00:00
_compare_types[ins->name()] = ins;
2025-06-30 16:45:32 +00:00
emit this->compareTypeListChanged();
2025-06-25 14:34:26 +00:00
}
2025-06-30 05:49:36 +00:00
std::shared_ptr<CompareDelegate> MapKernal::getCompare(const QString& name)
2025-06-25 14:34:26 +00:00
{
2025-06-28 17:38:37 +00:00
if (!_compare_types.contains(name))
2025-06-25 14:34:26 +00:00
return nullptr;
2025-06-28 17:38:37 +00:00
return _compare_types[name];
}
2025-06-30 05:49:36 +00:00
void MapKernal::registConvert(std::shared_ptr<ConvertDelegate> ins)
2025-06-28 17:38:37 +00:00
{
_convert_types[ins->name()] = ins;
2025-06-30 16:45:32 +00:00
emit this->convertTypeListChanged();
2025-06-28 17:38:37 +00:00
}
QList<QString> MapKernal::convertTypes() const
{
return _convert_types.keys();
}
2025-06-30 05:49:36 +00:00
std::shared_ptr<ConvertDelegate> MapKernal::getConvert(const QString& name)
2025-06-28 17:38:37 +00:00
{
if (!_convert_types.contains(name))
return nullptr;
return _convert_types[name];
}
2025-06-30 05:49:36 +00:00
void MapKernal::registExecute(std::shared_ptr<ExecuteDelegate> ins)
{
_execute_types[ins->typeName()] = ins;
2025-06-30 16:45:32 +00:00
emit this->executeTypeListChanged();
2025-06-30 05:49:36 +00:00
}
2025-06-28 17:38:37 +00:00
std::shared_ptr<MessageLoader> MapKernal::messageLoader() const
{
return this->_bind_loader;
}
2025-06-30 16:45:32 +00:00
void MapKernal::initial()
{
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
registData(std::make_shared<GeneralData>());
for (auto key : messageLoader()->allType())
registData(messageLoader()->makeDefault(key));
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD>ýڵ<C3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
registNode(std::make_shared<SequenceNode>());
registNode(std::make_shared<SelectorNode>());
registNode(std::make_shared<ParallelNode>());
registNode(std::make_shared<CompareNode>(this->shared_from_this()));
registNode(std::make_shared<ExecuteNode>(this->shared_from_this()));
registNode(std::make_shared<BehaviorMapNode>(this->shared_from_this()));
}
2025-06-28 17:38:37 +00:00
void MapKernal::registData(std::shared_ptr<TopicData> init)
{
if (_variable_types.contains(init->topicString()))
2025-06-29 17:19:07 +00:00
throw new UniException(QString(u8"<EFBFBD>ظ<EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{%1}").arg(init->topicString()));
2025-06-28 17:38:37 +00:00
_variable_types[init->topicString()] = init;
}
QList<QString> MapKernal::dataTypes() const
{
return _variable_types.keys();
}
std::shared_ptr<TopicData> MapKernal::getData(const QString& topic)
{
return _variable_types[topic];
}
2025-06-30 05:49:36 +00:00
QList<QString> MapKernal::executeTypes() const
{
return _execute_types.keys();
}
std::shared_ptr<ExecuteDelegate> MapKernal::getExecute(const QString& name)
{
return _execute_types[name];
}
void MapKernal::registNode(std::shared_ptr<LogicalNode> ins)
{
_logicalnode_types[ins->typeName()] = ins;
}
QList<QString> MapKernal::nodeTypes() const
{
return _logicalnode_types.keys();
}
std::shared_ptr<LogicalNode> MapKernal::getNode(const QString& name)
{
return _logicalnode_types[name];
}
2025-06-28 17:38:37 +00:00
std::shared_ptr<Serializable> MapKernal::newDefault() const
{
return nullptr;
}
2025-07-04 14:53:03 +00:00
LogicalNode::LogicalNode(NodeKind t, std::shared_ptr<MapKernal> kernal)
:_node_type(t), _bind_kernal(kernal) {
2025-06-28 17:38:37 +00:00
}
2025-06-29 14:58:45 +00:00
void LogicalNode::_set_parent_node(std::weak_ptr<LogicalNode> pnode)
2025-06-28 17:38:37 +00:00
{
this->_parent_bind = pnode;
}
2025-06-29 12:30:32 +00:00
NodeKind LogicalNode::nodeKind() const
2025-06-28 17:38:37 +00:00
{
return _node_type;
}
2025-06-29 17:19:07 +00:00
int LogicalNode::depth() const
{
auto node_temp = this->parent().lock();
if (!node_temp) return 0;
return this->parent().lock()->depth() + 1;
}
2025-07-02 17:11:48 +00:00
std::shared_ptr<BehaviorMapNode> LogicalNode::bindMap() const
2025-06-28 17:38:37 +00:00
{
2025-06-29 12:30:32 +00:00
auto node_temp = this->parent().lock();
2025-06-28 17:38:37 +00:00
if (!node_temp) return nullptr;
2025-06-29 12:30:32 +00:00
while (node_temp->nodeKind() != NodeKind::MAPNODE) {
node_temp = node_temp->parent().lock();
2025-06-28 17:38:37 +00:00
}
2025-07-02 17:11:48 +00:00
return std::dynamic_pointer_cast<BehaviorMapNode>(node_temp);
2025-06-28 17:38:37 +00:00
}
void LogicalNode::setID(int unique_id)
{
this->_node_id = unique_id;
}
int LogicalNode::getID() const
{
return this->_node_id;
}
2025-06-29 14:58:45 +00:00
QString LogicalNode::rtName() const
2025-06-28 17:38:37 +00:00
{
2025-06-29 17:19:07 +00:00
return QString(u8"%1(%2)").arg(this->typeName()).arg(getID());
2025-06-28 17:38:37 +00:00
}
2025-06-29 12:30:32 +00:00
std::weak_ptr<LogicalNode> LogicalNode::parent() const
2025-06-28 17:38:37 +00:00
{
return this->_parent_bind;
}
2025-06-29 14:58:45 +00:00
BehaviorMapNode::BehaviorMapNode(std::shared_ptr<MapKernal> core)
2025-07-04 14:53:03 +00:00
:LogicalNode(NodeKind::MAPNODE, core), _bind_kernal(core) {
2025-06-28 17:38:37 +00:00
}
2025-06-25 14:34:26 +00:00
2025-07-02 17:11:48 +00:00
std::shared_ptr<MapKernal> BehaviorMapNode::getKernal() const
{
return _bind_kernal;
}
2025-06-28 17:38:37 +00:00
void BehaviorMapNode::setVariable(const QString& key, IO_TYPE t, std::shared_ptr<TopicData> ins)
{
if (_variables.contains(key))
if (_variables[key].second->topicString() != ins->topicString())
2025-06-29 17:19:07 +00:00
throw new UniException(u8"<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD>ͬһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>");
2025-06-28 17:38:37 +00:00
_variables[key] = std::make_pair(t, ins);
}
std::shared_ptr<TopicData> BehaviorMapNode::getVariable(const QString& key) const
{
if (!_variables.contains(key))
return nullptr;
return _variables[key].second;
}
void BehaviorMapNode::resetName(const QString& val)
{
this->_map_name = val;
}
std::shared_ptr<Serializable> BehaviorMapNode::newDefault() const
{
2025-06-29 14:58:45 +00:00
return std::make_shared<BehaviorMapNode>(this->_bind_kernal);
2025-06-28 17:38:37 +00:00
}
void BehaviorMapNode::recoveryFrom(const QJsonObject& obj)
{
}
void BehaviorMapNode::saveTo(QJsonObject& obj) const
{
}
QList<std::shared_ptr<LogicalNode>> BehaviorMapNode::getForwards() const
{
return children();
}
bool BehaviorMapNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste)
{
this->_state_value = ste;
return true;
}
void BehaviorMapNode::reset()
{
this->_state_value = LogicalResult::UNDEFINED;
}
QString BehaviorMapNode::typeName() const
{
return _map_name;
}
LogicalResult BehaviorMapNode::execute()
{
return _state_value;
}
QHash<QString, std::shared_ptr<TopicData>> BehaviorMapNode::inputList() const
{
QHash<QString, std::shared_ptr<TopicData>> list;
for (auto key : this->_variables.keys()) {
2025-06-29 17:19:07 +00:00
if (this->_variables[key].first == IO_TYPE::INPUT && key.contains(u8"::"))
2025-06-28 17:38:37 +00:00
list[key] = _variables[key].second;
}
return list;
}
QHash<QString, std::shared_ptr<TopicData>> BehaviorMapNode::outputList() const
{
QHash<QString, std::shared_ptr<TopicData>> list;
for (auto key : this->_variables.keys()) {
2025-06-29 17:19:07 +00:00
if (this->_variables[key].first == IO_TYPE::OUTPUT && key.contains(u8"::"))
2025-06-28 17:38:37 +00:00
list[key] = _variables[key].second;
}
return list;
}
2025-07-04 14:53:03 +00:00
SequenceNode::SequenceNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::SEQUENCENODE, kernal) {
2025-06-28 17:38:37 +00:00
}
QList<std::shared_ptr<LogicalNode>> SequenceNode::getForwards() const
{
for (auto item : children()) {
// <20>ӽڵ<D3BD>ִ<EFBFBD><D6B4>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
if (_state_map.contains(item->getID())) {
if (_state_map[item->getID()] != LogicalResult::SUCCESS)
return QList<std::shared_ptr<LogicalNode>>();
}
// <20><>ȡ<EFBFBD>½ڵ<C2BD>
if (!_state_map.contains(item->getID()))
return QList<std::shared_ptr<LogicalNode>>() << item;
}
// ȫ<><C8AB><EFBFBD>ɹ<EFBFBD>
return QList<std::shared_ptr<LogicalNode>>();
}
QString SequenceNode::typeName() const
{
2025-07-02 17:15:51 +00:00
return u8"˳<EFBFBD><EFBFBD>";
2025-06-28 17:38:37 +00:00
}
LogicalResult SequenceNode::execute() {
if (children().size() >= _state_map.size())
return LogicalResult::FAILURE;
for (auto ste : this->_state_map) {
switch (ste) {
case LogicalResult::SUCCESS:
break;
default:
return LogicalResult::FAILURE;
}
}
return LogicalResult::SUCCESS;
}
QHash<QString, std::shared_ptr<TopicData>> SequenceNode::inputList() const
{
return QHash<QString, std::shared_ptr<TopicData>>();
}
QHash<QString, std::shared_ptr<TopicData>> SequenceNode::outputList() const
{
return QHash<QString, std::shared_ptr<TopicData>>();
}
void SequenceNode::recoveryFrom(const QJsonObject& obj)
{
QStringList state_items;
STRLIST_PEAK(state_items);
for (auto kv : state_items) {
2025-06-29 17:19:07 +00:00
auto kv_pair = kv.split(u8":");
2025-06-28 17:38:37 +00:00
_state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt();
}
}
void SequenceNode::saveTo(QJsonObject& obj) const
{
QStringList state_items;
for (auto inv : _state_map.keys()) {
2025-06-29 17:19:07 +00:00
state_items << QString(u8"%1:%2").arg(inv).arg((int)_state_map[inv]);
2025-06-28 17:38:37 +00:00
}
STRLIST_SAVE(state_items);
}
bool SequenceNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste)
{
this->_state_map[node->getID()] = ste;
return true;
}
std::shared_ptr<Serializable> SequenceNode::newDefault() const
{
2025-07-04 14:53:03 +00:00
return std::make_shared<SequenceNode>(this->bindMap()->getKernal());
2025-06-28 17:38:37 +00:00
}
void SequenceNode::reset()
{
this->_state_map.clear();
}
2025-06-29 14:58:45 +00:00
QList<std::shared_ptr<LogicalNode>> LogicalNode::children() const
2025-06-28 17:38:37 +00:00
{
return _child_list;
}
2025-06-29 14:58:45 +00:00
void LogicalNode::insert(std::shared_ptr<LogicalNode> node, int index /*= -1*/)
2025-06-28 17:38:37 +00:00
{
for (auto it : _child_list)
if (it->getID() == node->getID())
return;
2025-07-04 14:53:03 +00:00
if (node->parent().lock())
2025-07-03 16:59:12 +00:00
node->parent().lock()->remove(node);
2025-06-28 17:38:37 +00:00
_child_list.insert(index, node);
2025-07-03 16:59:12 +00:00
node->_set_parent_node(this->shared_from_this());
2025-06-28 17:38:37 +00:00
}
2025-06-29 14:58:45 +00:00
void LogicalNode::remove(std::shared_ptr<LogicalNode> node)
2025-06-28 17:38:37 +00:00
{
_child_list.removeAll(node);
}
2025-07-04 14:53:03 +00:00
SelectorNode::SelectorNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::SEQUENCENODE, kernal) {
2025-06-28 17:38:37 +00:00
}
QList<std::shared_ptr<LogicalNode>> SelectorNode::getForwards() const
{
for (auto item : children()) {
// <20>ӽڵ<D3BD>ִ<EFBFBD><D6B4>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
if (_state_map.contains(item->getID())) {
if (_state_map[item->getID()] == LogicalResult::SUCCESS)
return QList<std::shared_ptr<LogicalNode>>();
}
// <20><>ȡ<EFBFBD>½ڵ<C2BD>
if (!_state_map.contains(item->getID()))
return QList<std::shared_ptr<LogicalNode>>() << item;
}
// ȫ<><C8AB><EFBFBD>ɹ<EFBFBD>
return QList<std::shared_ptr<LogicalNode>>();
}
bool SelectorNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste)
{
_state_map[node->getID()] = ste;
return true;
}
std::shared_ptr<Serializable> SelectorNode::newDefault() const
{
return std::make_shared<SelectorNode>();
}
void SelectorNode::recoveryFrom(const QJsonObject& obj)
{
QStringList state_items;
STRLIST_PEAK(state_items);
for (auto kv : state_items) {
2025-06-29 17:19:07 +00:00
auto kv_pair = kv.split(u8":");
2025-06-28 17:38:37 +00:00
_state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt();
}
}
void SelectorNode::saveTo(QJsonObject& obj) const
{
QStringList state_items;
for (auto inv : _state_map.keys()) {
2025-06-29 17:19:07 +00:00
state_items << QString(u8"%1:%2").arg(inv).arg((int)_state_map[inv]);
2025-06-28 17:38:37 +00:00
}
STRLIST_SAVE(state_items);
}
void SelectorNode::reset()
{
_state_map.clear();
}
QString SelectorNode::typeName() const
{
2025-07-02 17:15:51 +00:00
return u8"ѡ<EFBFBD><EFBFBD>";
2025-06-28 17:38:37 +00:00
}
LogicalResult SelectorNode::execute()
{
for (auto value : _state_map) {
if (value == LogicalResult::SUCCESS)
return LogicalResult::SUCCESS;
}
return LogicalResult::FAILURE;
}
QHash<QString, std::shared_ptr<TopicData>> SelectorNode::inputList() const
{
return {};
}
QHash<QString, std::shared_ptr<TopicData>> SelectorNode::outputList() const
{
return {};
}
QList<std::shared_ptr<LogicalNode>> ParallelNode::getForwards() const
{
if (this->children().size() == _state_map.size())
return QList<std::shared_ptr<LogicalNode>>();
return this->children();
}
bool ParallelNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste)
{
_state_map[node->getID()] = ste;
return children().size() == _state_map.size();
}
void ParallelNode::reset()
{
_state_map.clear();
}
QString ParallelNode::typeName() const
{
2025-07-02 17:15:51 +00:00
return u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
2025-06-28 17:38:37 +00:00
}
LogicalResult ParallelNode::execute()
{
for (auto ste : this->_state_map)
if (ste != LogicalResult::SUCCESS)
return LogicalResult::FAILURE;
return LogicalResult::SUCCESS;
}
std::shared_ptr<Serializable> ParallelNode::newDefault() const
{
return std::make_shared<ParallelNode>();
}
2025-07-04 14:53:03 +00:00
ParallelNode::ParallelNode(std::shared_ptr<MapKernal> kernal)
: LogicalNode(NodeKind::PARALLELNODE, kernal) {
2025-06-28 17:38:37 +00:00
}
QHash<QString, std::shared_ptr<TopicData>> ParallelNode::inputList() const
{
return QHash<QString, std::shared_ptr<TopicData>>();
}
QHash<QString, std::shared_ptr<TopicData>> ParallelNode::outputList() const
{
return QHash<QString, std::shared_ptr<TopicData>>();
}
void ParallelNode::recoveryFrom(const QJsonObject& obj)
{
QStringList state_items;
STRLIST_PEAK(state_items);
for (auto kv : state_items) {
2025-06-29 17:19:07 +00:00
auto kv_pair = kv.split(u8":");
2025-06-28 17:38:37 +00:00
_state_map[kv_pair[0].toInt()] = (LogicalResult)kv_pair[1].toInt();
}
}
void ParallelNode::saveTo(QJsonObject& obj) const
{
QStringList state_items;
for (auto inv : _state_map.keys()) {
2025-06-29 17:19:07 +00:00
state_items << QString(u8"%1:%2").arg(inv).arg((int)_state_map[inv]);
2025-06-28 17:38:37 +00:00
}
STRLIST_SAVE(state_items);
}
void CompareNode::reset() {
}
QString CompareNode::typeName() const
{
2025-07-02 17:15:51 +00:00
return QString(u8"%1<%2>").arg(u8"<EFBFBD>Ƚ<EFBFBD>", delegateName());
2025-06-28 17:38:37 +00:00
}
LogicalResult CompareNode::execute()
{
if (this->_bind_delegate) {
2025-06-29 17:19:07 +00:00
auto vl = _data_map[u8"<EFBFBD><EFBFBD>ֵ"];
auto vb = _data_map[u8"<EFBFBD><EFBFBD>ֵ"];
2025-06-28 17:38:37 +00:00
if (this->_bind_delegate->compare(vl, vb))
return LogicalResult::SUCCESS;
}
return LogicalResult::FAILURE;
}
2025-06-29 14:58:45 +00:00
void CompareNode::insert(std::shared_ptr<LogicalNode> node, int index /*= -1*/)
{
}
QList<std::shared_ptr<LogicalNode>> CompareNode::getForwards() const
{
return QList<std::shared_ptr<LogicalNode>>();
}
bool CompareNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste) {
return true;
}
2025-06-28 17:38:37 +00:00
std::shared_ptr<Serializable> CompareNode::newDefault() const
{
2025-06-30 14:47:18 +00:00
return std::make_shared<CompareNode>(_bind_kernal);
2025-06-28 17:38:37 +00:00
}
2025-06-30 14:47:18 +00:00
CompareNode::CompareNode(std::shared_ptr<MapKernal> ins)
2025-07-04 14:53:03 +00:00
: LogicalNode(NodeKind::COMPARENODE, ins), _bind_kernal(ins) {
2025-06-29 17:19:07 +00:00
_data_map[u8"<EFBFBD><EFBFBD>ֵ"] = std::make_shared<GeneralData>();
_data_map[u8"<EFBFBD><EFBFBD>ֵ"] = std::make_shared<GeneralData>();
2025-06-28 17:38:37 +00:00
}
QString CompareNode::delegateName() const
{
if (_bind_delegate)
return _bind_delegate->name();
2025-06-29 17:19:07 +00:00
return u8"";
2025-06-28 17:38:37 +00:00
}
2025-06-30 05:49:36 +00:00
void CompareNode::bindDelegate(std::shared_ptr<CompareDelegate> ins)
2025-06-28 17:38:37 +00:00
{
this->_bind_delegate = ins;
}
QHash<QString, std::shared_ptr<TopicData>> CompareNode::inputList() const
{
return _data_map;
}
QHash<QString, std::shared_ptr<TopicData>> CompareNode::outputList() const
{
return QHash<QString, std::shared_ptr<TopicData>>();
}
2025-06-30 14:47:18 +00:00
#include <QJsonObject>
2025-06-28 17:38:37 +00:00
void CompareNode::recoveryFrom(const QJsonObject& obj)
{
2025-06-29 17:19:07 +00:00
auto vala = obj[u8"ValL"];
auto valb = obj[u8"ValR"];
2025-06-28 17:38:37 +00:00
2025-06-29 17:19:07 +00:00
_data_map[u8"<EFBFBD><EFBFBD>ֵ"]->recoveryFrom(vala.toObject());
_data_map[u8"<EFBFBD><EFBFBD>ֵ"]->recoveryFrom(valb.toObject());
2025-06-30 14:47:18 +00:00
QString delegate_name = "";
STRING_PEAK(delegate_name);
auto deins = _bind_kernal->getCompare(delegate_name);
bindDelegate(deins);
2025-06-28 17:38:37 +00:00
}
void CompareNode::saveTo(QJsonObject& obj) const
{
QJsonObject vala, valb;
2025-06-29 17:19:07 +00:00
_data_map[u8"<EFBFBD><EFBFBD>ֵ"]->saveTo(vala);
_data_map[u8"<EFBFBD><EFBFBD>ֵ"]->saveTo(valb);
2025-06-28 17:38:37 +00:00
2025-06-29 17:19:07 +00:00
obj[u8"ValL"] = vala;
obj[u8"ValR"] = valb;
2025-06-30 14:47:18 +00:00
QString delegate_name = "";
if (_bind_delegate) {
delegate_name = _bind_delegate->name();
}
STRING_SAVE(delegate_name);
2025-06-28 17:38:37 +00:00
}
#include <QJsonDocument>
QString GeneralData::topicString() const
{
2025-06-29 17:19:07 +00:00
return u8"GeneralData";
2025-06-28 17:38:37 +00:00
}
std::shared_ptr<Serializable> GeneralData::newDefault() const
{
return std::make_shared<GeneralData>();
}
void GeneralData::recoveryFrom(const QJsonObject& obj)
{
_element_bind = obj;
}
void GeneralData::saveTo(QJsonObject& obj) const
{
obj = _element_bind;
}
2025-06-30 05:49:36 +00:00
CompareDelegate::CompareDelegate(QJSEngine& bind_engine, const QString& func)
2025-06-28 17:38:37 +00:00
:_script_engine(bind_engine), _function_name(func) {
}
2025-06-30 05:49:36 +00:00
QString CompareDelegate::name() const
2025-06-28 17:38:37 +00:00
{
return _function_name;
}
2025-06-30 05:49:36 +00:00
bool CompareDelegate::compare(std::shared_ptr<TopicData> vleft, std::shared_ptr<TopicData> vright)
2025-06-28 17:38:37 +00:00
{
return true;
}
2025-06-30 05:49:36 +00:00
ConvertDelegate::ConvertDelegate(std::shared_ptr<MapKernal> host, QJSEngine& bind_engine, const QString& func)
2025-06-28 17:38:37 +00:00
: _host_bind(host), _script_engine(bind_engine), _function_name(func) {
}
2025-06-30 05:49:36 +00:00
QString ConvertDelegate::name() const
2025-06-28 17:38:37 +00:00
{
return _function_name;
}
2025-06-30 05:49:36 +00:00
QList<std::pair<ConvertDelegate::DATA_TOPIC_STRING, QString>> ConvertDelegate::inputTable() const
2025-06-28 17:38:37 +00:00
{
return _input_table;
}
2025-06-30 05:49:36 +00:00
void ConvertDelegate::inputReset(const QList<std::pair<DATA_TOPIC_STRING, QString>>& table)
2025-06-28 17:38:37 +00:00
{
this->_input_table = table;
}
2025-06-30 05:49:36 +00:00
std::pair<ConvertDelegate::DATA_TOPIC_STRING, QString> ConvertDelegate::outputVariable() const
2025-06-28 17:38:37 +00:00
{
return _output_appoint;
}
2025-06-30 05:49:36 +00:00
void ConvertDelegate::outputReset(std::pair<DATA_TOPIC_STRING, QString> appoint)
2025-06-28 17:38:37 +00:00
{
this->_output_appoint = appoint;
}
2025-06-30 05:49:36 +00:00
std::shared_ptr<TopicData> ConvertDelegate::convert(const QList<std::shared_ptr<TopicData>>& input_variables)
2025-06-28 17:38:37 +00:00
{
return nullptr;
2025-06-25 14:34:26 +00:00
}
2025-06-30 14:47:18 +00:00
ExecuteNode::ExecuteNode(std::shared_ptr<MapKernal> ins)
: LogicalNode(NodeKind::ACTIONNODE), _bind_kernal(ins) {
}
QString ExecuteNode::delegateName() const
{
if (_bind_delegate)
return _bind_delegate->typeName();
return "";
}
void ExecuteNode::bindDelegate(std::shared_ptr<ExecuteDelegate> ins)
{
_bind_delegate = ins;
}
QList<std::shared_ptr<LogicalNode>> ExecuteNode::getForwards() const
{
return QList<std::shared_ptr<LogicalNode>>();
}
QString ExecuteNode::typeName() const
{
2025-07-02 17:15:51 +00:00
return QString(u8"ִ<EFBFBD><EFBFBD><%1>").arg(delegateName());
2025-06-30 14:47:18 +00:00
}
QHash<QString, std::shared_ptr<TopicData>> ExecuteNode::inputList() const
{
if (_bind_delegate)
return _bind_delegate->inputList();
return QHash<QString, std::shared_ptr<TopicData>>();
}
QHash<QString, std::shared_ptr<TopicData>> ExecuteNode::outputList() const
{
if (_bind_delegate)
return _bind_delegate->outputList();
return QHash<QString, std::shared_ptr<TopicData>>();
}
void ExecuteNode::insert(std::shared_ptr<LogicalNode> node, int index /*= -1*/)
{
}
void ExecuteNode::reset()
{
if (_bind_delegate)
_bind_delegate->reset();
}
LogicalResult ExecuteNode::execute()
{
if (_bind_delegate)
return _bind_delegate->execute();
return LogicalResult::FAILURE;
}
bool ExecuteNode::fallback(std::shared_ptr<LogicalNode> node, LogicalResult ste)
{
return true;
}
std::shared_ptr<Serializable> ExecuteNode::newDefault() const
{
return std::make_shared<ExecuteNode>(this->_bind_kernal);
}
void ExecuteNode::recoveryFrom(const QJsonObject& obj)
{
QString delegate_name = "";
STRING_PEAK(delegate_name);
auto de_ins = _bind_kernal->getExecute(delegate_name);
this->bindDelegate(de_ins);
if (obj.contains("data_json")) {
auto delegate_json = obj["data_json"].toObject();
de_ins->recoveryFrom(delegate_json);
}
}
void ExecuteNode::saveTo(QJsonObject& obj) const
{
QString delegate_name = "";
if (_bind_delegate)
delegate_name = _bind_delegate->typeName();
STRING_SAVE(delegate_name);
if (_bind_delegate) {
QJsonObject data_json;
this->_bind_delegate->saveTo(data_json);
obj["data_json"] = data_json;
}
}