mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ndarray_view_generic.h
Go to the documentation of this file.
1 #ifndef MF_NDARRAY_VIEW_GENERIC_H_
2 #define MF_NDARRAY_VIEW_GENERIC_H_
3 
4 #include "frame_format.h"
5 #include "../ndarray_view.h"
6 #include "../ndarray_timed_view.h"
7 #include "../../common.h"
8 #include <stdexcept>
9 
10 namespace mf {
11 
13 
24 template<std::size_t Dim>
25 class ndarray_view_generic : public ndarray_view<Dim + 1, byte> {
27 
28 public:
29  using shape_type = typename base::shape_type;
30  using strides_type = typename base::strides_type;
31 
32 private:
33  frame_format format_;
34 
35  ndarray_view_generic() : format_(frame_format::null()) { }
36 
37 public:
39  base(vw), format_(format) { }
40 
42  base(start, shape, strides),
43  format_(format) { }
44 
46 
47  const frame_format& format() const noexcept { return format_; }
48 
49  decltype(auto) slice(std::ptrdiff_t c, std::ptrdiff_t dimension) const
50  { return ndarray_view_generic<Dim - 1>(base::slice(c, dimension), format_); }
51 
52  decltype(auto) operator[](std::ptrdiff_t c) const
53  { return ndarray_view_generic<Dim - 1>(base::operator[](c), format_); }
54 
55  decltype(auto) operator()(std::ptrdiff_t start, std::ptrdiff_t end, std::ptrdiff_t step = 1) const
56  { return ndarray_view_generic(base::operator()(start, end, step), format_); }
57 
58  decltype(auto) operator()(std::ptrdiff_t c) const
59  { return ndarray_view_generic(base::operator()(c), format_); }
60 
61  decltype(auto) operator()() const
62  { return ndarray_view_generic(base::operator()(), format_); }
63 
64  void reset(const ndarray_view_generic& other) noexcept {
65  base::reset(other);
66  format_ = other.format_;
67  }
68  void reset() noexcept { reset(null()); }
69 };
70 
71 
72 
74 
77 template<std::size_t Generic_dim, std::size_t Concrete_dim, typename Concrete_elem>
78 ndarray_view_generic<Generic_dim> to_generic(const ndarray_view<Concrete_dim, Concrete_elem>& vw);
79 
80 
81 
83 template<std::size_t Concrete_dim, typename Concrete_elem, std::size_t Generic_dim>
84 ndarray_view<Concrete_dim, Concrete_elem> from_generic(
85  const ndarray_view_generic<Generic_dim>& vw,
86  const ndsize<Concrete_dim - Generic_dim>& frame_shape
87 );
88 
89 
90 
91 }
92 
93 
94 #include "ndarray_view_generic.tcc"
95 
96 #endif
Generic ndarray_view where lower dimension(s) are type-erased.
Definition: ndarray_view_generic.h:25
Mapping between coordinates, indices, and addresses of multi-dimensional data.
Definition: ndarray_view.h:16
std::uint8_t byte
Single byte type.
Definition: common.h:56
ndsize< Dim > shape_type
Definition: ndarray_view.h:75
const shape_type & shape() const noexcept
Definition: ndarray_view.h:200
static ndarray_view_generic null()
Definition: ndarray_view_generic.h:45
typename base::shape_type shape_type
Definition: ndarray_view_generic.h:29
decltype(auto) operator[](std::ptrdiff_t c) const
Subscript operator, creates slice on first dimension.
Definition: ndarray_view.h:163
ndarray_view< Dim-1, byte > slice(std::ptrdiff_t c, std::ptrdiff_t dimension) const
Create ndarray_view with one less dimension, by fixing coordinate of axis dimension to c...
void reset(const ndarray_view_generic &other) noexcept
Definition: ndarray_view_generic.h:64
ndarray_timed_view_generic< Generic_dim > to_generic(const ndarray_timed_view< Concrete_dim, Concrete_elem > &vw)
Definition: ndarray_timed_view_generic.h:56
ndptrdiff< Dim > strides_type
Definition: ndarray_view.h:76
ndarray_view_generic(byte *start, const frame_format &format, const shape_type &shape, const strides_type &strides)
Definition: ndarray_view_generic.h:41
const frame_format & format() const noexcept
Definition: ndarray_view_generic.h:47
typename base::strides_type strides_type
Definition: ndarray_view_generic.h:30
ndarray_view_generic(const base &vw, const frame_format &format)
Definition: ndarray_view_generic.h:38
void reset() noexcept
Definition: ndarray_view_generic.h:68
static constexpr std::size_t dimension
Definition: ndarray_view.h:81
const strides_type & strides() const noexcept
Definition: ndarray_view.h:201
pointer start() const noexcept
Definition: ndarray_view.h:199
Format information of type-erased frame of ndarray_view_generic.
Definition: frame_format.h:14
void reset() noexcept
Definition: ndarray_view.h:127
ndarray_timed_view< Concrete_dim, Concrete_elem > from_generic(const ndarray_timed_view_generic< Generic_dim > &gen_vw, const ndsize< Concrete_dim-Generic_dim > &frame_shape)
Definition: ndarray_timed_view_generic.h:64
decltype(auto) slice(std::ptrdiff_t c, std::ptrdiff_t dimension) const
Definition: ndarray_view_generic.h:49