Skip to content

Commit 0e65e74

Browse files
committed
Remove the private implementation part from global.h
1 parent 16937c0 commit 0e65e74

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

include/modbuspp/global.h

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,12 @@
1616
*/
1717
#pragma once
1818

19-
#ifndef __DOXYGEN__
20-
21-
#include <memory>
2219
#include <cstdint>
2320
#include <cstddef>
2421
#include <cerrno>
2522
#include <sys/types.h>
2623
#include <modbus.h>
27-
28-
/*
29-
* Internal: Pointer to implementation
30-
* "Pointer to implementation" or "pImpl" is a C++ programming technique that
31-
* removes implementation details of a class from its object representation by
32-
* placing them in a separate class, accessed through an opaque pointer.
33-
* This technique is used to construct C++ library interfaces with stable
34-
* ABI and to reduce compile-time dependencies.
35-
*/
36-
#define PIMP_D(Class) Class::Private * const d = d_func()
37-
#define PIMP_Q(Class) Class * const q = q_func()
38-
#define PIMP_DECLARE_PRIVATE(Class)\
39-
inline Class::Private* d_func() {\
40-
return reinterpret_cast<Class::Private*>(d_ptr.get());\
41-
}\
42-
inline const Class::Private* d_func() const {\
43-
return reinterpret_cast<const Class::Private *>(d_ptr.get());\
44-
}\
45-
friend class Class::Private;
46-
#define PIMP_DECLARE_PUBLIC(Class) \
47-
inline Class* q_func() { return reinterpret_cast<Class *>(q_ptr); } \
48-
inline const Class* q_func() const { return reinterpret_cast<const Class *>(q_ptr); } \
49-
friend class Class;
50-
#endif /* __DOXYGEN__ not defined */
24+
#include <modbuspp/pimp.h>
5125

5226
/**
5327
* @brief libmodbuspp namespace

include/modbuspp/pimp.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
/* ========================================================================== */

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set (hdr_modbuspp
3535
${MODBUSPP_INC_DIR}/modbuspp/message.h
3636
${MODBUSPP_INC_DIR}/modbuspp/netlayer.h
3737
${MODBUSPP_INC_DIR}/modbuspp/popl.h
38+
${MODBUSPP_INC_DIR}/modbuspp/pimp.h
3839
${MODBUSPP_INC_DIR}/modbuspp/request.h
3940
${MODBUSPP_INC_DIR}/modbuspp/response.h
4041
${MODBUSPP_INC_DIR}/modbuspp/router.h

libmodbuspp.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<File Name="include/modbuspp/request.h"/>
2626
<File Name="include/modbuspp/response.h"/>
2727
<File Name="include/modbuspp/router.h"/>
28+
<File Name="include/modbuspp/pimp.h"/>
2829
</VirtualDirectory>
2930
<File Name="include/modbuspp.h"/>
3031
</VirtualDirectory>

0 commit comments

Comments
 (0)