interval.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_INTERVAL_HPP
24 #define NDN_INTERVAL_HPP
25 
26 #include <exception>
27 #include "../common.hpp"
28 
29 namespace ndn {
30 
36 class Interval {
37 public:
41  class Error : public std::exception {
42  public:
43  Error(const std::string& errorMessage) throw();
44 
45  virtual ~Error() throw();
46 
47  std::string
48  Msg() const { return errorMessage_; }
49 
50  virtual const char*
51  what() const throw();
52 
53  private:
54  const std::string errorMessage_;
55  };
56 
62  Interval(bool isValid = false);
63 
64 
73 
78  void
79  set(const Interval& interval)
80  {
81  startTime_ = interval.startTime_;
82  endTime_ = interval.endTime_;
83  isValid_ = interval.isValid_;
84  }
85 
91  bool
92  covers(MillisecondsSince1970 timePoint) const;
93 
100  Interval&
101  intersectWith(const Interval& interval);
102 
112  Interval&
113  unionWith(const Interval& interval);
114 
120  getStartTime() const;
121 
127  getEndTime() const;
128 
133  bool
134  isValid() const { return isValid_; }
135 
141  bool
142  isEmpty() const;
143 
144 private:
145  MillisecondsSince1970 startTime_;
146  MillisecondsSince1970 endTime_;
147  bool isValid_;
148 };
149 
150 }
151 
152 #endif
An Interval defines a time duration which contains a start timestamp and an end timestamp.
Definition: interval.hpp:36
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
Interval.Error extends std::exception for errors using Interval methods.
Definition: interval.hpp:41
bool covers(MillisecondsSince1970 timePoint) const
Check if the time point is in this interval.
Definition: interval.cpp:59
bool isEmpty() const
Check if this Interval is empty.
Definition: interval.cpp:152
Interval & unionWith(const Interval &interval)
Set this Interval to the union of this and the other interval.
Definition: interval.cpp:102
bool isValid() const
Check if this Interval is valid.
Definition: interval.hpp:134
Interval & intersectWith(const Interval &interval)
Set this Interval to the intersection of this and the other interval.
Definition: interval.cpp:71
MillisecondsSince1970 getStartTime() const
Get the start time.
Definition: interval.cpp:136
Interval(bool isValid=false)
Create an Interval with the given validity value.
Definition: interval.cpp:41
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:117
MillisecondsSince1970 getEndTime() const
Get the end time.
Definition: interval.cpp:144
void set(const Interval &interval)
Set this interval to have the same values as the other interval.
Definition: interval.hpp:79