From 04a92297ddfb86b1766733461f01104bcbd5b38e Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 30 Mar 2021 12:27:53 +0200 Subject: Cleanup: Replace std::vector with blender::Vector. --- source/blender/compositor/intern/COM_Node.cc | 20 +++---- source/blender/compositor/intern/COM_Node.h | 64 +++++------------------ source/blender/compositor/intern/COM_NodeGraph.cc | 34 ++++-------- source/blender/compositor/intern/COM_NodeGraph.h | 2 - 4 files changed, 31 insertions(+), 89 deletions(-) (limited to 'source/blender/compositor/intern') diff --git a/source/blender/compositor/intern/COM_Node.cc b/source/blender/compositor/intern/COM_Node.cc index 517f23f13cd..6ac48e3646c 100644 --- a/source/blender/compositor/intern/COM_Node.cc +++ b/source/blender/compositor/intern/COM_Node.cc @@ -76,13 +76,11 @@ Node::Node(bNode *editorNode, bool create_sockets) Node::~Node() { - while (!this->m_outputsockets.empty()) { - delete (this->m_outputsockets.back()); - this->m_outputsockets.pop_back(); + while (!this->outputs.is_empty()) { + delete (this->outputs.pop_last()); } - while (!this->m_inputsockets.empty()) { - delete (this->m_inputsockets.back()); - this->m_inputsockets.pop_back(); + while (!this->inputs.is_empty()) { + delete (this->inputs.pop_last()); } } @@ -94,7 +92,7 @@ void Node::addInputSocket(DataType datatype) void Node::addInputSocket(DataType datatype, bNodeSocket *bSocket) { NodeInput *socket = new NodeInput(this, bSocket, datatype); - this->m_inputsockets.push_back(socket); + this->inputs.append(socket); } void Node::addOutputSocket(DataType datatype) @@ -104,19 +102,17 @@ void Node::addOutputSocket(DataType datatype) void Node::addOutputSocket(DataType datatype, bNodeSocket *bSocket) { NodeOutput *socket = new NodeOutput(this, bSocket, datatype); - this->m_outputsockets.push_back(socket); + outputs.append(socket); } NodeOutput *Node::getOutputSocket(unsigned int index) const { - BLI_assert(index < this->m_outputsockets.size()); - return this->m_outputsockets[index]; + return outputs[index]; } NodeInput *Node::getInputSocket(unsigned int index) const { - BLI_assert(index < this->m_inputsockets.size()); - return this->m_inputsockets[index]; + return inputs[index]; } bNodeSocket *Node::getEditorInputSocket(int editorNodeInputSocketIndex) diff --git a/source/blender/compositor/intern/COM_Node.h b/source/blender/compositor/intern/COM_Node.h index 5b168ef87fd..9aca1a8ff44 100644 --- a/source/blender/compositor/intern/COM_Node.h +++ b/source/blender/compositor/intern/COM_Node.h @@ -18,10 +18,12 @@ #pragma once +#include "BLI_vector.hh" + #include "DNA_node_types.h" + #include #include -#include /* common node includes * added here so node files don't have to include themselves @@ -38,10 +40,6 @@ class NodeConverter; * My node documentation. */ class Node { - public: - typedef std::vector Inputs; - typedef std::vector Outputs; - private: /** * \brief stores the reference to the SDNA bNode struct @@ -53,16 +51,6 @@ class Node { */ bNode *m_editorNode; - /** - * \brief the list of actual inputsockets \see NodeInput - */ - Inputs m_inputsockets; - - /** - * \brief the list of actual outputsockets \see NodeOutput - */ - Outputs m_outputsockets; - /** * \brief Is this node part of the active group */ @@ -75,20 +63,14 @@ class Node { protected: /** - * \brief get access to the vector of input sockets + * \brief the list of actual inputsockets \see NodeInput */ - const Inputs &getInputSockets() const - { - return this->m_inputsockets; - } + blender::Vector inputs; /** - * \brief get access to the vector of input sockets + * \brief the list of actual outputsockets \see NodeOutput */ - const Outputs &getOutputSockets() const - { - return this->m_outputsockets; - } + blender::Vector outputs; public: Node(bNode *editorNode, bool create_sockets = true); @@ -131,19 +113,19 @@ class Node { } /** - * \brief Return the number of input sockets of this node. + * \brief get access to the vector of input sockets */ - unsigned int getNumberOfInputSockets() const + const blender::Vector &getInputSockets() const { - return this->m_inputsockets.size(); + return this->inputs; } /** - * \brief Return the number of output sockets of this node. + * \brief get access to the vector of input sockets */ - unsigned int getNumberOfOutputSockets() const + const blender::Vector &getOutputSockets() const { - return this->m_outputsockets.size(); + return this->outputs; } /** @@ -151,17 +133,7 @@ class Node { * \param index: * the index of the needed outputsocket */ - NodeOutput *getOutputSocket(const unsigned int index) const; - - /** - * get the reference to the first outputsocket - * \param index: - * the index of the needed outputsocket - */ - inline NodeOutput *getOutputSocket() const - { - return getOutputSocket(0); - } + NodeOutput *getOutputSocket(const unsigned int index = 0) const; /** * get the reference to a certain inputsocket @@ -170,14 +142,6 @@ class Node { */ NodeInput *getInputSocket(const unsigned int index) const; - /** Check if this is an input node - * An input node is a node that only has output sockets and no input sockets - */ - bool isInputNode() const - { - return m_inputsockets.empty(); - } - /** * \brief Is this node in the active group (the group that is being edited) * \param isInActiveGroup: diff --git a/source/blender/compositor/intern/COM_NodeGraph.cc b/source/blender/compositor/intern/COM_NodeGraph.cc index 53b912fe5e4..7e05bf637b7 100644 --- a/source/blender/compositor/intern/COM_NodeGraph.cc +++ b/source/blender/compositor/intern/COM_NodeGraph.cc @@ -45,9 +45,8 @@ NodeGraph::NodeGraph() NodeGraph::~NodeGraph() { - for (int index = 0; index < this->m_nodes.size(); index++) { - Node *node = this->m_nodes[index]; - delete node; + while (m_nodes.size()) { + delete m_nodes.pop_last(); } } @@ -155,27 +154,11 @@ void NodeGraph::add_bNode(const CompositorContext &context, } } -NodeGraph::NodeInputs NodeGraph::find_inputs(const NodeRange &node_range, bNodeSocket *b_socket) -{ - NodeInputs result; - for (blender::Vector::iterator it = node_range.first; it != node_range.second; ++it) { - Node *node = *it; - for (int index = 0; index < node->getNumberOfInputSockets(); index++) { - NodeInput *input = node->getInputSocket(index); - if (input->getbNodeSocket() == b_socket) { - result.push_back(input); - } - } - } - return result; -} - NodeOutput *NodeGraph::find_output(const NodeRange &node_range, bNodeSocket *b_socket) { for (blender::Vector::iterator it = node_range.first; it != node_range.second; ++it) { Node *node = *it; - for (int index = 0; index < node->getNumberOfOutputSockets(); index++) { - NodeOutput *output = node->getOutputSocket(index); + for (NodeOutput *output : node->getOutputSockets()) { if (output->getbNodeSocket() == b_socket) { return output; } @@ -204,12 +187,13 @@ void NodeGraph::add_bNodeLink(const NodeRange &node_range, bNodeLink *b_nodelink return; } - NodeInputs inputs = find_inputs(node_range, b_nodelink->tosock); - for (NodeInput *input : inputs) { - if (input->isLinked()) { - continue; + for (blender::Vector::iterator it = node_range.first; it != node_range.second; ++it) { + Node *node = *it; + for (NodeInput *input : node->getInputSockets()) { + if (input->getbNodeSocket() == b_nodelink->tosock && !input->isLinked()) { + add_link(output, input); + } } - add_link(output, input); } } diff --git a/source/blender/compositor/intern/COM_NodeGraph.h b/source/blender/compositor/intern/COM_NodeGraph.h index 156a315933c..9347df5d9e2 100644 --- a/source/blender/compositor/intern/COM_NodeGraph.h +++ b/source/blender/compositor/intern/COM_NodeGraph.h @@ -73,7 +73,6 @@ class NodeGraph { protected: typedef std::pair::iterator, blender::Vector::iterator> NodeRange; - typedef std::vector NodeInputs; static bNodeSocket *find_b_node_input(bNode *b_node, const char *identifier); static bNodeSocket *find_b_node_output(bNode *b_node, const char *identifier); @@ -92,7 +91,6 @@ class NodeGraph { bNodeInstanceKey key, bool is_active_group); - NodeInputs find_inputs(const NodeRange &node_range, bNodeSocket *b_socket); NodeOutput *find_output(const NodeRange &node_range, bNodeSocket *b_socket); void add_bNodeLink(const NodeRange &node_range, bNodeLink *b_nodelink); -- cgit v1.2.3