Zivid C++ API
2.3.1+1a22cbf1-1
Defining the Future of 3D Machine Vision
Zivid
Detail
Pimpl.h
Go to the documentation of this file.
1
2
/*******************************************************************************
3
* This file is part of the Zivid 3D Camera API
4
*
5
* Copyright 2015-2022 (C) Zivid AS
6
* All rights reserved.
7
*
8
* Zivid Software License, v1.0
9
*
10
* Redistribution and use in source and binary forms, with or without
11
* modification, are permitted provided that the following conditions are met:
12
*
13
* 1. Redistributions of source code must retain the above copyright notice,
14
* this list of conditions and the following disclaimer.
15
*
16
* 2. Redistributions in binary form must reproduce the above copyright notice,
17
* this list of conditions and the following disclaimer in the documentation
18
* and/or other materials provided with the distribution.
19
*
20
* 3. Neither the name of Zivid AS nor the names of its contributors may be used
21
* to endorse or promote products derived from this software without specific
22
* prior written permission.
23
*
24
* 4. This software, with or without modification, must not be used with any
25
* other 3D camera than from Zivid AS.
26
*
27
* 5. Any software provided in binary form under this license must not be
28
* reverse engineered, decompiled, modified and/or disassembled.
29
*
30
* THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
31
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32
* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
33
* DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
34
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
*
41
* Contact: Zivid Customer Success Team <customersuccess@zivid.com>
42
* Info: http://www.zivid.com
43
******************************************************************************/
44
45
#pragma once
46
47
#include <memory>
48
49
// Todo(ZIVID-983): Make doxygen skip most content in this file, but not regular functions. Possibly by using NO_DOC
50
51
// ------------------------------------------------------------------------------------------------------------------ //
52
#define ZIVID_PIMPL_VALUE_SEMANTICS(ClassName, Attributes) \
53
public: \
54
Attributes ~ClassName(); \
55
Attributes ClassName(const ClassName &other); \
56
Attributes ClassName &operator=(const ClassName &other); \
57
Attributes ClassName(ClassName &&other) noexcept; \
58
Attributes ClassName &operator=(ClassName &&other) noexcept; \
59
\
60
Attributes explicit ClassName(std::unique_ptr<class ClassName##Impl> &&impl); \
61
Attributes explicit ClassName(class ClassName##Impl &&impl); \
62
Attributes class ClassName##Impl &getImpl(); \
63
Attributes const class ClassName##Impl &getImpl() const; \
64
\
65
private: \
66
std::unique_ptr<class ClassName##Impl> m_impl
67
68
#define ZIVID_PIMPL_VALUE_SEMANTICS_CPP(ClassName) \
69
ClassName::ClassName(std::unique_ptr<ClassName##Impl> &&impl) \
70
: m_impl{ std::move(impl) } \
71
{} \
72
\
73
ClassName::ClassName(ClassName##Impl &&impl) \
74
: ClassName{ std::make_unique<ClassName##Impl>(std::move(impl)) } \
75
{} \
76
\
77
ClassName::ClassName(const ClassName &other) \
78
: ClassName{ ClassName##Impl{ other.getImpl() } } \
79
{} \
80
\
81
ClassName &ClassName::operator=(const ClassName &other) \
82
{ \
83
if(this != &other) \
84
{ \
85
*m_impl = other.getImpl(); \
86
} \
87
return *this; \
88
} \
89
\
90
ClassName##Impl &ClassName::getImpl() \
91
{ \
92
return *m_impl; \
93
} \
94
\
95
const ClassName##Impl &ClassName::getImpl() const \
96
{ \
97
return *m_impl; \
98
} \
99
\
100
ClassName::~ClassName() = default; \
101
ClassName::ClassName(ClassName &&other) noexcept = default; \
102
ClassName &ClassName::operator=(ClassName &&other) noexcept = default
103
104
// ------------------------------------------------------------------------------------------------------------------ //
105
#define ZIVID_PIMPL_MOVE_ONLY(ClassName, Attributes) \
106
public: \
107
Attributes ~ClassName(); \
108
Attributes ClassName(const ClassName &other) = delete; \
109
Attributes ClassName &operator=(const ClassName &other) = delete; \
110
Attributes ClassName(ClassName &&other) noexcept; \
111
Attributes ClassName &operator=(ClassName &&other) noexcept; \
112
\
113
Attributes explicit ClassName(std::unique_ptr<class ClassName##Impl> &&impl); \
114
Attributes class ClassName##Impl &getImpl(); \
115
Attributes const class ClassName##Impl &getImpl() const; \
116
\
117
private: \
118
std::unique_ptr<class ClassName##Impl> m_impl
119
120
#define ZIVID_PIMPL_MOVE_ONLY_CPP(ClassName) \
121
ClassName::ClassName(std::unique_ptr<ClassName##Impl> &&impl) \
122
: m_impl{ std::move(impl) } \
123
{} \
124
\
125
ClassName##Impl &ClassName::getImpl() \
126
{ \
127
return *m_impl; \
128
} \
129
\
130
const ClassName##Impl &ClassName::getImpl() const \
131
{ \
132
return *m_impl; \
133
} \
134
\
135
ClassName::~ClassName() = default; \
136
ClassName::ClassName(ClassName &&other) noexcept = default; \
137
ClassName &ClassName::operator=(ClassName &&other) noexcept = default
138
139
// ------------------------------------------------------------------------------------------------------------------ //
140
#define ZIVID_PIMPL_REFERENCE_SEMANTICS(ClassName, Attributes) \
141
public: \
142
\
143
Attributes ClassName clone() const; \
144
\
145
Attributes ~ClassName(); \
146
Attributes ClassName(const ClassName &other); \
147
Attributes ClassName &operator=(const ClassName &other); \
148
Attributes ClassName(ClassName &&other) noexcept; \
149
Attributes ClassName &operator=(ClassName &&other) noexcept; \
150
\
151
Attributes explicit ClassName(class ClassName##Impl &&impl); \
152
Attributes class ClassName##Impl &getImpl(); \
153
Attributes const class ClassName##Impl &getImpl() const; \
154
\
155
private: \
156
std::shared_ptr<class ClassName##Impl> m_impl
157
158
#define ZIVID_PIMPL_REFERENCE_SEMANTICS_CPP(ClassName) \
159
ClassName::ClassName(ClassName##Impl &&impl) \
160
: m_impl{ std::make_shared<ClassName##Impl>(std::move(impl)) } \
161
{} \
162
\
163
ClassName##Impl &ClassName::getImpl() \
164
{ \
165
return *m_impl; \
166
} \
167
\
168
const ClassName##Impl &ClassName::getImpl() const \
169
{ \
170
return *m_impl; \
171
} \
172
\
173
ClassName ClassName::clone() const \
174
{ \
175
return ClassName{ ClassName##Impl{ *m_impl } }; \
176
} \
177
\
178
ClassName::~ClassName() = default; \
179
ClassName::ClassName(const ClassName &other) = default; \
180
ClassName &ClassName::operator=(const ClassName &other) = default; \
181
ClassName::ClassName(ClassName &&other) noexcept = default; \
182
ClassName &ClassName::operator=(ClassName &&other) noexcept = default
Generated by
1.9.1