Zivid C++ API 2.14.0+e4a0c4a9-1
Traits.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
47
48#include <type_traits>
49
50namespace Zivid
51{
52 namespace DataModel
53 {
54#ifndef NO_DOC
56 namespace Detail
57 {
58 template<class...>
59 using Void = void;
60
61 void acceptNodeType(Zivid::DataModel::NodeType);
62
63 template<typename T, typename = void>
64 struct IsDataModelType : std::false_type
65 {};
66
67 template<typename T>
68 struct IsDataModelType<T, Void<decltype(acceptNodeType(std::decay<T>::type::nodeType))>> : std::true_type
69 {};
70
71 template<typename T>
72 struct IsDataModelLeaf
73 {
74 private:
75 template<
76 typename C,
77 typename std::enable_if<
78 std::decay<C>::type::nodeType == Zivid::DataModel::NodeType::leafValue
79 || std::decay<C>::type::nodeType == Zivid::DataModel::NodeType::leafDataModelList,
80 int>::type = 0>
81 static constexpr std::true_type isLeafHelper(int);
82 template<typename C, typename... Args>
83 static constexpr std::false_type isLeafHelper(Args &&...);
84
85 public:
86 using Type = decltype(isLeafHelper<T>(0));
87 };
88
89 template<typename T, typename = void>
90 struct IsDataModelRoot : std::false_type
91 {};
92
93 template<typename T>
94 struct IsDataModelRoot<T, Void<decltype(std::decay_t<T>::version)>> : IsDataModelType<T>
95 {};
96
97 template<typename T, typename = void>
98 struct IsOptional : std::false_type
99 {};
100
101 template<typename T>
102 struct IsOptional<T, Void<decltype(std::declval<T>().hasValue())>> : std::true_type
103 {};
104
105 template<typename T, typename = void>
106 struct IsNestedDataModelLeaf : std::false_type
107 {};
108
109 template<typename T>
110 struct IsNestedDataModelLeaf<T, Void<typename std::decay_t<T>::ValueType>>
111 : std::integral_constant<
112 bool,
113 IsDataModelLeaf<T>::Type::value && IsDataModelRoot<typename std::decay_t<T>::ValueType>::value>
114 {};
115
116 template<typename T, typename = void>
117 struct HasValidRange : std::false_type
118 {};
119
120 template<typename T>
121 struct HasValidRange<T, Void<decltype(std::declval<typename std::decay<T>::type>().validRange())>>
122 : std::true_type
123 {};
124
125 template<typename T, typename = void>
126 struct HasValidValues : std::false_type
127 {};
128
129 template<typename T>
130 struct HasValidValues<T, Void<decltype(std::declval<typename std::decay<T>::type>().validValues())>>
131 : std::true_type
132 {};
133
134 template<typename T, typename = void>
135 struct HasValidSize : std::false_type
136 {};
137
138 template<typename T>
139 struct HasValidSize<T, Void<decltype(std::declval<typename std::decay<T>::type>().validSize())>>
140 : std::true_type
141 {};
142 } // namespace Detail
143#endif
144
150 template<typename T>
151 using IsDataModelType = typename Detail::IsDataModelType<T>::type;
152
159 template<typename T>
160 using IsDataModelLeaf = typename Detail::IsDataModelLeaf<T>::Type;
161
167 template<typename T>
168 using IsNestedDataModelLeaf = typename Detail::IsNestedDataModelLeaf<T>;
169
175 template<typename T>
176 using IsDataModelRoot = typename Detail::IsDataModelRoot<T>::type;
177
178 template<typename T>
179 struct IsOptional : Detail::IsOptional<T>
180 {
181 static_assert(
183 "The template parameter to IsOptional must be a data model leaf type");
184 };
185
192 template<typename T>
193 struct HasValidRange : Detail::HasValidRange<T>
194 {
195 static_assert(
197 "The template parameter to HasValidRange must be a data model leaf type");
198 };
199
206 template<typename T>
207 struct HasValidValues : Detail::HasValidValues<T>
208 {
209 static_assert(
211 "The template parameter to HasValidValues must be a data model leaf type");
212 };
213
220 template<typename T>
221 struct HasValidSize : Detail::HasValidSize<T>
222 {
223 static_assert(
225 "The template parameter to HasValidSize must be a data model leaf type");
226 };
227
228 } // namespace DataModel
229} // namespace Zivid
typename Detail::IsDataModelLeaf< T >::Type IsDataModelLeaf
Check if T is a data model leaf type.
Definition Traits.h:160
typename Detail::IsNestedDataModelLeaf< T > IsNestedDataModelLeaf
Check if T is a nested data model leaf type (a leaf with ValueType being another data model)
Definition Traits.h:168
NodeType
Definition NodeType.h:49
typename Detail::IsDataModelRoot< T >::type IsDataModelRoot
Check if T is the root of a data model.
Definition Traits.h:176
typename Detail::IsDataModelType< T >::type IsDataModelType
Check if T is a data model type.
Definition Traits.h:151
Ret validRange(const CameraInfo &cameraInfo)
Definition SettingsInfo.h:190
std::set< typename T::ValueType > validValues(const CameraInfo &cameraInfo)
Definition SettingsInfo.h:184
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:84
Check if T has a ValidRange constraint.
Definition Traits.h:194
Check if T has a ValidSize constraint.
Definition Traits.h:222
Check if data model type T has a ValidValues constraint.
Definition Traits.h:208
Definition Traits.h:180