mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
common.h
Go to the documentation of this file.
1 #ifndef MF_COMMON_H_
2 #define MF_COMMON_H_
3 
4 #include <cstddef>
5 #include <cassert>
6 #include <exception>
7 #include <stdexcept>
8 
9 #include <ostream>
10 
11 #include "ndarray/ndspan.h"
12 #include "debug.h"
13 #include "exceptions.h"
14 
15 
16 #ifndef NDEBUG
17 
18  #define MF_ASSERT_MSG(condition, msg) \
19  if(!(condition)) { \
20  MF_DEBUG_BACKTRACE("assertion failed: " msg); \
21  std::abort(); \
22  }
23 
24  #define MF_ASSERT(condition) MF_ASSERT_MSG(condition, "`" #condition "`")
25 
26  #define MF_EXPECTS_MSG(condition, msg) MF_ASSERT_MSG(condition, "precondition: " msg)
27  #define MF_EXPECTS(condition) MF_EXPECTS_MSG(condition, "`" #condition "`")
28 
29  #define MF_ENSURES_MSG(condition, msg) MF_ASSERT_MSG(condition, "postcondition: " msg)
30  #define MF_ENSURES(condition) MF_EXPECTS_MSG(condition, "`" #condition "`")
31 
32 #else
33 
34  #define MF_ASSERT_MSG(condition, msg) ((void)0)
35  #define MF_ASSERT(condition) ((void)0)
36  #define MF_EXPECTS(condition) ((void)0)
37  #define MF_EXPECTS_MSG(condition, msg) ((void)0)
38  #define MF_ENSURES(condition) ((void)0)
39  #define MF_ENSURES_MSG(condition, msg) ((void)0)
40 
41 #endif
42 
43 
44 namespace mf {
45 
46 
48 using real = float;
49 
50 
52 using time_unit = std::ptrdiff_t;
53 
54 
56 using byte = std::uint8_t;
57 
58 
60 
61 class time_span : public ndspan<1, time_unit> {
62  using base = ndspan<1, time_unit>;
63 
64 public:
65  time_span() = default;
66  time_span(const base& span) : base(span) { }
68  base{start, end} { }
69 
70  time_unit start_time() const { return base::start_pos().front(); }
71  time_unit end_time() const { return base::end_pos().front(); }
72  time_unit duration() const { return base::size(); }
73 };
74 
75 
76 inline std::ostream& operator<<(std::ostream& str, const time_span& span) {
77  str << '[' << span.start_time() << ", " << span.end_time() << '[';
78  return str;
79 }
80 
81 
82 }
83 
84 #endif
float real
Real number type.
Definition: common.h:48
std::ptrdiff_t time_unit
Discrete time unit type.
Definition: common.h:52
std::uint8_t byte
Single byte type.
Definition: common.h:56
time_unit start_time() const
Definition: common.h:70
time_span()=default
time_span(time_unit start, time_unit end)
Definition: common.h:67
time_span(const base &span)
Definition: common.h:66
time_unit end_time() const
Definition: common.h:71
const coordinates_type & end_pos() const noexcept
Definition: ndspan.h:32
time_unit duration() const
Definition: common.h:72
Cuboid n-dimensional span delimited by two ndcoord vectors.
Definition: ndspan.h:15
std::size_t size() const
Definition: ndspan.h:47
One-dimensional time span.
Definition: common.h:61
const T & front() const noexcept
Definition: ndcoord.h:117
const coordinates_type & start_pos() const noexcept
Definition: ndspan.h:31
std::ostream & operator<<(std::ostream &str, const time_span &span)
Definition: common.h:76