mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ndspan.h
Go to the documentation of this file.
1 #ifndef MF_NDSPAN_H_
2 #define MF_NDSPAN_H_
3 
4 #include <ostream>
5 #include "../common.h"
6 #include "ndcoord.h"
7 
8 namespace mf {
9 
11 
14 template<std::size_t Dim, typename T = std::ptrdiff_t>
15 class ndspan {
16 public:
19 
20 private:
21  coordinates_type start_;
22  coordinates_type end_;
23 
24 public:
25  ndspan() = default;
26  ndspan(const ndspan&) = default;
27  ndspan(const coordinates_type& start, const coordinates_type& end);
28 
29  ndspan& operator=(const ndspan&) noexcept = default;
30 
31  const coordinates_type& start_pos() const noexcept { return start_; }
32  const coordinates_type& end_pos() const noexcept { return end_; }
33 
34  friend bool operator==(const ndspan& a, const ndspan& b) noexcept {
35  return (a.start_ == b.start_) && (a.end_ == b.end_);
36  }
37  friend bool operator!=(const ndspan& a, const ndspan& b) noexcept {
38  return (a.start_ != b.start_) || (a.end_ != b.end_);
39  }
40 
41  bool includes(const coordinates_type&) const;
42 
43  bool includes(const ndspan& sub) const;
44  bool includes_strict(const ndspan& sub) const;
45 
46  shape_type shape() const { return end_ - start_; }
47  std::size_t size() const { return shape().product(); }
48 
49  // TODO iterator over span coordinates
50 };
51 
52 
53 template<std::size_t Dim, typename T>
55  return ndspan<Dim, T>(start, end);
56 }
57 
58 
59 template<std::size_t Dim, typename T>
60 std::ostream& operator<<(std::ostream& str, const ndspan<Dim, T>& span) {
61  str << '[' << span.start_pos() << ", " << span.end_pos() << '[';
62  return str;
63 }
64 
65 
66 template<std::size_t Dim, typename T>
67 ndspan<Dim, T> span_intersection(const ndspan<Dim, T>& a, const ndspan<Dim, T>& b);
68 
69 }
70 
71 #include "ndspan.tcc"
72 
73 #endif
shape_type shape() const
Definition: ndspan.h:46
ndspan & operator=(const ndspan &) noexcept=default
bool includes_strict(const ndspan &sub) const
Definition: ndspan.tcc:30
const coordinates_type & end_pos() const noexcept
Definition: ndspan.h:32
T product() const noexcept
Definition: ndcoord.h:111
ndspan< Dim, T > make_ndspan(const ndcoord< Dim, T > &start, const ndcoord< Dim, T > &end)
Definition: ndspan.h:54
Cuboid n-dimensional span delimited by two ndcoord vectors.
Definition: ndspan.h:15
std::size_t size() const
Definition: ndspan.h:47
const coordinates_type & start_pos() const noexcept
Definition: ndspan.h:31
ndspan< Dim, T > span_intersection(const ndspan< Dim, T > &a, const ndspan< Dim, T > &b)
Definition: ndspan.tcc:38
bool includes(const coordinates_type &) const
Definition: ndspan.tcc:14
friend bool operator!=(const ndspan &a, const ndspan &b) noexcept
Definition: ndspan.h:37
ndspan()=default
friend bool operator==(const ndspan &a, const ndspan &b) noexcept
Definition: ndspan.h:34
ndcoord< Dim, T > coordinates_type
Definition: ndspan.h:17