[Bf-blender-cvs] [2bc0a886f12] temp-compact-node-prototype: cleanup
Jacques Lucke
noreply at git.blender.org
Thu Mar 25 16:11:06 CET 2021
Commit: 2bc0a886f1283187803d0783ee1a4b40a6d7d1d1
Author: Jacques Lucke
Date: Thu Mar 25 13:15:48 2021 +0100
Branches: temp-compact-node-prototype
https://developer.blender.org/rB2bc0a886f1283187803d0783ee1a4b40a6d7d1d1
cleanup
===================================================================
M source/blender/blenlib/BLI_hash.hh
A source/blender/blenlib/BLI_heap_value.hh
M source/blender/blenlib/CMakeLists.txt
M source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh
index 39695b110b1..f4cb6e6c778 100644
--- a/source/blender/blenlib/BLI_hash.hh
+++ b/source/blender/blenlib/BLI_hash.hh
@@ -222,4 +222,13 @@ template<typename T1, typename T2> struct DefaultHash<std::pair<T1, T2>> {
}
};
+template<typename T1, typename T2, typename T3>
+uint64_t default_hash_3(const T1 &v1, const T2 &v2, const T3 &v3)
+{
+ const uint64_t h1 = DefaultHash<T1>{}(v1);
+ const uint64_t h2 = DefaultHash<T2>{}(v2);
+ const uint64_t h3 = DefaultHash<T3>{}(v3);
+ return (h1 * 73856093) ^ (h2 * 19349663) ^ (h3 * 83492791);
+}
+
} // namespace blender
diff --git a/source/blender/blenlib/BLI_heap_value.hh b/source/blender/blenlib/BLI_heap_value.hh
new file mode 100644
index 00000000000..c1bdd2799d2
--- /dev/null
+++ b/source/blender/blenlib/BLI_heap_value.hh
@@ -0,0 +1,198 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bli
+ */
+
+#include "BLI_hash.hh"
+
+namespace blender {
+
+template<typename T> class HeapValue {
+ private:
+ T *value_ = nullptr;
+
+ public:
+ HeapValue(T value)
+ {
+ value_ = new T(std::move(value));
+ }
+
+ HeapValue(const HeapValue &other)
+ {
+ if (other.value_ != nullptr) {
+ value_ = new T(*other.value_);
+ }
+ }
+
+ HeapValue(HeapValue &&other)
+ {
+ value_ = other.value_;
+ other.value_ = nullptr;
+ }
+
+ ~HeapValue()
+ {
+ delete value_;
+ }
+
+ HeapValue &operator=(const HeapValue &other)
+ {
+ if (this == &other) {
+ return *this;
+ }
+ if (value_ != nullptr) {
+ if (other.value_ != nullptr) {
+ *value_ = *other.value_;
+ }
+ else {
+ delete value_;
+ value_ = nullptr;
+ }
+ }
+ else {
+ if (other.value_ != nullptr) {
+ value_ = new T(*other.value_);
+ }
+ else {
+ /* Do nothing. */
+ }
+ }
+ return *this;
+ }
+
+ HeapValue &operator=(HeapValue &&other)
+ {
+ if (this == &other) {
+ return *this;
+ }
+ delete value_;
+ value_ = other.value_;
+ other.value_ = nullptr;
+ return *this;
+ }
+
+ HeapValue &operator=(T value)
+ {
+ if (value_ == nullptr) {
+ value_ = new T(std::move(value));
+ }
+ else {
+ *value_ = std::move(value);
+ }
+ }
+
+ operator bool() const
+ {
+ return value_ != nullptr;
+ }
+
+ T &operator*()
+ {
+ BLI_assert(value_ != nullptr);
+ return *value_;
+ }
+
+ const T &operator*() const
+ {
+ BLI_assert(value_ != nullptr);
+ return *value_;
+ }
+
+ T *operator->()
+ {
+ BLI_assert(value_ != nullptr);
+ return value_;
+ }
+
+ const T *operator->() const
+ {
+ BLI_assert(value_ != nullptr);
+ return value_;
+ }
+
+ T *get()
+ {
+ return value_;
+ }
+
+ const T *get() const
+ {
+ return value_;
+ }
+
+ friend bool operator==(const HeapValue &a, const HeapValue &b)
+ {
+ if (a.value_ == nullptr && b.value_ == nullptr) {
+ return true;
+ }
+ if (a.value_ == nullptr) {
+ return false;
+ }
+ if (b.value_ == nullptr) {
+ return false;
+ }
+ return *a.value_ == *b.value_;
+ }
+
+ friend bool operator==(const HeapValue &a, const T &b)
+ {
+ if (a.value_ == nullptr) {
+ return false;
+ }
+ return *a.value_ == b;
+ }
+
+ friend bool operator==(const T &a, const HeapValue &b)
+ {
+ return b == a;
+ }
+
+ friend bool operator!=(const HeapValue &a, const HeapValue &b)
+ {
+ return !(a == b);
+ }
+
+ friend bool operator!=(const HeapValue &a, const T &b)
+ {
+ return !(a == b);
+ }
+
+ friend bool operator!=(const T &a, const HeapValue &b)
+ {
+ return !(a == b);
+ }
+};
+
+template<typename T> struct DefaultHash<HeapValue<T>> {
+ uint64_t operator()(const HeapValue<T> &value) const
+ {
+ if (value) {
+ return DefaultHash<T>{}(*value);
+ }
+ return 0;
+ }
+
+ uint64_t operator()(const T &value) const
+ {
+ return DefaultHash<T>{}(value);
+ }
+};
+
+} // namespace blender
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 37b0f742b8b..f4aef277595 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -203,6 +203,7 @@ set(SRC
BLI_hash_tables.hh
BLI_heap.h
BLI_heap_simple.h
+ BLI_heap_value.hh
BLI_index_mask.hh
BLI_index_range.hh
BLI_inplace_priority_queue.hh
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
index f0d3863fc06..ea5c85fddb6 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
@@ -16,6 +16,7 @@
#include "node_geometry_util.hh"
+#include "BLI_heap_value.hh"
#include "BLI_rand.hh"
#include "DNA_mesh_types.h"
@@ -71,193 +72,8 @@ static void geo_node_attribute_fill_update(bNodeTree *UNUSED(ntree), bNode *node
nodeSetSocketAvailability(socket_value_int32, data_type == CD_PROP_INT32);
}
-namespace blender {
-
-template<typename T> class HeapValue {
- private:
- T *value_ = nullptr;
-
- public:
- HeapValue(T value)
- {
- value_ = new T(std::move(value));
- }
-
- HeapValue(const HeapValue &other)
- {
- if (other.value_ != nullptr) {
- value_ = new T(*other.value_);
- }
- }
-
- HeapValue(HeapValue &&other)
- {
- value_ = other.value_;
- other.value_ = nullptr;
- }
-
- ~HeapValue()
- {
- delete value_;
- }
-
- HeapValue &operator=(const HeapValue &other)
- {
- if (this == &other) {
- return *this;
- }
- if (value_ != nullptr) {
- if (other.value_ != nullptr) {
- *value_ = *other.value_;
- }
- else {
- delete value_;
- value_ = nullptr;
- }
- }
- else {
- if (other.value_ != nullptr) {
- value_ = new T(*other.value_);
- }
- else {
- /* Do nothing. */
- }
- }
- return *this;
- }
-
- HeapValue &operator=(HeapValue &&other)
- {
- if (this == &other) {
- return *this;
- }
- delete value_;
- value_ = other.value_;
- other.value_ = nullptr;
- return *this;
- }
-
- HeapValue &operator=(T value)
- {
- if (value_ == nullptr) {
- value_ = new T(std::move(value));
- }
- else {
- *value_ = std::move(value);
- }
- }
-
- operator bool() const
- {
- return value_ != nullptr;
- }
-
- T &operator*()
- {
- BLI_assert(value_ != nullptr);
- return *value_;
- }
-
- const T &operator*() const
- {
- BLI_assert(value_ != nullptr);
- return *value_;
- }
-
- T *operator->()
- {
- BLI_assert(value_ != nullptr);
- return value_;
- }
-
- const T *operator->() const
- {
- BLI_assert(value_ != nullptr);
- return value_;
- }
-
- T *get()
- {
- return value_;
- }
-
- const T *get() const
- {
- return value_;
- }
-
- friend bool operator==(const HeapValue &a, const HeapValue &b)
- {
- if (a.value_ == nullptr && b.value_ == nullptr) {
- return true;
- }
- if (a.value_ == nullptr) {
- return false;
- }
- if (b.value_ == nullptr) {
- return false;
- }
- return *a.value_ == *b.value_;
- }
-
- friend bool operator==(const HeapValue &a, const T &b)
- {
- if (a.value_ == nullptr) {
- return false;
- }
- return *a.value_ == b;
- }
-
- friend bool operator==(const T &a, const HeapValue &b)
- {
- return b == a;
- }
-
- friend bool operator!=(const HeapValue &a, const HeapValue &b)
- {
- return !(a == b);
- }
-
- friend bool operator!=(const HeapValue &a, const T &b)
- {
- return !(a == b);
- }
-
- friend bool operator!=(const T &a, const HeapValue &b)
- {
- return !(a == b);
- }
-};
-
-template<typename T> struct DefaultHash<HeapValue<T>> {
- uint64_t operator()(const HeapValue<T> &value) const
- {
- if (value) {
- return DefaultHash<T>{}(*value);
- }
- return 0;
- }
-
- uint64_t operator()(const T &value) const
- {
- return DefaultHash<T>{}(value);
- }
-};
-} // namespace blender
-
namespace blender::nodes {
-template<typename T1, typename T2, typename T3>
-uint64_t default_hash_3(const T1 &v1, const T2 &v2, const T3 &v3)
-{
- const uint64_t h1 = DefaultHash<T1>{}(v1);
- const uint64_t h2 = DefaultHash<T2>{}(v2);
- const uint64_t h3 = DefaultHash<T3>{}(v3);
- return (h1 * 73856093) ^ (h2 * 19349663) ^ (h3 * 83492791);
-}
-
-namespace {
-
struct SocketMenuInfo {
bNodeTree *ntree;
bNode *node;
@@ -275,8 +91,6 @@ struct SocketMenuInfo {
}
};
-} // namespace
-
static Set<HeapValue<SocketMenuInfo>> &get_socket_menu_info_set()
{
static Set<HeapValue<SocketMenuInfo>> set;
More information about the Bf-blender-cvs
mailing list