[Bf-blender-cvs] [75ecfd03ab1] functions: more generic CPP and LLVM type info for lists

Jacques Lucke noreply at git.blender.org
Fri Mar 8 15:15:28 CET 2019


Commit: 75ecfd03ab164e6047cda6cc7a3bd93a683d4320
Author: Jacques Lucke
Date:   Fri Mar 8 14:31:50 2019 +0100
Branches: functions
https://developer.blender.org/rB75ecfd03ab164e6047cda6cc7a3bd93a683d4320

more generic CPP and LLVM type info for lists

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

M	source/blender/functions/types/numeric_lists.cpp

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

diff --git a/source/blender/functions/types/numeric_lists.cpp b/source/blender/functions/types/numeric_lists.cpp
index eab4dd72d55..336afd4a1c9 100644
--- a/source/blender/functions/types/numeric_lists.cpp
+++ b/source/blender/functions/types/numeric_lists.cpp
@@ -7,20 +7,30 @@
 
 namespace FN { namespace Types {
 
-	class FloatListType : public CPPTypeInfo {
+	template<typename T>
+	class ListCPPTypeInfo : public CPPTypeInfo {
+	private:
+		static List<T> *list_from_ptr(void *ptr)
+		{
+			return ((SharedList<T> *)ptr)->ptr();
+		}
+
+	public:
 		uint size_of_type() const override
 		{
-			return sizeof(FloatList *);
+			return sizeof(SharedList<T>);
 		}
 
 		void construct_default(void *ptr) const override
 		{
-			*(FloatList **)ptr = new FloatList();
+			List<T> *list = new List<T>();
+			*(SharedList<T> *)ptr = SharedList<T>::FromPointer(list);
 		}
 
 		void destruct_type(void *ptr) const override
 		{
-			(*(FloatList **)ptr)->remove_user();
+			List<T> *list = this->list_from_ptr(ptr);
+			list->remove_user();
 		}
 
 		void copy_to_initialized(void *src, void *dst) const override
@@ -31,37 +41,48 @@ namespace FN { namespace Types {
 
 		void copy_to_uninitialized(void *src, void *dst) const override
 		{
-			FloatList *list = (FloatList *)src;
+			List<T> *list = this->list_from_ptr(src);
 			list->new_user();
-			(*(FloatList **)dst) = list;
+			*(SharedList<T> *)dst = SharedList<T>::FromPointer(list);
 		}
 	};
 
-	static void *copy_func(void *value)
-	{
-		FloatList *list = (FloatList *)value;
-		list->new_user();
-		return list;
-	}
+	template<typename T>
+	class ListLLVMTypeInfo : public LLVMTypeInfo {
+	private:
+		static void *copy_func(void *value)
+		{
+			List<T> *list = (List<T> *)value;
+			list->new_user();
+			return list;
+		}
 
-	static void free_func(void *value)
-	{
-		FloatList *list = (FloatList *)value;
-		list->remove_user();
-	}
+		static void free_func(void *value)
+		{
+			List<T> *list = (List<T> *)value;
+			list->remove_user();
+		}
 
-	static void *default_func()
-	{
-		return new FloatList();
-	}
+		static void *default_func()
+		{
+			return new List<T>();
+		}
 
+	public:
+		static LLVMTypeInfo *Create()
+		{
+			static_assert(sizeof(SharedList<T>) == sizeof(List<T> *),
+				"Currently it is assumed that only a pointer to the list is stored");
+			return new PointerLLVMTypeInfo(
+				copy_func, free_func, default_func);
+		}
+	};
 
 	LAZY_INIT_REF__NO_ARG(SharedType, get_float_list_type)
 	{
 		SharedType type = SharedType::New("Float List");
-		type->extend(new FloatListType());
-		type->extend(new PointerLLVMTypeInfo(
-			copy_func, free_func, default_func));
+		type->extend(new ListCPPTypeInfo<float>());
+		type->extend(ListLLVMTypeInfo<float>::Create());
 		return type;
 	}



More information about the Bf-blender-cvs mailing list