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 
34  Fw::Endianness mode = Fw::Endianness::BIG) const override; // !< Serialize method
36  Fw::Endianness mode = Fw::Endianness::BIG) override; // !< Deserialize method
37  void add(U32 seconds, U32 mseconds); // !< Add seconds and microseconds to existing time interval
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  bool operator>=(const TimeInterval& other) const;
43  bool operator<=(const TimeInterval& other) const;
44  TimeInterval& operator=(const TimeInterval& other);
45 
47  typedef enum { LT = -1, EQ = 0, GT = 1, INCOMPARABLE = 2 } Comparison;
48 
53  static Comparison compare(const TimeInterval& time1,
54  const TimeInterval& time2
55  );
56 
60  static TimeInterval add(const TimeInterval& a,
61  const TimeInterval& b
62  );
63 
69  static TimeInterval sub(const TimeInterval& t1,
70  const TimeInterval& t2
71  );
72 
73 #ifdef BUILD_UT // Stream operators to support Googletest
74  friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val);
75 #endif
76  private:
77  TimeIntervalValue m_val; // !< TimeInterval value
78 };
79 
80 } // namespace Fw
81 
82 #endif
SerializeStatus serializeTo(SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) const override
Serialize the contents of this object to a buffer.
Data structure for Time Interval.
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 deserializeFrom(SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) override
Deserialize the contents of this object from a buffer.
bool operator==(const TimeInterval &other) const
U32 getUSeconds() const
TimeInterval()=default
Comparison
The type of a comparison result.
Implementation of malloc based allocator.
Endianness
Big endian serialization.
U32 getSeconds() const