|
| 1 | +/* Copyright © 2018-2019 Pascal JEAN, All rights reserved. |
| 2 | + * This file is part of the libmodbuspp Library. |
| 3 | + * |
| 4 | + * The libmodbuspp Library is free software; you can redistribute it and/or |
| 5 | + * modify it under the terms of the GNU Lesser General Public |
| 6 | + * License as published by the Free Software Foundation; either |
| 7 | + * version 3 of the License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * The libmodbuspp Library is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | + * Lesser General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public License |
| 15 | + * along with the libmodbuspp Library; if not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +#pragma once |
| 18 | + |
| 19 | +#include <memory> |
| 20 | + |
| 21 | +/* |
| 22 | + * Internal: Pointer to implementation |
| 23 | + * "Pointer to implementation" or "pImpl" is a C++ programming technique that |
| 24 | + * removes implementation details of a class from its object representation by |
| 25 | + * placing them in a separate class, accessed through an opaque pointer. |
| 26 | + * This technique is used to construct C++ library interfaces with stable |
| 27 | + * ABI and to reduce compile-time dependencies. |
| 28 | + */ |
| 29 | +#define PIMP_D(Class) Class::Private * const d = d_func() |
| 30 | +#define PIMP_Q(Class) Class * const q = q_func() |
| 31 | +#define PIMP_DECLARE_PRIVATE(Class)\ |
| 32 | + inline Class::Private* d_func() {\ |
| 33 | + return reinterpret_cast<Class::Private*>(d_ptr.get());\ |
| 34 | + }\ |
| 35 | + inline const Class::Private* d_func() const {\ |
| 36 | + return reinterpret_cast<const Class::Private *>(d_ptr.get());\ |
| 37 | + }\ |
| 38 | + friend class Class::Private; |
| 39 | +#define PIMP_DECLARE_PUBLIC(Class) \ |
| 40 | + inline Class* q_func() { return reinterpret_cast<Class *>(q_ptr); } \ |
| 41 | + inline const Class* q_func() const { return reinterpret_cast<const Class *>(q_ptr); } \ |
| 42 | + friend class Class; |
| 43 | + |
| 44 | +/* ========================================================================== */ |
0 commit comments