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:
authorJacques Lucke <mail@jlucke.com>2020-02-10 17:29:17 +0300
committerJacques Lucke <mail@jlucke.com>2020-02-10 17:33:39 +0300
commitf8df6286c2c05d8480f84d5e5640c4bcb46aa4ad (patch)
tree9f831ebbf6b1c0d8dfca00559bd745c88144cafa
parentec116e3d492511298c9bf595c19e6c49e07c97f6 (diff)
BLI: add utilities for defining non-movable and non-copyable classes
Structs and classes can subclass these member-free classes privately. Then they become non-movable, non-copyable or both.
-rw-r--r--source/blender/blenlib/BLI_utility_mixins.h29
-rw-r--r--source/blender/blenlib/CMakeLists.txt1
2 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_utility_mixins.h b/source/blender/blenlib/BLI_utility_mixins.h
new file mode 100644
index 00000000000..66164fdcd24
--- /dev/null
+++ b/source/blender/blenlib/BLI_utility_mixins.h
@@ -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 2780e2becf8..1e4e07d63b3 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -243,6 +243,7 @@ set(SRC
BLI_utildefines_iter.h
BLI_utildefines_stack.h
BLI_utildefines_variadic.h
+ BLI_utility_mixins.h
BLI_uvproject.h
BLI_vector.h
BLI_vector_set.h