Zivid C++ API  2.4.2+1a2e8cfb-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-2021 (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 
95 namespace 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<typename C,
121  typename std::enable_if<std::decay<C>::type::nodeType == Zivid::DataModel::NodeType::leafValue
122  || std::decay<C>::type::nodeType
124  int>::type = 0>
125  static constexpr std::true_type isLeafHelper(int);
126  template<typename C, typename... Args>
127  static constexpr std::false_type isLeafHelper(Args &&...);
128 
129  public:
130  using Type = decltype(isLeafHelper<T>(0));
131  };
132 
133  template<typename T, typename = void>
134  struct IsOptional : std::false_type
135  {};
136 
137  template<typename T>
138  struct IsOptional<T, Void<decltype(std::declval<T>().hasValue())>> : std::true_type
139  {};
140 
141  template<typename T, typename = void>
142  struct HasValidRange : std::false_type
143  {};
144 
145  template<typename T>
146  struct HasValidRange<T, Void<decltype(std::declval<typename std::decay<T>::type>().validRange())>>
147  : std::true_type
148  {};
149 
150  template<typename T, typename = void>
151  struct HasValidValues : std::false_type
152  {};
153 
154  template<typename T>
155  struct HasValidValues<T, Void<decltype(std::declval<typename std::decay<T>::type>().validValues())>>
156  : std::true_type
157  {};
158 
159  template<typename T, typename = void>
160  struct HasValidSize : std::false_type
161  {};
162 
163  template<typename T>
164  struct HasValidSize<T, Void<decltype(std::declval<typename std::decay<T>::type>().validSize())>>
165  : std::true_type
166  {};
167  } // namespace Detail
168 #endif
169 
175  template<typename T>
176  using IsDataModelType = typename Detail::IsDataModelType<T>::type;
177 
184  template<typename T>
185  using IsDataModelLeaf = typename Detail::IsDataModelLeaf<T>::Type;
186 
187  template<typename T>
188  struct IsOptional : Detail::IsOptional<T>
189  {
190  static_assert(IsDataModelLeaf<T>::value,
191  "The template parameter to IsOptional must be a data model leaf type");
192  };
193 
200  template<typename T>
201  struct HasValidRange : Detail::HasValidRange<T>
202  {
203  static_assert(IsDataModelLeaf<T>::value,
204  "The template parameter to HasValidRange must be a data model leaf type");
205  };
206 
213  template<typename T>
214  struct HasValidValues : Detail::HasValidValues<T>
215  {
216  static_assert(IsDataModelLeaf<T>::value,
217  "The template parameter to HasValidValues must be a data model leaf type");
218  };
219 
226  template<typename T>
227  struct HasValidSize : Detail::HasValidSize<T>
228  {
229  static_assert(IsDataModelLeaf<T>::value,
230  "The template parameter to HasValidSize must be a data model leaf type");
231  };
232 
233  } // namespace DataModel
234 } // 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:185
typename Detail::IsDataModelType< T >::type IsDataModelType
Check if T is a data model type
Definition: Traits.h:176
Ret validRange(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:200
std::set< typename T::ValueType > validValues(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:194
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:99
Check if T has a ValidRange constraint
Definition: Traits.h:202
Check if T has a ValidSize constraint
Definition: Traits.h:228
Check if data model type T has a ValidValues constraint
Definition: Traits.h:215
Definition: Traits.h:189