feat: operator nm getter and operator input setting
This commit is contained in:
@@ -23,5 +23,21 @@ enzo::nt::NetworkManager* enzo::nt::NetworkManager::getInstance()
|
|||||||
return instancePtr_;
|
return instancePtr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enzo::nt::GeometryOperator& enzo::nt::NetworkManager::getGeoOperator(nt::OpId opId)
|
||||||
|
{
|
||||||
|
return *gopStore_.at(opId);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enzo::nt::NetworkManager::isValidOp(nt::OpId opId)
|
||||||
|
{
|
||||||
|
auto it = gopStore_.find(opId);
|
||||||
|
if( it == gopStore_.end() || it->second==nullptr )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
enzo::nt::NetworkManager* enzo::nt::NetworkManager::instancePtr_ = nullptr;
|
enzo::nt::NetworkManager* enzo::nt::NetworkManager::instancePtr_ = nullptr;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ public:
|
|||||||
|
|
||||||
static NetworkManager* getInstance();
|
static NetworkManager* getInstance();
|
||||||
|
|
||||||
|
bool isValidOp(nt::OpId opId);
|
||||||
|
GeometryOperator& getGeoOperator(nt::OpId opId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static NetworkManager* instancePtr_;
|
static NetworkManager* instancePtr_;
|
||||||
NetworkManager() {};
|
NetworkManager() {};
|
||||||
|
|||||||
@@ -1,9 +1,55 @@
|
|||||||
#include "Engine/Operator/GeometryOperator.h"
|
#include "Engine/Operator/GeometryOperator.h"
|
||||||
#include <cstdint>
|
#include <optional>
|
||||||
|
|
||||||
using namespace enzo;
|
using namespace enzo;
|
||||||
|
|
||||||
nt::GeometryOperator::GeometryOperator()
|
nt::GeometryOperator::GeometryOperator()
|
||||||
{
|
{
|
||||||
|
// TODO: drive by geometry definition
|
||||||
|
maxInputs_=4;
|
||||||
|
maxOutputs_=4;
|
||||||
|
|
||||||
|
inputIds_ = std::vector<std::optional<nt::OpId>>(maxInputs_, std::nullopt);
|
||||||
|
outputIds_ = std::vector<std::optional<nt::OpId>>(maxOutputs_, std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nt::GeometryOperator::setInput(unsigned int inputNumber, nt::OpId opId)
|
||||||
|
{
|
||||||
|
if(inputNumber>=maxInputs_)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inputIds_[inputNumber] = opId;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool nt::GeometryOperator::setOutput(unsigned int outputNumber, nt::OpId opId)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(outputNumber>=maxOutputs_)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
inputIds_[outputNumber] = opId;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<nt::OpId> nt::GeometryOperator::getInput(unsigned int inputNumber) const
|
||||||
|
{
|
||||||
|
if(inputNumber>=maxInputs_)
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return inputIds_.at(inputNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<nt::OpId> nt::GeometryOperator::getOutput(unsigned int outputNumber) const
|
||||||
|
{
|
||||||
|
if(outputNumber>=maxOutputs_)
|
||||||
|
{
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return outputIds_.at(outputNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace enzo::nt {
|
namespace enzo::nt {
|
||||||
|
|
||||||
@@ -7,9 +8,16 @@ class GeometryOperator
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeometryOperator();
|
GeometryOperator();
|
||||||
// nodeDef
|
bool setInput(unsigned int inputNumber, nt::OpId opId);
|
||||||
|
bool setOutput(unsigned int outputNumber, nt::OpId opId);
|
||||||
|
std::optional<nt::OpId> getInput(unsigned int inputNumber) const;
|
||||||
|
std::optional<nt::OpId> getOutput(unsigned int outputNumber) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector<std::optional<nt::OpId>> inputIds_;
|
||||||
|
std::vector<std::optional<nt::OpId>> outputIds_;
|
||||||
|
unsigned int maxInputs_;
|
||||||
|
unsigned int maxOutputs_;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,25 @@
|
|||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
|
#include "Engine/Operator/GeometryOperator.h"
|
||||||
|
#include "Engine/Types.h"
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("network")
|
TEST_CASE("network")
|
||||||
{
|
{
|
||||||
using namespace enzo;
|
using namespace enzo;
|
||||||
nt::NetworkManager* nm = nt::NetworkManager::getInstance();
|
nt::NetworkManager* nm = nt::NetworkManager::getInstance();
|
||||||
nm->addOperator();
|
nt::OpId newOpId = nm->addOperator();
|
||||||
|
nt::OpId newOpId2 = nm->addOperator();
|
||||||
|
|
||||||
|
REQUIRE(nm->isValidOp(newOpId));
|
||||||
|
if(nm->isValidOp(newOpId))
|
||||||
|
{
|
||||||
|
nt::GeometryOperator& newOp = nm->getGeoOperator(newOpId);
|
||||||
|
REQUIRE(newOp.setInput(0, newOpId2));
|
||||||
|
|
||||||
|
std::optional<nt::OpId> returnOpId = newOp.getInput(0);
|
||||||
|
REQUIRE(returnOpId.has_value());
|
||||||
|
REQUIRE(*returnOpId==newOpId2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user