Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenlib/BLI_index_map.h48
-rw-r--r--source/blender/blenlib/BLI_index_to_ref_map.h47
-rw-r--r--source/blender/blenlib/CMakeLists.txt2
-rw-r--r--source/blender/functions/FN_node_tree_multi_function_network.h20
-rw-r--r--source/blender/functions/intern/node_tree_multi_function_network/builder.cc8
5 files changed, 62 insertions, 63 deletions
diff --git a/source/blender/blenlib/BLI_index_map.h b/source/blender/blenlib/BLI_index_map.h
deleted file mode 100644
index c8668880c42..00000000000
--- a/source/blender/blenlib/BLI_index_map.h
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef __BLI_INDEX_MAP_H__
-#define __BLI_INDEX_MAP_H__
-
-#include "BLI_array_cxx.h"
-
-namespace BLI {
-
-template<typename ValueT, uint N = 4, typename Allocator = GuardedAllocator> class IndexMap {
- private:
- Array<ValueT, N, Allocator> m_array;
- ValueT m_sentinel;
-
- public:
- IndexMap(uint size, ValueT sentinel) : m_array(size, sentinel), m_sentinel(sentinel)
- {
- }
-
- uint size() const
- {
- return m_array.size();
- }
-
- void add(uint key, const ValueT &value)
- {
- m_array[key] = value;
- }
-
- void add_new(uint key, const ValueT &value)
- {
- BLI_assert(m_array[key] == m_sentinel);
- m_array[key] = value;
- }
-
- bool contains(uint key) const
- {
- return m_array[key] != m_sentinel;
- }
-
- const ValueT &lookup(uint key) const
- {
- BLI_assert(this->contains(key));
- return m_array[key];
- }
-};
-
-} // namespace BLI
-
-#endif /* __BLI_INDEX_MAP_H__ */
diff --git a/source/blender/blenlib/BLI_index_to_ref_map.h b/source/blender/blenlib/BLI_index_to_ref_map.h
new file mode 100644
index 00000000000..88dfceefac8
--- /dev/null
+++ b/source/blender/blenlib/BLI_index_to_ref_map.h
@@ -0,0 +1,47 @@
+#ifndef __BLI_INDEX_TO_REF_MAP_H__
+#define __BLI_INDEX_TO_REF_MAP_H__
+
+#include "BLI_array_cxx.h"
+
+namespace BLI {
+
+template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class IndexToRefMap {
+ private:
+ Array<T *, N, Allocator> m_array;
+
+ public:
+ IndexToRefMap(uint size) : m_array(size, nullptr)
+ {
+ }
+
+ uint size() const
+ {
+ return m_array.size();
+ }
+
+ void add(uint key, T &value)
+ {
+ m_array[key] = &value;
+ }
+
+ void add_new(uint key, T &value)
+ {
+ BLI_assert(m_array[key] == nullptr);
+ m_array[key] = &value;
+ }
+
+ bool contains(uint key) const
+ {
+ return m_array[key] != nullptr;
+ }
+
+ const T &lookup(uint key) const
+ {
+ BLI_assert(this->contains(key));
+ return *m_array[key];
+ }
+};
+
+} // namespace BLI
+
+#endif /* __BLI_INDEX_TO_REF_MAP_H__ */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 589ecaaecfd..40f6fa6f769 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -276,7 +276,7 @@ set(SRC
BLI_index_mask.h
BLI_parallel.h
BLI_string_multi_map.h
- BLI_index_map.h
+ BLI_index_to_ref_map.h
)
set(LIB
diff --git a/source/blender/functions/FN_node_tree_multi_function_network.h b/source/blender/functions/FN_node_tree_multi_function_network.h
index 206d285384f..fb2519ff866 100644
--- a/source/blender/functions/FN_node_tree_multi_function_network.h
+++ b/source/blender/functions/FN_node_tree_multi_function_network.h
@@ -4,13 +4,13 @@
#include "FN_node_tree.h"
#include "BLI_multi_map.h"
-#include "BLI_index_map.h"
+#include "BLI_index_to_ref_map.h"
#include "FN_multi_function_network.h"
namespace FN {
-using BLI::IndexMap;
+using BLI::IndexToRefMap;
using BLI::MultiMap;
#define IdMultiMap_UNMAPPED UINT_MAX
@@ -80,14 +80,14 @@ class InlinedTreeMFSocketMap {
const FunctionNodeTree *m_function_tree;
const MFNetwork *m_network;
- IndexMap<const MFSocket *> m_dummy_socket_by_fsocket_id;
- IndexMap<const FSocket *> m_fsocket_by_dummy_socket_id;
+ IndexToRefMap<const MFSocket> m_dummy_socket_by_fsocket_id;
+ IndexToRefMap<const FSocket> m_fsocket_by_dummy_socket_id;
public:
InlinedTreeMFSocketMap(const FunctionNodeTree &function_tree,
const MFNetwork &network,
- IndexMap<const MFSocket *> dummy_socket_by_fsocket_id,
- IndexMap<const FSocket *> fsocket_by_dummy_socket_id)
+ IndexToRefMap<const MFSocket> dummy_socket_by_fsocket_id,
+ IndexToRefMap<const FSocket> fsocket_by_dummy_socket_id)
: m_function_tree(&function_tree),
m_network(&network),
m_dummy_socket_by_fsocket_id(std::move(dummy_socket_by_fsocket_id)),
@@ -107,24 +107,24 @@ class InlinedTreeMFSocketMap {
const MFInputSocket &lookup_singly_mapped_input_socket(const FInputSocket &fsocket) const
{
- return m_dummy_socket_by_fsocket_id.lookup(fsocket.id())->as_input();
+ return m_dummy_socket_by_fsocket_id.lookup(fsocket.id()).as_input();
}
const MFOutputSocket &lookup_socket(const FOutputSocket &fsocket) const
{
- return m_dummy_socket_by_fsocket_id.lookup(fsocket.id())->as_output();
+ return m_dummy_socket_by_fsocket_id.lookup(fsocket.id()).as_output();
}
const FInputSocket &lookup_fsocket(const MFInputSocket &socket) const
{
BLI_assert(socket.node().is_dummy());
- return m_fsocket_by_dummy_socket_id.lookup(socket.id())->as_input();
+ return m_fsocket_by_dummy_socket_id.lookup(socket.id()).as_input();
}
const FOutputSocket &lookup_fsocket(const MFOutputSocket &socket) const
{
BLI_assert(socket.node().is_dummy());
- return m_fsocket_by_dummy_socket_id.lookup(socket.id())->as_output();
+ return m_fsocket_by_dummy_socket_id.lookup(socket.id()).as_output();
}
};
diff --git a/source/blender/functions/intern/node_tree_multi_function_network/builder.cc b/source/blender/functions/intern/node_tree_multi_function_network/builder.cc
index ad982c8e6cf..b5c97de7b3f 100644
--- a/source/blender/functions/intern/node_tree_multi_function_network/builder.cc
+++ b/source/blender/functions/intern/node_tree_multi_function_network/builder.cc
@@ -203,8 +203,8 @@ std::unique_ptr<FunctionTreeMFNetwork> FunctionTreeMFNetworkBuilder::build()
{
// m_builder->to_dot__clipboard();
- IndexMap<const MFSocket *> dummy_socket_by_fsocket_id(m_function_tree.socket_count(), nullptr);
- IndexMap<const FSocket *> fsocket_by_dummy_socket_id(m_builder->sockets_by_id().size(), nullptr);
+ IndexToRefMap<const MFSocket> dummy_socket_by_fsocket_id(m_function_tree.socket_count());
+ IndexToRefMap<const FSocket> fsocket_by_dummy_socket_id(m_builder->sockets_by_id().size());
auto network = BLI::make_unique<MFNetwork>(std::move(m_builder));
@@ -213,8 +213,8 @@ std::unique_ptr<FunctionTreeMFNetwork> FunctionTreeMFNetworkBuilder::build()
for (uint mapped_id : mapped_ids) {
const MFSocket &socket = network->socket_by_id(mapped_id);
if (socket.node().is_dummy()) {
- dummy_socket_by_fsocket_id.add_new(fsocket->id(), &socket);
- fsocket_by_dummy_socket_id.add_new(socket.id(), fsocket);
+ dummy_socket_by_fsocket_id.add_new(fsocket->id(), socket);
+ fsocket_by_dummy_socket_id.add_new(socket.id(), *fsocket);
}
}
}