[libcamera-devel] [PATCH 1/5] libcamera: Provide class.h

Kieran Bingham kieran.bingham at ideasonboard.com
Thu Oct 22 15:56:01 CEST 2020


Provide a public header to define helpers for class definitions.
This initially implements macros to clearly define the deletion of
copy/move/assignment constructors/operators for classes to restrict
their capabilities explicitly.

Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
 include/libcamera/class.h     | 35 +++++++++++++++++++++++++++++++++++
 include/libcamera/meson.build |  1 +
 2 files changed, 36 insertions(+)
 create mode 100644 include/libcamera/class.h

diff --git a/include/libcamera/class.h b/include/libcamera/class.h
new file mode 100644
index 000000000000..adcfa8860957
--- /dev/null
+++ b/include/libcamera/class.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2020, Google Inc.
+ *
+ * class.h - class helpers
+ */
+#ifndef __LIBCAMERA_CLASS_H__
+#define __LIBCAMERA_CLASS_H__
+
+/**
+ * \brief Delete the copy constructor and assignment operator.
+ */
+#define DELETE_COPY_AND_ASSIGN(klass)   \
+	/* copy constructor. */         \
+	klass(const klass &) = delete;  \
+	/* copy assignment operator. */ \
+	klass &operator=(const klass &) = delete
+
+/**
+ * \brief Delete the move construtor and assignment operator.
+ */
+#define DELETE_MOVE_AND_ASSIGN(klass)   \
+	/* move constructor. */         \
+	klass(klass &&) = delete;       \
+	/* move assignment operator. */ \
+	klass &operator=(klass &&) = delete
+
+/**
+ * \brief Delete all copy and move constructors, and assignment operators.
+ */
+#define DELETE_COPY_MOVE_AND_ASSIGN(klass) \
+	DELETE_COPY_AND_ASSIGN(klass);     \
+	DELETE_MOVE_AND_ASSIGN(klass)
+
+#endif /* __LIBCAMERA_CLASS_H__ */
diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build
index 3d5fc70134ad..b3363a6f735b 100644
--- a/include/libcamera/meson.build
+++ b/include/libcamera/meson.build
@@ -5,6 +5,7 @@ libcamera_public_headers = files([
     'buffer.h',
     'camera.h',
     'camera_manager.h',
+    'class.h',
     'controls.h',
     'event_dispatcher.h',
     'event_notifier.h',
-- 
2.25.1



More information about the libcamera-devel mailing list