mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
frame_format.h
Go to the documentation of this file.
1 #ifndef MF_NDARRAY_FRAME_FORMAT_H_
2 #define MF_NDARRAY_FRAME_FORMAT_H_
3 
4 #include "../../common.h"
5 #include "../../utility/misc.h"
6 #include <typeinfo>
7 #include <typeindex>
8 
9 namespace mf {
10 
12 
14 class frame_format {
15 private:
16  std::type_index elem_type_ = std::type_index(typeid(void));
17  std::size_t elem_size_ = 0;
18  std::size_t elem_alignment_ = 0;
19 
21 
23  std::size_t stride_ = 0;
24 
25  frame_format() = default;
26 
27 public:
28  frame_format(const frame_format&) = default;
29  frame_format& operator=(const frame_format&) = default;
30 
31  static frame_format null() { return frame_format(); }
32 
33  template<typename Elem>
34  static frame_format default_format(std::size_t stride = sizeof(Elem)) {
35  static_assert(sizeof(Elem) >= alignof(Elem), "sizeof always larger or equal to alignof");
36  MF_EXPECTS(stride >= sizeof(Elem) && is_nonzero_multiple_of(stride, alignof(Elem)));
37  frame_format format;
38  format.elem_type_ = std::type_index(typeid(Elem));
39  format.elem_size_ = sizeof(Elem);
40  format.elem_alignment_ = alignof(Elem);
41  format.stride_ = stride;
42  return format;
43  }
44 
45  template<typename Elem>
46  bool is_type() const noexcept {
47  std::type_index query_type(typeid(Elem));
48  return (elem_type_ == query_type);
49  }
50 
51  std::type_index elem_type_index() const noexcept { return elem_type_; }
52  std::size_t elem_size() const noexcept { return elem_size_; }
53  std::size_t elem_alignment() const noexcept { return elem_alignment_; }
54  std::size_t stride() const noexcept { return stride_; }
55  std::size_t padding() const noexcept { return (stride_ - elem_size_); }
56 };
57 
58 
59 }
60 
61 #endif
62 
std::size_t padding() const noexcept
Definition: frame_format.h:55
std::size_t elem_alignment() const noexcept
Definition: frame_format.h:53
std::size_t stride() const noexcept
Definition: frame_format.h:54
static frame_format default_format(std::size_t stride=sizeof(Elem))
Definition: frame_format.h:34
std::type_index elem_type_index() const noexcept
Definition: frame_format.h:51
#define MF_EXPECTS(condition)
Definition: common.h:27
bool is_type() const noexcept
Definition: frame_format.h:46
std::size_t elem_size() const noexcept
Definition: frame_format.h:52
frame_format & operator=(const frame_format &)=default
static frame_format null()
Definition: frame_format.h:31
Format information of type-erased frame of ndarray_view_generic.
Definition: frame_format.h:14
bool is_nonzero_multiple_of(T x, T base)
Check if x is a non-zero multiple of base.
Definition: misc.h:43