[Bf-blender-cvs] [fd3d5ae32eb] temp-derived-node-tree-refactor: add conversion/comparison operators and hash functions
Jacques Lucke
noreply at git.blender.org
Wed Mar 3 09:57:02 CET 2021
Commit: fd3d5ae32ebacd6a449d9ac38194b2a0341fa609
Author: Jacques Lucke
Date: Wed Mar 3 08:54:21 2021 +0100
Branches: temp-derived-node-tree-refactor
https://developer.blender.org/rBfd3d5ae32ebacd6a449d9ac38194b2a0341fa609
add conversion/comparison operators and hash functions
===================================================================
M source/blender/nodes/NOD_XXX_node_tree.hh
===================================================================
diff --git a/source/blender/nodes/NOD_XXX_node_tree.hh b/source/blender/nodes/NOD_XXX_node_tree.hh
index 314bad1993f..232d90d393a 100644
--- a/source/blender/nodes/NOD_XXX_node_tree.hh
+++ b/source/blender/nodes/NOD_XXX_node_tree.hh
@@ -20,8 +20,15 @@
namespace blender::nodes {
+class XXXNodeTreeContextInfo;
+class XXXNodeTreeContext;
class XXXNodeTree;
+struct XXXNode;
+struct XXXSocket;
+struct XXXInputSocket;
+struct XXXOutputSocket;
+
class XXXNodeTreeContextInfo {
private:
XXXNodeTreeContextInfo *parent_;
@@ -33,29 +40,62 @@ class XXXNodeTreeContextInfo {
class XXXNodeTreeContext {
private:
- XXXNodeTreeContextInfo *context_;
+ XXXNodeTreeContextInfo *context_ = nullptr;
friend XXXNodeTree;
+
+ public:
+ friend bool operator==(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b);
+ friend bool operator!=(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b);
+
+ uint64_t hash() const;
};
struct XXXNode {
XXXNodeTreeContext context;
- NodeRef *node;
+ const NodeRef *node = nullptr;
+
+ friend bool operator==(const XXXNode &a, const XXXNode &b);
+ friend bool operator!=(const XXXNode &a, const XXXNode &b);
+
+ uint64_t hash() const;
};
struct XXXSocket {
XXXNodeTreeContext context;
- SocketRef *socket;
+ const SocketRef *socket;
+
+ XXXSocket(const XXXInputSocket &input_socket);
+ XXXSocket(const XXXOutputSocket &output_socket);
+
+ friend bool operator==(const XXXSocket &a, const XXXSocket &b);
+ friend bool operator!=(const XXXSocket &a, const XXXSocket &b);
+
+ uint64_t hash() const;
};
struct XXXInputSocket {
XXXNodeTreeContext context;
- InputSocketRef *socket;
+ const InputSocketRef *socket = nullptr;
+
+ explicit XXXInputSocket(const XXXSocket &base_socket);
+
+ friend bool operator==(const XXXInputSocket &a, const XXXInputSocket &b);
+ friend bool operator!=(const XXXInputSocket &a, const XXXInputSocket &b);
+
+ uint64_t hash() const;
};
struct XXXOutputSocket {
XXXNodeTreeContext context;
- OutputSocketRef *socket;
+ const OutputSocketRef *socket = nullptr;
+
+ explicit XXXOutputSocket(const XXXSocket &base_socket);
+
+ friend bool operator==(const XXXOutputSocket &a, const XXXOutputSocket &b);
+ friend bool operator!=(const XXXOutputSocket &a, const XXXOutputSocket &b);
+
+ uint64_t hash() const;
};
class XXXNodeTree {
@@ -74,4 +114,121 @@ class XXXNodeTree {
void destruct_context_info_recursively(XXXNodeTreeContextInfo *context_info);
};
+/* --------------------------------------------------------------------
+ * XXXNodeTreeContext inline methods.
+ */
+
+inline bool operator==(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b)
+{
+ return a.context_ == b.context_;
+}
+
+inline bool operator!=(const XXXNodeTreeContext &a, const XXXNodeTreeContext &b)
+{
+ return !(a == b);
+}
+
+inline uint64_t XXXNodeTreeContext::hash() const
+{
+ return DefaultHash<XXXNodeTreeContextInfo *>{}(context_);
+}
+
+/* --------------------------------------------------------------------
+ * XXXNode inline methods.
+ */
+
+inline bool operator==(const XXXNode &a, const XXXNode &b)
+{
+ return a.context == b.context && a.node == b.node;
+}
+
+inline bool operator!=(const XXXNode &a, const XXXNode &b)
+{
+ return !(a == b);
+}
+
+inline uint64_t XXXNode::hash() const
+{
+ return DefaultHash<XXXNodeTreeContext>{}(context) ^ DefaultHash<const NodeRef *>{}(node);
+}
+
+/* --------------------------------------------------------------------
+ * XXXSocket inline methods.
+ */
+
+inline XXXSocket::XXXSocket(const XXXInputSocket &input_socket)
+ : context(input_socket.context), socket(input_socket.socket)
+{
+}
+
+inline XXXSocket::XXXSocket(const XXXOutputSocket &output_socket)
+ : context(output_socket.context), socket(output_socket.socket)
+{
+}
+
+inline bool operator==(const XXXSocket &a, const XXXSocket &b)
+{
+ return a.context == b.context && a.socket == b.socket;
+}
+
+inline bool operator!=(const XXXSocket &a, const XXXSocket &b)
+{
+ return !(a == b);
+}
+
+inline uint64_t XXXSocket::hash() const
+{
+ return DefaultHash<XXXNodeTreeContext>{}(context) ^ DefaultHash<const SocketRef *>{}(socket);
+}
+
+/* --------------------------------------------------------------------
+ * XXXInputSocket inline methods.
+ */
+
+inline XXXInputSocket::XXXInputSocket(const XXXSocket &base_socket)
+ : context(base_socket.context), socket(&base_socket.socket->as_input())
+{
+}
+
+inline bool operator==(const XXXInputSocket &a, const XXXInputSocket &b)
+{
+ return a.context == b.context && a.socket == b.socket;
+}
+
+inline bool operator!=(const XXXInputSocket &a, const XXXInputSocket &b)
+{
+ return !(a == b);
+}
+
+inline uint64_t XXXInputSocket::hash() const
+{
+ return DefaultHash<XXXNodeTreeContext>{}(context) ^
+ DefaultHash<const InputSocketRef *>{}(socket);
+}
+
+/* --------------------------------------------------------------------
+ * XXXOutputSocket inline methods.
+ */
+
+inline XXXOutputSocket::XXXOutputSocket(const XXXSocket &base_socket)
+ : context(base_socket.context), socket(&base_socket.socket->as_output())
+{
+}
+
+inline bool operator==(const XXXOutputSocket &a, const XXXOutputSocket &b)
+{
+ return a.context == b.context && a.socket == b.socket;
+}
+
+inline bool operator!=(const XXXOutputSocket &a, const XXXOutputSocket &b)
+{
+ return !(a == b);
+}
+
+inline uint64_t XXXOutputSocket::hash() const
+{
+ return DefaultHash<XXXNodeTreeContext>{}(context) ^
+ DefaultHash<const OutputSocketRef *>{}(socket);
+}
+
} // namespace blender::nodes
More information about the Bf-blender-cvs
mailing list