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 
6 #include <Fw/Types/Assert.hpp>
8 
17 namespace Fw {
18 
19 class TimeInterval : public Serializable {
20  public:
21  enum { SERIALIZED_SIZE = sizeof(U32) * 2 };
22 
23  TimeInterval() = default; // !< Default constructor
24  ~TimeInterval() = default; // !< Default destructor
25  TimeInterval(const TimeInterval& other); // !< Copy constructor
26  TimeInterval(U32 seconds, U32 useconds); // !< Constructor with member values as arguments
27  void set(U32 seconds, U32 useconds); // !< Sets value of time stored
28  U32 getSeconds() const; // !< Gets seconds part of time
29  U32 getUSeconds() const; // !< Gets microseconds part of time
30 
31  SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; // !< Serialize method
32  SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; // !< Deserialize method
33  void add(U32 seconds, U32 mseconds); // !< Add seconds and microseconds to existing time interval
34  bool operator==(const TimeInterval& other) const;
35  bool operator!=(const TimeInterval& other) const;
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  TimeInterval& operator=(const TimeInterval& other);
41 
43  typedef enum { LT = -1, EQ = 0, GT = 1, INCOMPARABLE = 2 } Comparison;
44 
49  static Comparison compare(const TimeInterval& time1,
50  const TimeInterval& time2
51  );
52 
56  static TimeInterval add(const TimeInterval& a,
57  const TimeInterval& b
58  );
59 
65  static TimeInterval sub(const TimeInterval& t1,
66  const TimeInterval& t2
67  );
68 
69 #ifdef BUILD_UT // Stream operators to support Googletest
70  friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val);
71 #endif
72  private:
73  TimeIntervalValue m_val; // !< TimeInterval value
74 };
75 
76 } // namespace Fw
77 
78 #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