mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
elem.h
Go to the documentation of this file.
1 #ifndef MF_ELEM_H_
2 #define MF_ELEM_H_
3 
4 #include <cstddef>
5 #include <array>
6 #include <complex>
7 #include <type_traits>
8 #include "common.h"
9 
10 namespace mf {
11 
13 template<typename Elem, typename Scalar = Elem, std::size_t Components = 1, bool Nullable = false>
15  static_assert(std::is_standard_layout<Elem>::value, "elem must be standard layout type");
16  static_assert(std::is_standard_layout<Scalar>::value, "elem scalar must be standard layout type");
17 
18  using scalar_type = Scalar;
19  constexpr static bool is_tuple = false;
20  constexpr static std::size_t components = Components;
21  constexpr static std::size_t stride = sizeof(Scalar);
22 
23  constexpr static bool is_nullable = Nullable;
24 };
25 
26 
28 
29 template<typename Elem>
30 struct elem_traits : elem_traits_base<Elem> { };
31 
32 
34 
35 template<typename T, std::size_t N>
36 struct elem_traits<std::array<T, N>> :
37  elem_traits_base<std::array<T, N>, T, N> { };
38 
40 template<typename T>
41 struct elem_traits<std::complex<T>> :
42  elem_traits_base<std::complex<T>, T, 2> { };
43 
44 
45 template<typename Elem>
46 std::enable_if_t<elem_traits<Elem>::is_nullable, bool> is_null(const Elem& elem) {
47  return elem.is_null();
48 }
49 
50 
51 template<typename Elem>
52 std::enable_if_t<! elem_traits<Elem>::is_nullable, bool> is_null(const Elem& elem) {
53  return false;
54 }
55 
56 
57 }
58 
59 #endif
std::enable_if_t< elem_traits< Elem >::is_nullable, bool > is_null(const Elem &elem)
Definition: elem.h:46
static constexpr std::size_t stride
Definition: elem.h:21
Elem traits base class with the required members.
Definition: elem.h:14
Default elem traits, using Elem as standard layout scalar type.
Definition: elem.h:30
static constexpr bool is_nullable
Definition: elem.h:23
static constexpr bool is_tuple
Definition: elem.h:19
static constexpr std::size_t components
Definition: elem.h:20