libcamera  v0.2.0+85-1c5830a9
Supporting cameras in Linux since 2019
class.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2020, Google Inc.
4  *
5  * class.h - Utilities and helpers for classes
6  */
7 
8 #pragma once
9 
10 #include <memory>
11 
12 namespace libcamera {
13 
14 #ifndef __DOXYGEN__
15 #define LIBCAMERA_DISABLE_COPY(klass) \
16  klass(const klass &) = delete; \
17  klass &operator=(const klass &) = delete;
18 
19 #define LIBCAMERA_DISABLE_MOVE(klass) \
20  klass(klass &&) = delete; \
21  klass &operator=(klass &&) = delete;
22 
23 #define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass) \
24  LIBCAMERA_DISABLE_COPY(klass) \
25  LIBCAMERA_DISABLE_MOVE(klass)
26 #else
27 #define LIBCAMERA_DISABLE_COPY(klass)
28 #define LIBCAMERA_DISABLE_MOVE(klass)
29 #define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
30 #endif
31 
32 #ifndef __DOXYGEN__
33 #define LIBCAMERA_DECLARE_PRIVATE() \
34 public: \
35  class Private; \
36  friend class Private; \
37  template <bool B = true> \
38  const Private *_d() const \
39  { \
40  return Extensible::_d<Private>(); \
41  } \
42  template <bool B = true> \
43  Private *_d() \
44  { \
45  return Extensible::_d<Private>(); \
46  }
47 
48 #define LIBCAMERA_DECLARE_PUBLIC(klass) \
49  friend class klass; \
50  using Public = klass;
51 
52 #define LIBCAMERA_O_PTR() \
53  _o<Public>()
54 
55 #else
56 #define LIBCAMERA_DECLARE_PRIVATE()
57 #define LIBCAMERA_DECLARE_PUBLIC(klass)
58 #define LIBCAMERA_O_PTR()
59 #endif
60 
62 {
63 public:
64  class Private
65  {
66  public:
67  Private();
68  virtual ~Private();
69 
70 #ifndef __DOXYGEN__
71  template<typename T>
72  const T *_o() const
73  {
74  return static_cast<const T *>(o_);
75  }
76 
77  template<typename T>
78  T *_o()
79  {
80  return static_cast<T *>(o_);
81  }
82 #endif
83 
84  private:
85  /* To initialize o_ from Extensible. */
86  friend class Extensible;
87  Extensible *const o_;
88  };
89 
90  Extensible(std::unique_ptr<Private> d);
91 
92 protected:
93  template<typename T>
94  const T *_d() const
95  {
96  return static_cast<const T *>(d_.get());
97  }
98 
99  template<typename T>
100  T *_d()
101  {
102  return static_cast<T *>(d_.get());
103  }
104 
105 private:
106  const std::unique_ptr<Private> d_;
107 };
108 
109 } /* namespace libcamera */
Base class for private data managed through a d-pointer.
Definition: class.h:64
const T * _d() const
Retrieve the private data instance.
Definition: class.h:94
Top-level libcamera namespace.
Definition: backtrace.h:17
Private()
Construct an instance of an Extensible class private data.
Definition: class.cpp:194
T * _d()
Retrieve the private data instance.
Definition: class.h:100
Base class to manage private data through a d-pointer.
Definition: class.h:61