[Bf-blender-cvs] [04a92297ddf] master: Cleanup: Replace std::vector with blender::Vector.

Jeroen Bakker noreply at git.blender.org
Tue Mar 30 16:06:22 CEST 2021


Commit: 04a92297ddfb86b1766733461f01104bcbd5b38e
Author: Jeroen Bakker
Date:   Tue Mar 30 12:27:53 2021 +0200
Branches: master
https://developer.blender.org/rB04a92297ddfb86b1766733461f01104bcbd5b38e

Cleanup: Replace std::vector with blender::Vector.

===================================================================

M	source/blender/compositor/intern/COM_Node.cc
M	source/blender/compositor/intern/COM_Node.h
M	source/blender/compositor/intern/COM_NodeGraph.cc
M	source/blender/compositor/intern/COM_NodeGraph.h
M	source/blender/compositor/nodes/COM_CryptomatteNode.cc
M	source/blender/compositor/nodes/COM_ImageNode.cc
M	source/blender/compositor/nodes/COM_OutputFileNode.cc
M	source/blender/compositor/nodes/COM_RenderLayersNode.cc
M	source/blender/compositor/operations/COM_CryptomatteOperation.cc
M	source/blender/compositor/operations/COM_CryptomatteOperation.h
M	source/blender/compositor/operations/COM_OutputFileOperation.cc
M	source/blender/compositor/operations/COM_OutputFileOperation.h

===================================================================

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 <algorithm>
 #include <string>
-#include <vector>
 
 /* 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<NodeInput *> Inputs;
-  typedef std::vector<NodeOutput *> 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<NodeInput *> 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<NodeOutput *> 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<NodeInput *> &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<NodeOutput *> &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<Node *>::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<Node *>::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<Node *>::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<blender::Vector<Node *>::iterator, blender::Vector<Node *>::iterator>
       NodeRange;
-  typedef std::vector<NodeInput *> 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);
 
diff --git a/source/blender/compositor/nodes/COM_CryptomatteNode.cc b/source/blender/compositor/nodes/COM_CryptomatteNode.cc
index 89caff047b4..23305fa06f8 100644
--- a/source/blender/compositor/nodes/COM_CryptomatteNode.cc
+++ b/source/blender/compositor/nodes/COM_CryptomatteNode.cc
@@ -254,7 +254,7 @@ CryptomatteOperation *CryptomatteLegacyNode::create_cryptomatte_operation(
     const bNode &UNUSED(node),
     const NodeCryptomatte *cryptomatte_settings) const
 {
-  const int num_inputs = getNumberOfInputSockets() - 1;
+  const int num_inputs = inputs.size() - 1;
   CryptomatteOperation *operation = new CryptomatteOperation(num_inputs);
   if (cryptomatte_settings) {
     LISTBASE_FOREACH (CryptomatteEntry *, cryptomatte_entry, &cryptomatte_settings->entries) {
diff --git a/source/blender/compositor/nodes/COM_ImageNode.cc b/source/blender/compositor/nodes/COM_ImageNode.cc
index 380773eca64..092cf836a41 100644
--- a/source/blender/compositor/nodes/COM_ImageNode.cc
+++ b/source/blender/compositor/nodes/COM_ImageNode.cc
@@ -79,7 +79,6 @@ void ImageNode::convertToOperations(NodeConverter &converter,
   Image *image = (Image *)editorNode->id;
   ImageUser *imageuser = (ImageUser *)editorNode->storage;
   int framenumber = context.getFramenumber();
-  int numberOfOutputs = this->getNumberOfOutputSockets();
   bool outputStraightAlpha = (editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT) != 0;
   BKE_image_user_frame_calc(image, imageuser, context.getFramenumber());
   /* force a load, we assume iuser index will be set OK anyway */
@@ -89,14 +88,12 @@ void ImageNode::convertToOperations(NodeConverter &converter,
     if (image->rr) {
       RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer);
       if (rl) {
-        NodeOutput *socket;
         int index;
 
         is_multilayer_ok = t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list