/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Google Inc. * * class.cpp - Utilities and helpers for classes */ #include /** * \file class.h * \brief Utilities to help constructing class interfaces * * The extensible class can be inherited to create public classes with stable * ABIs. */ namespace libcamera { /** * \def LIBCAMERA_DISABLE_COPY * \brief Disable copy construction and assignment of the \a klass * \param klass The name of the class * * Example usage: * \code{.cpp} * class NonCopyable * { * public: * NonCopyable(); * ... * * private: * LIBCAMERA_DISABLE_COPY(NonCopyable) * }; * \endcode */ /** * \def LIBCAMERA_DISABLE_MOVE * \brief Disable move construction and assignment of the \a klass * \param klass The name of the class * * Example usage: * \code{.cpp} * class NonMoveable * { * public: * NonMoveable(); * ... * * private: * LIBCAMERA_DISABLE_MOVE(NonMoveable) * }; * \endcode */ /** * \def LIBCAMERA_DISABLE_COPY_AND_MOVE * \brief Disable copy and move construction and assignment of the \a klass * \param klass The name of the class * * Example usage: * \code{.cpp} * class NonCopyableNonMoveable * { * public: * NonCopyableNonMoveable(); * ... * * private: * LIBCAMERA_DISABLE_COPY_AND_MOVE(NonCopyableNonMoveable) * }; * \endcode */ /** * \def LIBCAMERA_DECLARE_PRIVATE * \brief Declare private data for a public class * * The LIBCAMERA_DECLARE_PRIVATE() macro plumbs the infrastructure necessary to * make a class manage its private data through a d-pointer. It shall be used at * the very top of the class definition. */ /** * \def LIBCAMERA_DECLARE_PUBLIC * \brief Declare public data for a private class * \param klass The public class name * * The LIBCAMERA_DECLARE_PUBLIC() macro is the counterpart of * LIBCAMERA_DECLARE_PRIVATE() to be used in the private data class. It shall be * used at the very top of the private class definition, with the public class * name passed as the \a klass parameter. */ /** * \def LIBCAMERA_O_PTR() * \brief Retrieve the public instance corresponding to the private data * * This macro is used in any member function of the private data class to access * the public class instance corresponding to the private data. */ /** * \class Extensible * \brief Base class to manage private data through a d-pointer * * The Extensible class provides a base class to implement the * d-pointer design pattern (also * known as opaque pointer * or pImpl idiom). * It helps creating public classes that can be extended without breaking their * ABI. Such classes store their private data in a separate private data object, * referenced by a pointer in the public class (hence the name d-pointer). * * Classes that follow this design pattern are referred herein as extensible * classes. To be extensible, a class PublicClass shall: * * - inherit from the Extensible class or from another extensible class * - invoke the LIBCAMERA_DECLARE_PRIVATE() macro at the very top of the class * definition * - define a private data class named PublicClass::Private that inherits from * the Private data class of the base class * - invoke the LIBCAMERA_DECLARE_PUBLIC() macro at the very top of the Private * data class definition * - pass a pointer to a newly allocated Private data object to the constructor * of the base class *<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-video"><polygon points="23 7 16 12 23 17 23 7"></polygon><rect x="1" y="5" width="15" height="14" rx="2" ry="2"></rect></svg>