[Bf-blender-cvs] [c541e319316] functions: cleanup some nonmovable and noncopyable functions

Jacques Lucke noreply at git.blender.org
Mon Sep 9 12:17:34 CEST 2019


Commit: c541e319316b39158388fa2837fc1c7cbe5c4876
Author: Jacques Lucke
Date:   Mon Sep 9 12:17:28 2019 +0200
Branches: functions
https://developer.blender.org/rBc541e319316b39158388fa2837fc1c7cbe5c4876

cleanup some nonmovable and noncopyable functions

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

M	source/blender/blenlib/BLI_monotonic_allocator.hpp
A	source/blender/blenlib/BLI_utility_mixins.hpp
M	source/blender/blenlib/CMakeLists.txt
M	source/blender/functions/backends/cpp/list.hpp
M	source/blender/functions/core/function.hpp
M	source/blender/functions/core/type.hpp
M	source/blender/simulations/bparticles/action_contexts.hpp
M	source/blender/simulations/bparticles/particle_function.hpp

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

diff --git a/source/blender/blenlib/BLI_monotonic_allocator.hpp b/source/blender/blenlib/BLI_monotonic_allocator.hpp
index 1ed920ca029..1d8350a8262 100644
--- a/source/blender/blenlib/BLI_monotonic_allocator.hpp
+++ b/source/blender/blenlib/BLI_monotonic_allocator.hpp
@@ -25,10 +25,11 @@
 #pragma once
 
 #include "BLI_vector.hpp"
