summaryrefslogtreecommitdiff
path: root/include/libcamera/base
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2021-06-25 00:09:15 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2021-06-25 16:11:03 +0100
commit6410d1d37c1ea9d1d168840a7ba063facb0bc9d6 (patch)
treed23c636895d51df3b4b6fe128f322132203a3a26 /include/libcamera/base
parentcbdc93e9d1666010d49e06940158a37c61cc6fa7 (diff)
libcamera/base: Move class helpers to the base library
Move the class support infrastructure to the base library. Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'include/libcamera/base')
-rw-r--r--include/libcamera/base/class.h105
-rw-r--r--include/libcamera/base/meson.build1
2 files changed, 106 insertions, 0 deletions
diff --git a/include/libcamera/base/class.h b/include/libcamera/base/class.h
new file mode 100644
index 00000000..a07dac05
--- /dev/null
+++ b/include/libcamera/base/class.h
@@ -0,0 +1,105 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2020, Google Inc.
+ *
+ * class.h - Utilities and helpers for classes
+ */
+#ifndef __LIBCAMERA_BASE_CLASS_H__
+#define __LIBCAMERA_BASE_CLASS_H__
+
+#include <memory>
+
+namespace libcamera {
+
+#ifndef __DOXYGEN__
+#define LIBCAMERA_DISABLE_COPY(klass) \
+ klass(const klass &) = delete; \
+ klass &operator=(const klass &) = delete;
+
+#define LIBCAMERA_DISABLE_MOVE(klass) \
+ klass(klass &&) = delete; \
+ klass &operator=(klass &&) = delete;
+
+#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass) \
+ LIBCAMERA_DISABLE_COPY(klass) \
+ LIBCAMERA_DISABLE_MOVE(klass)
+#else
+#define LIBCAMERA_DISABLE_COPY(klass)
+#define LIBCAMERA_DISABLE_MOVE(klass)
+#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
+#endif
+
+#ifndef __DOXYGEN__
+#define LIBCAMERA_DECLARE_PRIVATE() \
+public: \
+ class Private; \
+ friend class Private;
+
+#define LIBCAMERA_DECLARE_PUBLIC(klass) \
+ friend class klass; \
+ using Public = klass;
+
+#define LIBCAMERA_D_PTR() \
+ _d<Private>();
+
+#define LIBCAMERA_O_PTR() \
+ _o<Public>();
+
+#else
+#define LIBCAMERA_DECLARE_PRIVATE()
+#define LIBCAMERA_DECLARE_PUBLIC(klass)
+#define LIBCAMERA_D_PTR()
+#define LIBCAMERA_O_PTR()
+#endif
+
+class Extensible
+{
+public:
+ class Private
+ {
+ public:
+ Private(Extensible *o);
+ virtual ~Private();
+
+#ifndef __DOXYGEN__
+ template<typename T>
+ const T *_o() const
+ {
+ return static_cast<const T *>(o_);
+ }
+
+ template<typename T>
+ T *_o()
+ {
+ return static_cast<T *>(o_);
+ }
+#endif
+
+ private:
+ Extensible *const o_;
+ };
+
+ Extensible(Private *d);
+
+protected:
+#ifndef __DOXYGEN__
+ template<typename T>
+ const T *_d() const
+ {
+ return static_cast<const T *>(d_.get());
+ }
+
+ template<typename T>
+ T *_d()
+ {
+ return static_cast<T *>(d_.get());
+ }
+#endif
+
+private:
+ const std::unique_ptr<Private> d_;
+};
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_BASE_CLASS_H__ */
diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build
index 9f0ba6b0..2db756c5 100644
--- a/include/libcamera/base/meson.build
+++ b/include/libcamera/base/meson.build
@@ -3,6 +3,7 @@
libcamera_base_include_dir = libcamera_include_dir / 'base'
libcamera_base_headers = files([
+ 'class.h',
'utils.h',
])