From 4f4dd966020eb7b34bf24a6b3479e86dd1ae0082 Mon Sep 17 00:00:00 2001 From: lnd3 Date: Sun, 29 Sep 2024 21:38:44 +0200 Subject: [PATCH] Add copy/move constructors for node graph to make serialization work later. --- .../include/nodegraph/NodeGraphSchema.h | 27 +++++++++++++++++++ .../include/nodegraph/core/NodeGraphBase.h | 27 +++++++++++++++++++ .../include/nodegraph/core/NodeGraphGroup.h | 15 ++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/packages/nodegraph/include/nodegraph/NodeGraphSchema.h b/packages/nodegraph/include/nodegraph/NodeGraphSchema.h index 691994a..1693c74 100644 --- a/packages/nodegraph/include/nodegraph/NodeGraphSchema.h +++ b/packages/nodegraph/include/nodegraph/NodeGraphSchema.h @@ -101,6 +101,33 @@ namespace l::nodegraph { ~NodeGraphSchema() = default; + NodeGraphSchema& operator=(NodeGraphSchema&& other) noexcept { + mMainNodeGraph = std::move(other.mMainNodeGraph); + mName = std::move(other.mName); + mRegisteredNodeTypes = std::move(other.mRegisteredNodeTypes); + mCreateCustomNode = other.mCreateCustomNode; + mKeyState = other.mKeyState; + mAudioOutput = other.mAudioOutput; + mMidiManager = other.mMidiManager; + return *this; + } + NodeGraphSchema& operator=(const NodeGraphSchema& other) noexcept { + mMainNodeGraph = other.mMainNodeGraph; + mName = other.mName; + mRegisteredNodeTypes = other.mRegisteredNodeTypes; + mCreateCustomNode = other.mCreateCustomNode; + mKeyState = other.mKeyState; + mAudioOutput = other.mAudioOutput; + mMidiManager = other.mMidiManager; + return *this; + } + NodeGraphSchema(NodeGraphSchema&& other) noexcept { + *this = std::move(other); + } + NodeGraphSchema(const NodeGraphSchema& other) noexcept { + *this = other; + } + void SetName(std::string_view name) { mName = name; } diff --git a/packages/nodegraph/include/nodegraph/core/NodeGraphBase.h b/packages/nodegraph/include/nodegraph/core/NodeGraphBase.h index 431bc00..6294eed 100644 --- a/packages/nodegraph/include/nodegraph/core/NodeGraphBase.h +++ b/packages/nodegraph/include/nodegraph/core/NodeGraphBase.h @@ -32,6 +32,33 @@ namespace l::nodegraph { LOG(LogInfo) << "Node graph base destroyed"; } + NodeGraphBase& operator=(NodeGraphBase&& other) noexcept { + this->mId = other.mId; + //this->mInputs = std::move(other.mInputs); + //this->mOutputs = std::move(other.mOutputs); + this->mName = std::move(other.mName); + this->mLastTickCount = other.mLastTickCount; + this->mOutputType = other.mOutputType; + this->mProcessUpdateHasRun = other.mProcessUpdateHasRun; + return *this; + } + NodeGraphBase& operator=(const NodeGraphBase& other) noexcept { + this->mId = other.mId; + //this->mInputs = std::move(other.mInputs); + //this->mOutputs = std::move(other.mOutputs); + this->mName = std::move(other.mName); + this->mLastTickCount = other.mLastTickCount; + this->mOutputType = other.mOutputType; + this->mProcessUpdateHasRun = other.mProcessUpdateHasRun; + return *this; + } + NodeGraphBase(NodeGraphBase&& other) noexcept { + *this = std::move(other); + } + NodeGraphBase(const NodeGraphBase& other) noexcept { + *this = other; + } + virtual void Reset(); virtual void SetId(int32_t id) { mId = id; } virtual int32_t GetId() const { return mId; } diff --git a/packages/nodegraph/include/nodegraph/core/NodeGraphGroup.h b/packages/nodegraph/include/nodegraph/core/NodeGraphGroup.h index 276d952..bef111c 100644 --- a/packages/nodegraph/include/nodegraph/core/NodeGraphGroup.h +++ b/packages/nodegraph/include/nodegraph/core/NodeGraphGroup.h @@ -40,6 +40,19 @@ namespace l::nodegraph { LOG(LogInfo) << "Node group destroyed"; } + NodeGraphGroup& operator=(NodeGraphGroup&&) noexcept { + return *this; + } + NodeGraphGroup& operator=(const NodeGraphGroup&) noexcept { + return *this; + } + NodeGraphGroup(NodeGraphGroup&& other) noexcept { + *this = std::move(other); + } + NodeGraphGroup(const NodeGraphGroup& other) noexcept { + *this = other; + } + void SetNumInputs(int8_t numInputs); void SetNumOutputs(int8_t outputCount); void SetInput(int8_t inputChannel, NodeGraphBase& source, int8_t sourceOutputChannel); @@ -62,7 +75,7 @@ namespace l::nodegraph { template, int> = 0> l::nodegraph::NodeGraphBase* NewNode(OutputType nodeType, Params&&... params) { - mNodes.push_back(std::make_unique>(nodeType, std::forward(params)...)); + mNodes.emplace_back(std::make_unique>(nodeType, std::forward(params)...)); auto nodePtr = mNodes.back().get(); if (nodeType == OutputType::ExternalOutput || nodeType == OutputType::ExternalVisualOutput) { mOutputNodes.push_back(nodePtr);