Zivid C++ API 2.9.0+4dbba385-1
Defining the Future of 3D Machine Vision
Traits.h
Go to the documentation of this file.
1
2
3/*******************************************************************************
4
5 * This file is part of the Zivid 3D Camera API
6
7 *
8
9 * Copyright 2015-2023 (C) Zivid AS
10
11 * All rights reserved.
12
13 *
14
15 * Zivid Software License, v1.0
16
17 *
18
19 * Redistribution and use in source and binary forms, with or without
20
21 * modification, are permitted provided that the following conditions are met:
22
23 *
24
25 * 1. Redistributions of source code must retain the above copyright notice,
26
27 * this list of conditions and the following disclaimer.
28
29 *
30
31 * 2. Redistributions in binary form must reproduce the above copyright notice,
32
33 * this list of conditions and the following disclaimer in the documentation
34
35 * and/or other materials provided with the distribution.
36
37 *
38
39 * 3. Neither the name of Zivid AS nor the names of its contributors may be used
40
41 * to endorse or promote products derived from this software without specific
42
43 * prior written permission.
44
45 *
46
47 * 4. This software, with or without modification, must not be used with any
48
49 * other 3D camera than from Zivid AS.
50
51 *
52
53 * 5. Any software provided in binary form under this license must not be
54
55 * reverse engineered, decompiled, modified and/or disassembled.
56
57 *
58
59 * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
60
61 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62
63 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
64
65 * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
66
67 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68
69 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
70
71 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
72
73 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
74
75 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
76
77 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78
79 *
80
81 * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
82
83 * Info: http://www.zivid.com
84
85 ******************************************************************************/
86
87
88
89#pragma once
90
92
93#include <type_traits>
94
95namespace Zivid
96{
97 namespace DataModel
98 {
99#ifndef NO_DOC
101 namespace Detail
102 {
103 template<class...>
104 using Void = void;
105
106 void acceptNodeType(Zivid::DataModel::NodeType);
107
108 template<typename T, typename = void>
109 struct IsDataModelType : std::false_type
110 {};
111
112 template<typename T>
113 struct IsDataModelType<T, Void<decltype(acceptNodeType(std::decay<T>::type::nodeType))>> : std::true_type
114 {};
115
116 template<typename T>
117 struct IsDataModelLeaf
118 {
119 private:
120 template<
121 typename C,
122 typename std::enable_if<
123 std::decay<C>::type::nodeType == Zivid::DataModel::NodeType::leafValue
124 || std::decay<C>::type::nodeType == Zivid::DataModel::NodeType::leafDataModelList,
125 int>::type = 0>
126 static constexpr std::true_type isLeafHelper(int);
127 template<typename C, typename... Args>
128 static constexpr std::false_type isLeafHelper(Args &&...);
129
130 public:
131 using Type = decltype(isLeafHelper<T>(0));
132 };
133
134 template<typename T, typename = void>
135 struct IsOptional : std::false_type
136 {};
137
138 template<typename T>
139 struct IsOptional<T, Void<decltype(std::declval<T>().hasValue())>> : std::true_type
140 {};
141
142 template<typename T, typename = void>
143 struct HasValidRange : std::false_type
144 {};
145
146 template<typename T>
147 struct HasValidRange<T, Void<decltype(std::declval<typename std::decay<T>::type>().validRange())>>
148 : std::true_type
149 {};
150
151 template<typename T, typename = void>
152 struct HasValidValues : std::false_type
153 {};
154
155 template<typename T>
156 struct HasValidValues<T, Void<decltype(std::declval<typename std::decay<T>::type>().validValues())>>
157 : std::true_type
158 {};
159
160 template<typename T, typename = void>
161 struct HasValidSize : std::false_type
162 {};
163
164 template<typename T>
165 struct HasValidSize<T, Void<decltype(std::declval<typename std::decay<T>::type>().validSize())>>
166 : std::true_type
167 {};
168 } // namespace Detail
169#endif
170
176 template<typename T>
177 using IsDataModelType = typename Detail::IsDataModelType<T>::type;
178
185 template<typename T>
186 using IsDataModelLeaf = typename Detail::IsDataModelLeaf<T>::Type;
187
188 template<typename T>
189 struct IsOptional : Detail::IsOptional<T>
190 {
191 static_assert(
193 "The template parameter to IsOptional must be a data model leaf type");
194 };
195
202 template<typename T>
203 struct HasValidRange : Detail::HasValidRange<T>
204 {
205 static_assert(
207 "The template parameter to HasValidRange must be a data model leaf type");
208 };
209
216 template<typename T>
217 struct HasValidValues : Detail::HasValidValues<T>
218 {
219 static_assert(
221 "The template parameter to HasValidValues must be a data model leaf type");
222 };
223
230 template<typename T>
231 struct HasValidSize : Detail::HasValidSize<T>
232 {
233 static_assert(
235 "The template parameter to HasValidSize must be a data model leaf type");
236 };
237
238 } // namespace DataModel
239} // namespace Zivid
NodeType
Definition: NodeType.h:100
typename Detail::IsDataModelLeaf< T >::Type IsDataModelLeaf
Check if T is a data model leaf type
Definition: Traits.h:186
typename Detail::IsDataModelType< T >::type IsDataModelType
Check if T is a data model type
Definition: Traits.h:177
Ret validRange(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:225
std::set< typename T::ValueType > validValues(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:219
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:99
Check if T has a ValidRange constraint
Definition: Traits.h:204
Check if T has a ValidSize constraint
Definition: Traits.h:232
Check if data model type T has a ValidValues constraint
Definition: Traits.h:218
Definition: Traits.h:190