RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
typeTraits.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_TYPETRAITS_HPP
14#define RTCTK_COMPONENTFRAMEWORK_TYPETRAITS_HPP
15
16#include <complex>
17#include <gsl/span>
18#include <utility>
19#include <vector>
20
23
25
26// The following are helper classes to identify certain type specialisations.
27
32template <typename>
33struct IsVectorType : std::false_type {};
34
39template <typename T, typename A>
40struct IsVectorType<std::vector<T, A>> : std::true_type {};
41
46template <typename T>
47inline constexpr bool IS_VECTOR_TYPE = IsVectorType<T>::value;
48
49// tests
50static_assert(IS_VECTOR_TYPE<std::array<uint8_t, 1>> == false);
51static_assert(IS_VECTOR_TYPE<gsl::span<uint8_t>> == false);
52static_assert(IS_VECTOR_TYPE<gsl::span<uint8_t, 3>> == false);
53static_assert(IS_VECTOR_TYPE<std::vector<uint8_t>> == true);
55static_assert(IS_VECTOR_TYPE<uint8_t> == false);
56static_assert(IS_VECTOR_TYPE<MatrixBuffer<uint8_t>> == false);
57
62template <typename>
63struct IsMatrixBufferType : std::false_type {};
64
69template <typename T, typename A>
70struct IsMatrixBufferType<MatrixBuffer<T, A>> : std::true_type {};
71
76template <typename T>
78
79// tests
81static_assert(IS_MATRIX_BUFFER_TYPE<gsl::span<uint8_t>> == false);
82static_assert(IS_MATRIX_BUFFER_TYPE<gsl::span<uint8_t, 3>> == false);
83static_assert(IS_MATRIX_BUFFER_TYPE<std::vector<uint8_t>> == false);
84static_assert(IS_MATRIX_BUFFER_TYPE<uint8_t> == false);
87
92template <typename>
93struct IsSpanType : std::false_type {};
94
99template <typename T, decltype(gsl::dynamic_extent) N>
100struct IsSpanType<gsl::span<T, N>> : std::true_type {};
101
106template <typename T>
107inline constexpr bool IS_SPAN_TYPE = IsSpanType<T>::value;
108
113template <typename>
114struct IsMatrixSpanType : std::false_type {};
115
120template <typename T>
121struct IsMatrixSpanType<MatrixSpan<T>> : std::true_type {};
122
127template <typename T>
129
134template <typename>
135struct IsStdArrayType : std::false_type {};
136
141template <typename T, std::size_t N>
142struct IsStdArrayType<std::array<T, N>> : std::true_type {};
143
148template <typename T>
150
151// tests
152static_assert(IS_STD_ARRAY_TYPE<std::array<uint8_t, 1>> == true);
153static_assert(IS_STD_ARRAY_TYPE<gsl::span<uint8_t, 3>> == false);
154static_assert(IS_STD_ARRAY_TYPE<gsl::span<uint8_t>> == false);
155static_assert(IS_STD_ARRAY_TYPE<uint8_t> == false);
156static_assert(IS_STD_ARRAY_TYPE<std::vector<uint8_t>> == false);
157static_assert(IS_STD_ARRAY_TYPE<MatrixBuffer<uint8_t>> == false);
158
163template <typename>
164struct IsStaticSpanType : std::false_type {};
165
170template <typename T, decltype(gsl::dynamic_extent) N>
171struct IsStaticSpanType<gsl::span<T, N>>
172 : std::conditional<N == gsl::dynamic_extent, std::false_type, std::true_type>::type {};
173
178template <typename T>
180
181// tests
182static_assert(IS_STATIC_SPAN_TYPE<std::array<uint8_t, 1>> == false);
183static_assert(IS_STATIC_SPAN_TYPE<gsl::span<uint8_t, 3>> == true);
184static_assert(IS_STATIC_SPAN_TYPE<gsl::span<uint8_t>> == false);
185static_assert(IS_STATIC_SPAN_TYPE<uint8_t> == false);
186static_assert(IS_STATIC_SPAN_TYPE<std::vector<uint8_t>> == false);
187static_assert(IS_STATIC_SPAN_TYPE<MatrixBuffer<uint8_t>> == false);
188
193template <typename>
194struct IsDynamicSpanType : std::false_type {};
195
200template <typename T, decltype(gsl::dynamic_extent) N>
201struct IsDynamicSpanType<gsl::span<T, N>>
202 : std::conditional<N == gsl::dynamic_extent, std::true_type, std::false_type>::type {};
203
208template <typename T>
210
211// tests
212static_assert(IS_DYNAMIC_SPAN_TYPE<std::array<uint8_t, 1>> == false);
213static_assert(IS_DYNAMIC_SPAN_TYPE<gsl::span<uint8_t>> == true);
214static_assert(IS_DYNAMIC_SPAN_TYPE<gsl::span<uint8_t, 3>> == false);
215static_assert(IS_DYNAMIC_SPAN_TYPE<uint8_t> == false);
216static_assert(IS_DYNAMIC_SPAN_TYPE<std::vector<uint8_t>> == false);
217static_assert(IS_DYNAMIC_SPAN_TYPE<MatrixBuffer<uint8_t>> == false);
218
223template <class, class = void>
224struct IsSupportedUriSchemeDefined : std::false_type {};
225
230template <class T>
231struct IsSupportedUriSchemeDefined<T, std::void_t<decltype(T::SUPPORTED_URI_SCHEME)>>
232 : std::true_type {};
233
238template <typename T>
240
251template <class, class = void>
252struct IsAdapterIdTypeDefined : std::false_type {};
253
258template <class T>
259struct IsAdapterIdTypeDefined<T, std::void_t<decltype(std::declval<typename T::AdapterIdType>())>>
260 : std::true_type {};
261
266template <typename T>
268
273template <typename>
274struct IsComplexType : std::false_type {};
275
280template <typename T>
281struct IsComplexType<std::complex<T>> : std::true_type {};
282
287template <typename T>
289
290} // namespace rtctk::componentFramework
291
292#endif // RTCTK_COMPONENTFRAMEWORK_TYPETRAITS_HPP
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:28
A span referencing a 2D matrix buffer.
Definition matrixSpan.hpp:35
Declaration of the MatrixBuffer template class used in APIs.
Declaration of the MatrixSpan template class used in APIs.
Definition commandReplier.cpp:22
constexpr bool IS_STATIC_SPAN_TYPE
Is true if the type is a gsl::span type with fixed size.
Definition typeTraits.hpp:179
constexpr bool IS_MATRIX_SPAN_TYPE
Is true if the type is a MatrixSpan<U> of some type U.
Definition typeTraits.hpp:128
constexpr bool IS_STD_ARRAY_TYPE
Is true if the type is a std::array<U> of some type U.
Definition typeTraits.hpp:149
constexpr bool IS_SPAN_TYPE
Is true if the type is a gsl::span<U> of some type U.
Definition typeTraits.hpp:107
constexpr bool IS_ADAPTER_ID_TYPE_DEFINED
Is true if the class contains the type declaration for AdapterIdType.
Definition typeTraits.hpp:267
constexpr bool IS_DYNAMIC_SPAN_TYPE
Is true if the type is a gsl::span type with dynamic size.
Definition typeTraits.hpp:209
constexpr bool IS_COMPLEX_TYPE
Is true if the type is a std::complex<U> of some type U.
Definition typeTraits.hpp:288
constexpr bool IS_VECTOR_TYPE
Is true if the type is a std::vector<U> of some type U.
Definition typeTraits.hpp:47
constexpr bool IS_SUPPORTED_URI_SCHEME_DEFINED
Is true if the class contains the member SUPPORTED_URI_SCHEME.
Definition typeTraits.hpp:239
constexpr bool IS_MATRIX_BUFFER_TYPE
Is true if the type is a MatrixBuffer<U> of some type U.
Definition typeTraits.hpp:77
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Structure for detecting if a class declared a type called AdapterIdType using SFINAE.
Definition typeTraits.hpp:252
Structure for detecting std::vector types using SFINAE.
Definition typeTraits.hpp:274
Structure for detecting gsl::span types of dynamic size using SFINAE.
Definition typeTraits.hpp:194
Structure for detecting MatrixBuffer types using SFINAE.
Definition typeTraits.hpp:63
Structure for detecting MatrixSpan types using SFINAE.
Definition typeTraits.hpp:114
Structure for detecting gsl::span types using SFINAE.
Definition typeTraits.hpp:93
Structure for detecting gsl::span types of fixed size using SFINAE.
Definition typeTraits.hpp:164
Structure for detecting std::array types using SFINAE.
Definition typeTraits.hpp:135
Structure for detecting if a class declared a member called SUPPORTED_URI_SCHEME using SFINAE.
Definition typeTraits.hpp:224
Structure for detecting std::vector types using SFINAE.
Definition typeTraits.hpp:33