F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
TimeInterval.hpp
Go to the documentation of this file.
1 #ifndef FW_TIME_INTERVAL_HPP
2 #define FW_TIME_INTERVAL_HPP
3 
5 #include <Fw/Time/Time.hpp>
7 #include <Fw/Types/Assert.hpp>
9 
18 namespace Fw {
19 
20 class TimeInterval : public Serializable {
21  public:
22  enum { SERIALIZED_SIZE = sizeof(U32) * 2 };
23 
24  TimeInterval() = default; // !< Default constructor
25  ~TimeInterval() = default; // !< Default destructor
26  TimeInterval(const TimeInterval& other); // !< Copy constructor
27  TimeInterval(U32 seconds, U32 useconds); // !< Constructor with member values as arguments
28  TimeInterval(const Time& start, const Time& end); // !< Constructor with start / end times as arguments
29  void set(U32 seconds, U32 useconds); // !< Sets value of time stored
30  U32 getSeconds() const; // !< Gets seconds part of time
31  U32 getUSeconds() const; // !< Gets microseconds part of time
32 
33  SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; // !< Serialize method
34  SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; // !< Deserialize method
35  void add(U32 seconds, U32 mseconds); // !< Add seconds and microseconds to existing time interval
36  bool operator==(const TimeInterval& other) const;
37  bool operator!=(const TimeInterval& other) const;
38  bool operator>(const TimeInterval& other) const;
39  bool operator<(const TimeInterval& other) const;
40  bool operator>=(const TimeInterval& other) const;
41  bool operator<=(const TimeInterval& other) const;
42  TimeInterval& operator=(const TimeInterval& other);
43 
45  typedef enum { LT = -1, EQ = 0, GT = 1, INCOMPARABLE = 2 } Comparison;
46 
51  static Comparison compare(const TimeInterval& time1,
52  const TimeInterval& time2
53  );
54 
58  static TimeInterval add(const TimeInterval& a,
59  const TimeInterval& b
60  );
61 
67  static TimeInterval sub(const TimeInterval& t1,
68  const TimeInterval& t2
69  );
70 
71 #ifdef BUILD_UT // Stream operators to support Googletest
72  friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val);
73 #endif
74  private:
75  TimeIntervalValue m_val; // !< TimeInterval value
76 };
77 
78 } // namespace Fw
79 
80 #endif
Data structure for Time Interval.
SerializeStatus deserializeFrom(SerializeBufferBase &buffer) override
deserialize contents from buffer
bool operator>=(const TimeInterval &other) const
~TimeInterval()=default
bool operator<(const TimeInterval &other) const
static Comparison compare(const TimeInterval &time1, const TimeInterval &time2)
bool operator!=(const TimeInterval &other) const
TimeInterval & operator=(const TimeInterval &other)
SerializeStatus
forward declaration for string
static TimeInterval sub(const TimeInterval &t1, const TimeInterval &t2)
bool operator<=(const TimeInterval &other) const
void add(U32 seconds, U32 mseconds)
bool operator>(const TimeInterval &other) const
SerializeStatus serializeTo(SerializeBufferBase &buffer) const override
serialize contents to buffer
bool operator==(const TimeInterval &other) const
U32 getUSeconds() const
TimeInterval()=default
Comparison
The type of a comparison result.
forward declaration
U32 getSeconds() const