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