Zivid C++ API  2.3.1+1a22cbf1-1
Defining the Future of 3D Machine Vision
Traits.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * This file is part of the Zivid 3D Camera API
4  *
5  * Copyright 2015-2022 (C) Zivid AS
6  * All rights reserved.
7  *
8  * Zivid Software License, v1.0
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of Zivid AS nor the names of its contributors may be used
21  * to endorse or promote products derived from this software without specific
22  * prior written permission.
23  *
24  * 4. This software, with or without modification, must not be used with any
25  * other 3D camera than from Zivid AS.
26  *
27  * 5. Any software provided in binary form under this license must not be
28  * reverse engineered, decompiled, modified and/or disassembled.
29  *
30  * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
31  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
42  * Info: http://www.zivid.com
43  ******************************************************************************/
44 
45 #pragma once
46 
48 
49 #include <type_traits>
50 
51 namespace Zivid
52 {
53  namespace DataModel
54  {
55 #ifndef NO_DOC
57  namespace Detail
58  {
59  template<class...>
60  using Void = void;
61 
62  void acceptNodeType(Zivid::DataModel::NodeType);
63 
64  template<typename T, typename = void>
65  struct IsDataModelType : std::false_type
66  {};
67 
68  template<typename T>
69  struct IsDataModelType<T, Void<decltype(acceptNodeType(std::decay<T>::type::nodeType))>> : std::true_type
70  {};
71 
72  template<typename T>
73  struct IsDataModelLeaf
74  {
75  private:
76  template<typename C,
77  typename std::enable_if<std::decay<C>::type::nodeType == Zivid::DataModel::NodeType::leafValue
78  || std::decay<C>::type::nodeType
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(IsDataModelLeaf<T>::value,
147  "The template parameter to IsOptional must be a data model leaf type");
148  };
149 
156  template<typename T>
157  struct HasValidRange : Detail::HasValidRange<T>
158  {
159  static_assert(IsDataModelLeaf<T>::value,
160  "The template parameter to HasValidRange must be a data model leaf type");
161  };
162 
169  template<typename T>
170  struct HasValidValues : Detail::HasValidValues<T>
171  {
172  static_assert(IsDataModelLeaf<T>::value,
173  "The template parameter to HasValidValues must be a data model leaf type");
174  };
175 
182  template<typename T>
183  struct HasValidSize : Detail::HasValidSize<T>
184  {
185  static_assert(IsDataModelLeaf<T>::value,
186  "The template parameter to HasValidSize must be a data model leaf type");
187  };
188 
189  } // namespace DataModel
190 } // namespace Zivid
NodeType
Definition: NodeType.h:56
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:158
std::set< typename T::ValueType > validValues(const CameraInfo &cameraInfo)
Definition: SettingsInfo.h:152
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:55
Check if T has a ValidRange constraint
Definition: Traits.h:158
Check if T has a ValidSize constraint
Definition: Traits.h:184
Check if data model type T has a ValidValues constraint
Definition: Traits.h:171
Definition: Traits.h:145