RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
typeTraits.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_COMPONENTFRAMEWORK_TYPETRAITS_HPP
13#define RTCTK_COMPONENTFRAMEWORK_TYPETRAITS_HPP
14
15#include <complex>
16#include <gsl/span>
17#include <utility>
18#include <vector>
19
22
24
25// The following are helper classes to identify certain type specialisations.
26
31template <typename>
32struct IsVectorType : std::false_type {};
33
38template <typename T, typename A>
39struct IsVectorType<std::vector<T, A>> : std::true_type {};
40
45template <typename T>
46inline constexpr bool IS_VECTOR_TYPE = IsVectorType<T>::value;
47
48// tests
49static_assert(IS_VECTOR_TYPE<std::array<uint8_t, 1>> == false);
50static_assert(IS_VECTOR_TYPE<gsl::span<uint8_t>> == false);
51static_assert(IS_VECTOR_TYPE<gsl::span<uint8_t, 3>> == false);
52static_assert(IS_VECTOR_TYPE<std::vector<uint8_t>> == true);
54static_assert(IS_VECTOR_TYPE<uint8_t> == false);
55static_assert(IS_VECTOR_TYPE<MatrixBuffer<uint8_t>> == false);
56
61template <typename>
62struct IsMatrixBufferType : std::false_type {};
63
68template <typename T, typename A>
69struct IsMatrixBufferType<MatrixBuffer<T, A>> : std::true_type {};
70
75template <typename T>
77
78// tests
80static_assert(IS_MATRIX_BUFFER_TYPE<gsl::span<uint8_t>> == false);
81static_assert(IS_MATRIX_BUFFER_TYPE<gsl::span<uint8_t, 3>> == false);
82static_assert(IS_MATRIX_BUFFER_TYPE<std::vector<uint8_t>> == false);
83static_assert(IS_MATRIX_BUFFER_TYPE<uint8_t> == false);
86
91template <typename>
92struct IsSpanType : std::false_type {};
93
98template <typename T, decltype(gsl::dynamic_extent) N>
99struct IsSpanType<gsl::span<T, N>> : std::true_type {};
100
105template <typename T>
106inline constexpr bool IS_SPAN_TYPE = IsSpanType<T>::value;
107
112template <typename>
113struct IsMatrixSpanType : std::false_type {};
114
119template <typename T>
120struct IsMatrixSpanType<MatrixSpan<T>> : std::true_type {};
121
126template <typename T>
128
133template <typename>
134struct IsStdArrayType : std::false_type {};
135
140template <typename T, std::size_t N>
141struct IsStdArrayType<std::array<T, N>> : std::true_type {};
142
147template <typename T>
149
150// tests
151static_assert(IS_STD_ARRAY_TYPE<std::array<uint8_t, 1>> == true);
152static_assert(IS_STD_ARRAY_TYPE<gsl::span<uint8_t, 3>> == false);
153static_assert(IS_STD_ARRAY_TYPE<gsl::span<uint8_t>> == false);
154static_assert(IS_STD_ARRAY_TYPE<uint8_t> == false);
155static_assert(IS_STD_ARRAY_TYPE<std::vector<uint8_t>> == false);
156static_assert(IS_STD_ARRAY_TYPE<MatrixBuffer<uint8_t>> == false);
157
162template <typename>
163struct IsStaticSpanType : std::false_type {};
164
169template <typename T, decltype(gsl::dynamic_extent) N>
170struct IsStaticSpanType<gsl::span<T, N>>
171 : std::conditional_t<N == gsl::dynamic_extent, std::false_type, std::true_type> {};
172
177template <typename T>
179
180// tests
181static_assert(IS_STATIC_SPAN_TYPE<std::array<uint8_t, 1>> == false);
182static_assert(IS_STATIC_SPAN_TYPE<gsl::span<uint8_t, 3>> == true);
183static_assert(IS_STATIC_SPAN_TYPE<gsl::span<uint8_t>> == false);
184static_assert(IS_STATIC_SPAN_TYPE<uint8_t> == false);
185static_assert(IS_STATIC_SPAN_TYPE<std::vector<uint8_t>> == false);
186static_assert(IS_STATIC_SPAN_TYPE<MatrixBuffer<uint8_t>> == false);
187
192template <typename>
193struct IsDynamicSpanType : std::false_type {};
194
199template <typename T, decltype(gsl::dynamic_extent) N>
200struct IsDynamicSpanType<gsl::span<T, N>>
201 : std::conditional_t<N == gsl::dynamic_extent, std::true_type, std::false_type> {};
202
207template <typename T>
209
210// tests
211static_assert(IS_DYNAMIC_SPAN_TYPE<std::array<uint8_t, 1>> == false);
212static_assert(IS_DYNAMIC_SPAN_TYPE<gsl::span<uint8_t>> == true);
213static_assert(IS_DYNAMIC_SPAN_TYPE<gsl::span<uint8_t, 3>> == false);
214static_assert(IS_DYNAMIC_SPAN_TYPE<uint8_t> == false);
215static_assert(IS_DYNAMIC_SPAN_TYPE<std::vector<uint8_t>> == false);
216static_assert(IS_DYNAMIC_SPAN_TYPE<MatrixBuffer<uint8_t>> == false);
217
222template <class, class = void>
223struct IsSupportedUriSchemeDefined : std::false_type {};
224
229template <class T>
230struct IsSupportedUriSchemeDefined<T, std::void_t<decltype(T::SUPPORTED_URI_SCHEME)>>
231 : std::true_type {};
232
237template <typename T>
239
250template <class, class = void>
251struct IsAdapterIdTypeDefined : std::false_type {};
252
257template <class T>
258struct IsAdapterIdTypeDefined<T, std::void_t<decltype(std::declval<typename T::AdapterIdType>())>>
259 : std::true_type {};
260
265template <typename T>
267
272template <typename>
273struct IsComplexType : std::false_type {};
274
279template <typename T>
280struct IsComplexType<std::complex<T>> : std::true_type {};
281
286template <typename T>
288
289} // namespace rtctk::componentFramework
290
291#endif // RTCTK_COMPONENTFRAMEWORK_TYPETRAITS_HPP
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:27
A span referencing a 2D matrix buffer.
Definition matrixSpan.hpp:35
constexpr bool IS_STATIC_SPAN_TYPE
Is true if the type is a gsl::span type with fixed size.
Definition typeTraits.hpp:178
constexpr bool IS_MATRIX_SPAN_TYPE
Is true if the type is a MatrixSpan<U> of some type U.
Definition typeTraits.hpp:127
constexpr bool IS_STD_ARRAY_TYPE
Is true if the type is a std::array<U> of some type U.
Definition typeTraits.hpp:148
constexpr bool IS_SPAN_TYPE
Is true if the type is a gsl::span<U> of some type U.
Definition typeTraits.hpp:106
constexpr bool IS_ADAPTER_ID_TYPE_DEFINED
Is true if the class contains the type declaration for AdapterIdType.
Definition typeTraits.hpp:266
constexpr bool IS_DYNAMIC_SPAN_TYPE
Is true if the type is a gsl::span type with dynamic size.
Definition typeTraits.hpp:208
constexpr bool IS_VECTOR_TYPE
Is true if the type is a std::vector<U> of some type U.
Definition typeTraits.hpp:46
constexpr bool IS_SUPPORTED_URI_SCHEME_DEFINED
Is true if the class contains the member SUPPORTED_URI_SCHEME.
Definition typeTraits.hpp:238
constexpr bool IS_MATRIX_BUFFER_TYPE
Is true if the type is a MatrixBuffer<U> of some type U.
Definition typeTraits.hpp:76
constexpr bool IS_COMPLEX_TYPE
Is true if the type is a std::complex<U> of some type U.
Definition typeTraits.hpp:287
Declaration of the MatrixBuffer template class used in APIs.
Declaration of the MatrixSpan template class used in APIs.
Definition commandReplier.cpp:21
Definition ddsSub.hpp:155
Structure for detecting if a class declared a type called AdapterIdType using SFINAE.
Definition typeTraits.hpp:251
Structure for detecting std::vector types using SFINAE.
Definition typeTraits.hpp:273
Structure for detecting gsl::span types of dynamic size using SFINAE.
Definition typeTraits.hpp:193
Structure for detecting MatrixBuffer types using SFINAE.
Definition typeTraits.hpp:62
Structure for detecting MatrixSpan types using SFINAE.
Definition typeTraits.hpp:113
Structure for detecting gsl::span types using SFINAE.
Definition typeTraits.hpp:92
Structure for detecting gsl::span types of fixed size using SFINAE.
Definition typeTraits.hpp:163
Structure for detecting std::array types using SFINAE.
Definition typeTraits.hpp:134
Structure for detecting if a class declared a member called SUPPORTED_URI_SCHEME using SFINAE.
Definition typeTraits.hpp:223
Structure for detecting std::vector types using SFINAE.
Definition typeTraits.hpp:32