EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
Interval.h
1 #ifndef INTERVAL_H_
2 #define INTERVAL_H_
3 
4 // tools
5 #include "tools/epicsTimeHelper.h"
6 #include "tools/MsgLogger.h"
7 
10 class Interval {
11 
12 public:
13 
16  clear();
17  }
18 
20  Interval(const epicsTime &start, const epicsTime &end)
21  : start(start), end(end) {
22  LOG_ASSERT(start <= end);
23  }
24 
26  const epicsTime &getStart() const
27  { return start; }
28 
30  const epicsTime &getEnd() const
31  { return end; }
32 
34  double width() const
35  { return end - start; }
36 
38  void clear()
39  {
40  start = nullTime;
41  end = nullTime;
42  }
43 
45  void setStart(const epicsTime &time)
46  { start = time; }
47 
49  void setEnd(const epicsTime &time)
50  { end = time; }
51 
53  void add(const Interval &other)
54  {
55  if (start > other.start)
56  start = other.start;
57  if (end < other.end)
58  end = other.end;
59  LOG_ASSERT(start <= end);
60  }
61 
63  bool isValid() const
64  {
65  return start != nullTime && end != nullTime;
66  }
67 
73  bool covers(const Interval &other) const
74  {
75  return start <= other.start && end >= other.end;
76  }
77 
79  bool operator == (const Interval &other) const
80  {
81  return start == other.start && end == other.end;
82  }
83 
85  bool operator != (const Interval &other) const
86  {
87  return start != other.start || end != other.end;
88  }
89 
95  bool overlaps(const Interval &other) const
96  {
97  // Same as this:
98  // return end > other.start && other.end > start;
99  if (end <= other.start || other.end <= start)
100  return false;
101  return true;
102  }
103 
105  stdString toString() const;
106 
107 private:
108  epicsTime start, end;
109 };
110 
111 #endif /*INTERVAL_H_*/
void setStart(const epicsTime &time)
Update start time of Interval.
Definition: Interval.h:45
void add(const Interval &other)
Union; Cause Interval to include the range of the other Interval.
Definition: Interval.h:53
const epicsTime & getStart() const
Definition: Interval.h:26
void clear()
Reset Interval to null start and end times.
Definition: Interval.h:38
Interval(const epicsTime &start, const epicsTime &end)
Construct Interval with given start..end.
Definition: Interval.h:20
stdString toString() const
Prints this interval to string.
bool operator==(const Interval &other) const
Definition: Interval.h:79
Interval()
Construct empty Interval.
Definition: Interval.h:15
A time interval.
Definition: Interval.h:10
void setEnd(const epicsTime &time)
Update end time of Interval.
Definition: Interval.h:49
bool isValid() const
Definition: Interval.h:63
double width() const
Definition: Interval.h:34
bool operator!=(const Interval &other) const
Definition: Interval.h:85
const epicsTime & getEnd() const
Definition: Interval.h:30
bool overlaps(const Interval &other) const
Check if this and other interval overlap.
Definition: Interval.h:95
bool covers(const Interval &other) const
Check if this interval &#39;covers&#39; another one, meaning this interval matches the other one...
Definition: Interval.h:73