[Bf-blender-cvs] [c3b0b85d47d] functions: move Composition to BLI

Jacques Lucke noreply at git.blender.org
Sun Feb 10 20:26:36 CET 2019


Commit: c3b0b85d47d26ae45865ca70f043a146aaab3832
Author: Jacques Lucke
Date:   Thu Feb 7 18:31:15 2019 +0100
Branches: functions
https://developer.blender.org/rBc3b0b85d47d26ae45865ca70f043a146aaab3832

move Composition to BLI

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

A	source/blender/blenlib/BLI_composition.hpp
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/functions/core/core.hpp

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

diff --git a/source/blender/blenlib/BLI_composition.hpp b/source/blender/blenlib/BLI_composition.hpp
new file mode 100644
index 00000000000..571d2921e0b
--- /dev/null
+++ b/source/blender/blenlib/BLI_composition.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include "BLI_small_map.hpp"
+
+namespace BLI {
+
+	class Composition {
+	public:
+		typedef void (*FreeFunction)(void *value);
+
+	private:
+		struct Entry {
+			void *value;
+			FreeFunction free;
+
+			template<typename T>
+			Entry(T *value)
+				: value((void *)value), free(get_free_function<T>()) {}
+		};
+
+	public:
+		template<typename T>
+		void add(T *value)
+		{
+			this->m_elements.add(this->get_key<T>(), Entry(value));
+		}
+
+		template<typename T>
+		inline T *get() const
+		{
+			uint64_t key = this->get_key<T>();
+			if (this->m_elements.contains(key)) {
+				return (T *)this->m_elements.lookup(key).value;
+			}
+			else {
+				return nullptr;
+			}
+		}
+
+		~Composition()
+		{
+			for (const Entry &entry : this->m_elements.values()) {
+				entry.free(entry.value);
+			}
+		}
+
+	private:
+		template<typename T>
+		static uint64_t get_key()
+		{
+			return (uint64_t)T::identifier();
+		}
+
+		template<typename T>
+		static FreeFunction get_free_function()
+		{
+			return T::free;
+		}
+
+		BLI::SmallMap<uint64_t, Entry> m_elements;
+	};
+
+} /* namespace BLI */
\ No newline at end of file
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index d41e0766728..08b8ad43929 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -225,6 +225,7 @@ set(SRC
 	PIL_time.h
 	PIL_time_utildefines.h
 
+	BLI_composition.hpp
 	BLI_small_vector.hpp
 	BLI_small_map.hpp
 	BLI_small_set.hpp
diff --git a/source/blender/functions/core/core.hpp b/source/blender/functions/core/core.hpp
index c86bea681ec..6ab83c8fe4f 100644
--- a/source/blender/functions/core/core.hpp
+++ b/source/blender/functions/core/core.hpp
@@ -3,6 +3,7 @@
 #include <string>
 #include <iostream>
 
+#include "BLI_composition.hpp"
 #include "BLI_small_vector.hpp"
 #include "BLI_small_map.hpp"
 #include "BLI_shared.hpp"
@@ -19,67 +20,6 @@ namespace FN {
 	using SharedFunction = Shared<Function>;
 	using SmallTypeVector = SmallVector<SharedType>;
 
-	class Composition {
-	public:
-		typedef void (*FreeFunction)(void *value);
-
-	private:
-		struct Entry {
-			void *value;
-			FreeFunction free;
-		};
-
-	public:
-		template<typename T>
-		void add(T *value)
-		{
-			this->m_elements.add(this->get_key<T>(), this->create_entry(value));
-		}
-
-		template<typename T>
-		inline T *get() const
-		{
-			uint64_t key = this->get_key<T>();
-			if (this->m_elements.contains(key)) {
-				return (T *)this->m_elements.lookup(key).value;
-			}
-			else {
-				return nullptr;
-			}
-		}
-
-		~Composition()
-		{
-			for (const Entry &entry : this->m_elements.values()) {
-				entry.free(entry.value);
-			}
-		}
-
-	private:
-		template<typename T>
-		static uint64_t get_key()
-		{
-			return (uint64_t)T::identifier();
-		}
-
-		template<typename T>
-		static FreeFunction get_free_function()
-		{
-			return T::free;
-		}
-
-		template<typename T>
-		Entry create_entry(T *value)
-		{
-			Entry entry;
-			entry.value = (void *)value;
-			entry.free = this->get_free_function<T>();
-			return entry;
-		}
-
-		BLI::SmallMap<uint64_t, Entry> m_elements;
-	};
-
 	class Type final {
 	public:
 		Type() = delete;



More information about the Bf-blender-cvs mailing list