Skip to content

Commit

Permalink
Add copy/move constructors for node graph to make serialization work …
Browse files Browse the repository at this point in the history
…later.
  • Loading branch information
linuscu committed Sep 29, 2024
1 parent 89b20f4 commit 4f4dd96
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/nodegraph/include/nodegraph/NodeGraphSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions packages/nodegraph/include/nodegraph/core/NodeGraphBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
15 changes: 14 additions & 1 deletion packages/nodegraph/include/nodegraph/core/NodeGraphGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -62,7 +75,7 @@ namespace l::nodegraph {

template<class T, class... Params, std::enable_if_t<std::is_base_of_v<NodeGraphOp, T>, int> = 0>
l::nodegraph::NodeGraphBase* NewNode(OutputType nodeType, Params&&... params) {
mNodes.push_back(std::make_unique<l::nodegraph::NodeGraph<T, Params...>>(nodeType, std::forward<Params>(params)...));
mNodes.emplace_back(std::make_unique<l::nodegraph::NodeGraph<T, Params...>>(nodeType, std::forward<Params>(params)...));
auto nodePtr = mNodes.back().get();
if (nodeType == OutputType::ExternalOutput || nodeType == OutputType::ExternalVisualOutput) {
mOutputNodes.push_back(nodePtr);
Expand Down

0 comments on commit 4f4dd96

Please sign in to comment.