+#include "BLI_utility_mixins.hpp"
 
 namespace BLI {
 
-class MonotonicAllocator {
+class MonotonicAllocator : NonCopyable, NonMovable {
  private:
   Vector<void *> m_pointers;
 
@@ -42,9 +43,6 @@ class MonotonicAllocator {
   {
   }
 
-  MonotonicAllocator(MonotonicAllocator &other) = delete;
-  MonotonicAllocator(MonotonicAllocator &&other) = delete;
-
   ~MonotonicAllocator()
   {
     for (void *ptr : m_pointers) {
diff --git a/source/blender/blenlib/BLI_utility_mixins.hpp b/source/blender/blenlib/BLI_utility_mixins.hpp
new file mode 100644
index 00000000000..66164fdcd24
--- /dev/null
+++ b/source/blender/blenlib/BLI_utility_mixins.hpp
@@ -0,0 +1,29 @@
+#pragma once
+
+namespace BLI {
+
+class NonCopyable {
+ public:
+  /* Disable copy construction and assignment. */
+  NonCopyable(const NonCopyable &other) = delete;
+  NonCopyable &operator=(const NonCopyable &other) = delete;
+
+  /* Explicitly enable default construction, move construction and move assignment. */
+  NonCopyable() = default;
+  NonCopyable(NonCopyable &&other) = default;
+  NonCopyable &operator=(NonCopyable &&other) = default;
+};
+
+class NonMovable {
+ public:
+  /* Disable move construction and assignment. */
+  NonMovable(NonMovable &&other) = delete;
+  NonMovable &operator=(NonMovable &&other) = delete;
+
+  /* Explicitly enable default construction, copy construction and copy assignment. */
+  NonMovable() = default;
+  NonMovable(const NonMovable &other) = default;
+  NonMovable &operator=(const NonMovable &other) = default;
+};
+
+}  // namespace BLI
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 6f501854be0..9de9b343a65 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -268,6 +268,7 @@ set(SRC
   BLI_multi_vector.hpp
   BLI_open_addressing.hpp
   BLI_hash.hpp
+  BLI_utility_mixins.hpp
 )
 
 set(LIB
diff --git a/source/blender/functions/backends/cpp/list.hpp b/source/blender/functions/backends/cpp/list.hpp
index 57c9e803f1f..5d7909d4301 100644
--- a/source/blender/functions/backends/cpp/list.hpp
+++ b/source/blender/functions/backends/cpp/list.hpp
@@ -2,13 +2,14 @@
 
 #include "tuple.hpp"
 #include "BLI_refcount.hpp"
+#include "BLI_utility_mixins.hpp"
 
 namespace FN {
 
 class List;
 using SharedList = AutoRefCount<List>;
 
-class List : public RefCounter {
+class List : public RefCounter, BLI::NonMovable, BLI::NonCopyable {
  private:
   Type *m_type;
   CPPTypeInfo *m_type_info;
@@ -18,6 +19,7 @@ class List : public RefCounter {
 
  public:
   List() = delete;
+
   List(Type *type) : m_type(std::move(type))
   {
     m_type_info = &m_type->extension<CPPTypeInfo>();
@@ -26,11 +28,6 @@ class List : public RefCounter {
     m_capacity = 0;
   }
 
-  List(List &other) = delete;
-  List(List &&other) = delete;
-  List &operator=(List &other) = delete;
-  List &operator=(List &&other) = delete;
-
   ~List()
   {
     if (m_storage != nullptr) {
diff --git a/source/blender/functions/core/function.hpp b/source/blender/functions/core/function.hpp
index 88d71f45142..3d85c2151c5 100644
--- a/source/blender/functions/core/function.hpp
+++ b/source/blender/functions/core/function.hpp
@@ -21,12 +21,13 @@
 
 #include "type.hpp"
 #include "BLI_chained_strings.hpp"
+#include "BLI_utility_mixins.hpp"
 
 namespace FN {
 
 class Function;
 
-class FunctionBody {
+class FunctionBody : BLI::NonCopyable, BLI::NonMovable {
  private:
   Function *m_owner = nullptr;
 
@@ -39,8 +40,6 @@ class FunctionBody {
 
  public:
   FunctionBody() = default;
-  FunctionBody(FunctionBody &other) = delete;
-  FunctionBody(FunctionBody &&other) = delete;
 
   virtual ~FunctionBody();
 
diff --git a/source/blender/functions/core/type.hpp b/source/blender/functions/core/type.hpp
index d3e5d2859a9..a3fab70d2d4 100644
--- a/source/blender/functions/core/type.hpp
+++ b/source/blender/functions/core/type.hpp
@@ -24,6 +24,7 @@
 #include "BLI_refcount.hpp"
 #include "BLI_string_ref.hpp"
 #include "MEM_guardedalloc.h"
+#include "BLI_utility_mixins.hpp"
 
 namespace FN {
 
@@ -31,7 +32,7 @@ using namespace BLI;
 
 class Type;
 
-class TypeExtension {
+class TypeExtension : BLI::NonCopyable, BLI::NonMovable {
  private:
   Type *m_owner = nullptr;
   friend Type;
@@ -40,8 +41,6 @@ class TypeExtension {
 
  public:
   TypeExtension() = default;
-  TypeExtension(TypeExtension &other) = delete;
-  TypeExtension(TypeExtension &&other) = delete;
 
   virtual ~TypeExtension();
 
diff --git a/source/blender/simulations/bparticles/action_contexts.hpp b/source/blender/simulations/bparticles/action_contexts.hpp
index d34df4a4f2f..371c27faff7 100644
--- a/source/blender/simulations/bparticles/action_contexts.hpp
+++ b/source/blender/simulations/bparticles/action_contexts.hpp
@@ -1,6 +1,7 @@
 #pragma once
 
 #include "BLI_temporary_allocator.hpp"
+#include "BLI_utility_mixins.hpp"
 
 #include "action_interface.hpp"
 
@@ -11,7 +12,7 @@ namespace BParticles {
 using BLI::float3;
 using BLI::float4x4;
 
-class MeshSurfaceContext : public ActionContext {
+class MeshSurfaceContext : public ActionContext, BLI::NonCopyable, BLI::NonMovable {
  private:
   Vector<void *> m_buffers_to_free;
   Object *m_object;
@@ -81,9 +82,6 @@ class MeshSurfaceContext : public ActionContext {
     }
   }
 
-  MeshSurfaceContext(const MeshSurfaceContext &other) = delete;
-  MeshSurfaceContext &operator=(const MeshSurfaceContext &other) = delete;
-
   Object *object() const
   {
     return m_object;
diff --git a/source/blender/simulations/bparticles/particle_function.hpp b/source/blender/simulations/bparticles/particle_function.hpp
index 4d255c0f8d4..0fb457b5d61 100644
--- a/source/blender/simulations/bparticles/particle_function.hpp
+++ b/source/blender/simulations/bparticles/particle_function.hpp
@@ -23,7 +23,7 @@ using FN::Type;
 
 class ParticleFunction;
 
-class ParticleFunctionResult {
+class ParticleFunctionResult : BLI::NonCopyable, BLI::NonMovable {
  private:
   Vector<void *> m_buffers;
   Vector<uint> m_strides;
@@ -37,8 +37,6 @@ class ParticleFunctionResult {
 
  public:
   ParticleFunctionResult() = default;
-  ParticleFunctionResult(ParticleFunctionResult &other) = delete;
-  ParticleFunctionResult(ParticleFunctionResult &&other) = delete;
 
   ~ParticleFunctionResult()
   {



More information about the Bf-blender-cvs mailing list