1
0
mirror of synced 2024-12-02 11:17:19 +01:00
ImHex/plugins/builtin/source/content/dpn/control_nodes.cpp
iTrooz e0264a3459
refactor: Split data processor nodes in several files (#1419)
I'm really not sure about how I grouped the nodes, but that's a start.
In need of review

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2023-11-13 23:36:39 +01:00

125 lines
6.5 KiB
C++

#include <hex/api/content_registry.hpp>
#include <hex/data_processor/node.hpp>
namespace hex::plugin::builtin {
class NodeIf : public dp::Node {
public:
NodeIf() : Node("hex.builtin.nodes.control_flow.if.header",
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.control_flow.if.condition"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.control_flow.if.true"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.control_flow.if.false"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.common.output") }) { }
void process() override {
const auto &cond = this->getIntegerOnInput(0);
const auto &trueData = this->getBufferOnInput(1);
const auto &falseData = this->getBufferOnInput(2);
if (cond != 0)
this->setBufferOnOutput(3, trueData);
else
this->setBufferOnOutput(3, falseData);
}
};
class NodeEquals : public dp::Node {
public:
NodeEquals() : Node("hex.builtin.nodes.control_flow.equals.header",
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
void process() override {
const auto &inputA = this->getIntegerOnInput(0);
const auto &inputB = this->getIntegerOnInput(1);
this->setIntegerOnOutput(2, inputA == inputB);
}
};
class NodeNot : public dp::Node {
public:
NodeNot() : Node("hex.builtin.nodes.control_flow.not.header",
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
void process() override {
const auto &input = this->getIntegerOnInput(0);
this->setIntegerOnOutput(1, !input);
}
};
class NodeGreaterThan : public dp::Node {
public:
NodeGreaterThan() : Node("hex.builtin.nodes.control_flow.gt.header",
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
void process() override {
const auto &inputA = this->getIntegerOnInput(0);
const auto &inputB = this->getIntegerOnInput(1);
this->setIntegerOnOutput(2, inputA > inputB);
}
};
class NodeLessThan : public dp::Node {
public:
NodeLessThan() : Node("hex.builtin.nodes.control_flow.lt.header",
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
void process() override {
const auto &inputA = this->getIntegerOnInput(0);
const auto &inputB = this->getIntegerOnInput(1);
this->setIntegerOnOutput(2, inputA < inputB);
}
};
class NodeBoolAND : public dp::Node {
public:
NodeBoolAND() : Node("hex.builtin.nodes.control_flow.and.header",
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
void process() override {
const auto &inputA = this->getIntegerOnInput(0);
const auto &inputB = this->getIntegerOnInput(1);
this->setIntegerOnOutput(2, inputA && inputB);
}
};
class NodeBoolOR : public dp::Node {
public:
NodeBoolOR() : Node("hex.builtin.nodes.control_flow.or.header",
{ dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.a"),
dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.input.b"),
dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Integer, "hex.builtin.nodes.common.output") }) { }
void process() override {
const auto &inputA = this->getIntegerOnInput(0);
const auto &inputB = this->getIntegerOnInput(1);
this->setIntegerOnOutput(2, inputA || inputB);
}
};
void registerControlDataProcessorNodes() {
ContentRegistry::DataProcessorNode::add<NodeIf>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.if");
ContentRegistry::DataProcessorNode::add<NodeEquals>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.equals");
ContentRegistry::DataProcessorNode::add<NodeNot>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.not");
ContentRegistry::DataProcessorNode::add<NodeGreaterThan>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.gt");
ContentRegistry::DataProcessorNode::add<NodeLessThan>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.lt");
ContentRegistry::DataProcessorNode::add<NodeBoolAND>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.and");
ContentRegistry::DataProcessorNode::add<NodeBoolOR>("hex.builtin.nodes.control_flow", "hex.builtin.nodes.control_flow.or");
}
}