Zivid C++ API 2.11.1+de9b5dae-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 IsOptional : std::false_type
91 {};
92
93 template<typename T>
94 struct IsOptional<T, Void<decltype(std::declval<T>().hasValue())>> : std::true_type
95 {};
96
97 template<typename T, typename = void>
98 struct HasValidRange : std::false_type
99 {};
100
101 template<typename T>
102 struct HasValidRange<T, Void<decltype(std::declval<typename std::decay<T>::type>().validRange())>>
103 : std::true_type
104 {};
105
106 template<typename T, typename = void>
107 struct HasValidValues : std::false_type
108 {};
109
110 template<typename T>
111 struct HasValidValues<T, Void<decltype(std::declval<typename std::decay<T>::type>().validValues())>>
112 : std::true_type
113 {};
114
115 template<typename T, typename = void>
116 struct HasValidSize : std::false_type
117 {};
118
119 template<typename T>
120 struct HasValidSize<T, Void<decltype(std::declval<typename std::decay<T>::type>().validSize())>>
121 : std::true_type
122 {};
123 } // namespace Detail
124#endif
125
131 template<typename T>
132 using IsDataModelType = typename Detail::IsDataModelType<T>::type;
133
140 template<typename T>
141 using IsDataModelLeaf = typename Detail::IsDataModelLeaf<T>::Type;
142
143 template<typename T>
144 struct IsOptional : Detail::IsOptional<T>
145 {
146 static_assert(
148 "The template parameter to IsOptional must be a data model leaf type");
149 };
150
157 template<typename T>
158 struct HasValidRange : Detail::HasValidRange<T>
159 {
160 static_assert(
162 "The template parameter to HasValidRange must be a data model leaf type");
163 };
164
171 template<typename T>
172 struct HasValidValues : Detail::HasValidValues<T>
173 {
174 static_assert(
176 "The template parameter to HasValidValues must be a data model leaf type");
177 };
178
185 template<typename T>
186 struct HasValidSize : Detail::HasValidSize<T>
187 {
188 static_assert(
190 "The template parameter to HasValidSize must be a data model leaf type");
191 };
192
193 } // namespace DataModel
194} // namespace Zivid
NodeType
Definition NodeType.h:55
typename Detail::IsDataModelLeaf< T >::Type IsDataModelLeaf
Check if T is a data model leaf type.
Definition Traits.h:141
typename Detail::IsDataModelType< T >::type IsDataModelType
Check if T is a data model type.
Definition Traits.h:132
Ret validRange(const CameraInfo &cameraInfo)
Definition SettingsInfo.h:182
std::set< typename T::ValueType > validValues(const CameraInfo &cameraInfo)
Definition SettingsInfo.h:176
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:54
Check if T has a ValidRange constraint.
Definition Traits.h:159
Check if T has a ValidSize constraint.
Definition Traits.h:187
Check if data model type T has a ValidValues constraint.
Definition Traits.h:173
Definition Traits.h:145