From 6524ceb8cfa53e2209b73023cfa16d1b58b1247e Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 26 Mar 2021 15:49:21 +0100 Subject: Cleanup: Remove ptr For Owned Children. --- .../blender/compositor/intern/COM_NodeOperation.cc | 40 ++-- .../blender/compositor/intern/COM_NodeOperation.h | 205 ++++++++++----------- 2 files changed, 116 insertions(+), 129 deletions(-) (limited to 'source/blender/compositor/intern') diff --git a/source/blender/compositor/intern/COM_NodeOperation.cc b/source/blender/compositor/intern/COM_NodeOperation.cc index 195073545ec..e68c53bd7b2 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cc +++ b/source/blender/compositor/intern/COM_NodeOperation.cc @@ -39,38 +39,24 @@ NodeOperation::NodeOperation() this->m_btree = nullptr; } -NodeOperation::~NodeOperation() +NodeOperationOutput *NodeOperation::getOutputSocket(unsigned int index) { - while (!this->m_outputs.is_empty()) { - delete (this->m_outputs.pop_last()); - } - while (!this->m_inputs.is_empty()) { - delete (this->m_inputs.pop_last()); - } -} - -NodeOperationOutput *NodeOperation::getOutputSocket(unsigned int index) const -{ - BLI_assert(index < m_outputs.size()); - return m_outputs[index]; + return &m_outputs[index]; } -NodeOperationInput *NodeOperation::getInputSocket(unsigned int index) const +NodeOperationInput *NodeOperation::getInputSocket(unsigned int index) { - BLI_assert(index < m_inputs.size()); - return m_inputs[index]; + return &m_inputs[index]; } void NodeOperation::addInputSocket(DataType datatype, ResizeMode resize_mode) { - NodeOperationInput *socket = new NodeOperationInput(this, datatype, resize_mode); - m_inputs.append(socket); + m_inputs.append(NodeOperationInput(this, datatype, resize_mode)); } void NodeOperation::addOutputSocket(DataType datatype) { - NodeOperationOutput *socket = new NodeOperationOutput(this, datatype); - m_outputs.append(socket); + m_outputs.append(NodeOperationOutput(this, datatype)); } void NodeOperation::determineResolution(unsigned int resolution[2], @@ -79,11 +65,12 @@ void NodeOperation::determineResolution(unsigned int resolution[2], unsigned int temp[2]; unsigned int temp2[2]; + // TODO(jbakker): Replace for loops with direct array access. for (unsigned int index = 0; index < m_inputs.size(); index++) { - NodeOperationInput *input = m_inputs[index]; - if (input->isConnected()) { + NodeOperationInput &input = m_inputs[index]; + if (input.isConnected()) { if (index == this->m_resolutionInputSocketIndex) { - input->determineResolution(resolution, preferredResolution); + input.determineResolution(resolution, preferredResolution); temp2[0] = resolution[0]; temp2[1] = resolution[1]; break; @@ -91,14 +78,15 @@ void NodeOperation::determineResolution(unsigned int resolution[2], } } for (unsigned int index = 0; index < m_inputs.size(); index++) { - NodeOperationInput *input = m_inputs[index]; - if (input->isConnected()) { + NodeOperationInput &input = m_inputs[index]; + if (input.isConnected()) { if (index != this->m_resolutionInputSocketIndex) { - input->determineResolution(temp, temp2); + input.determineResolution(temp, temp2); } } } } + void NodeOperation::setResolutionInputSocketIndex(unsigned int index) { this->m_resolutionInputSocketIndex = index; diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h index 3836268c63c..5b9375ae531 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.h +++ b/source/blender/compositor/intern/COM_NodeOperation.h @@ -37,9 +37,6 @@ class OpenCLDevice; class ReadBufferOperation; class WriteBufferOperation; -class NodeOperationInput; -class NodeOperationOutput; - class NodeOperation; typedef NodeOperation SocketReader; @@ -73,6 +70,99 @@ enum class PixelSampler { Bicubic = 2, }; +class NodeOperationInput { + private: + NodeOperation *m_operation; + + /** Datatype of this socket. Is used for automatically data transformation. + * \section data-conversion + */ + DataType m_datatype; + + /** Resize mode of this socket */ + ResizeMode m_resizeMode; + + /** Connected output */ + NodeOperationOutput *m_link; + + public: + NodeOperationInput(NodeOperation *op, + DataType datatype, + ResizeMode resizeMode = ResizeMode::Center); + + NodeOperation &getOperation() const + { + return *m_operation; + } + DataType getDataType() const + { + return m_datatype; + } + + void setLink(NodeOperationOutput *link) + { + m_link = link; + } + NodeOperationOutput *getLink() const + { + return m_link; + } + bool isConnected() const + { + return m_link; + } + + void setResizeMode(ResizeMode resizeMode) + { + this->m_resizeMode = resizeMode; + } + ResizeMode getResizeMode() const + { + return this->m_resizeMode; + } + + SocketReader *getReader(); + + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") +#endif +}; + +class NodeOperationOutput { + private: + NodeOperation *m_operation; + + /** Datatype of this socket. Is used for automatically data transformation. + * \section data-conversion + */ + DataType m_datatype; + + public: + NodeOperationOutput(NodeOperation *op, DataType datatype); + + NodeOperation &getOperation() const + { + return *m_operation; + } + DataType getDataType() const + { + return m_datatype; + } + + /** + * \brief determine the resolution of this data going through this socket + * \param resolution: the result of this operation + * \param preferredResolution: the preferable resolution as no resolution could be determined + */ + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); + +#ifdef WITH_CXX_GUARDEDALLOC + MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") +#endif +}; + /** * \brief NodeOperation contains calculation logic * @@ -81,8 +171,8 @@ enum class PixelSampler { */ class NodeOperation { private: - blender::Vector m_inputs; - blender::Vector m_outputs; + blender::Vector m_inputs; + blender::Vector m_outputs; /** * \brief the index of the input socket that will be used to determine the resolution @@ -136,7 +226,9 @@ class NodeOperation { unsigned int m_height; public: - virtual ~NodeOperation(); + virtual ~NodeOperation() + { + } unsigned int getNumberOfInputSockets() const { @@ -146,12 +238,12 @@ class NodeOperation { { return m_outputs.size(); } - NodeOperationOutput *getOutputSocket(unsigned int index) const; - NodeOperationOutput *getOutputSocket() const + NodeOperationOutput *getOutputSocket(unsigned int index); + NodeOperationOutput *getOutputSocket() { return getOutputSocket(0); } - NodeOperationInput *getInputSocket(unsigned int index) const; + NodeOperationInput *getInputSocket(unsigned int index); /** Check if this is an input operation * An input operation is an operation that only has output sockets and no input sockets @@ -430,7 +522,7 @@ class NodeOperation { * Return the meta data associated with this branch. * * The return parameter holds an instance or is an nullptr. */ - virtual std::unique_ptr getMetaData() const + virtual std::unique_ptr getMetaData() { return std::unique_ptr(); } @@ -529,96 +621,3 @@ class NodeOperation { MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") #endif }; - -class NodeOperationInput { - private: - NodeOperation *m_operation; - - /** Datatype of this socket. Is used for automatically data transformation. - * \section data-conversion - */ - DataType m_datatype; - - /** Resize mode of this socket */ - ResizeMode m_resizeMode; - - /** Connected output */ - NodeOperationOutput *m_link; - - public: - NodeOperationInput(NodeOperation *op, - DataType datatype, - ResizeMode resizeMode = ResizeMode::Center); - - NodeOperation &getOperation() const - { - return *m_operation; - } - DataType getDataType() const - { - return m_datatype; - } - - void setLink(NodeOperationOutput *link) - { - m_link = link; - } - NodeOperationOutput *getLink() const - { - return m_link; - } - bool isConnected() const - { - return m_link; - } - - void setResizeMode(ResizeMode resizeMode) - { - this->m_resizeMode = resizeMode; - } - ResizeMode getResizeMode() const - { - return this->m_resizeMode; - } - - SocketReader *getReader(); - - void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") -#endif -}; - -class NodeOperationOutput { - private: - NodeOperation *m_operation; - - /** Datatype of this socket. Is used for automatically data transformation. - * \section data-conversion - */ - DataType m_datatype; - - public: - NodeOperationOutput(NodeOperation *op, DataType datatype); - - NodeOperation &getOperation() const - { - return *m_operation; - } - DataType getDataType() const - { - return m_datatype; - } - - /** - * \brief determine the resolution of this data going through this socket - * \param resolution: the result of this operation - * \param preferredResolution: the preferable resolution as no resolution could be determined - */ - void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") -#endif -}; -- cgit v1.2.3