F´ Flight Software - C/C++ Documentation  devel
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 
4 #include <FpConfig.hpp>
5 #include <Fw/Types/Assert.hpp>
7 
16 namespace Fw {
17 
18  class TimeInterval: public Serializable {
19  public:
20 
21  enum {
22  SERIALIZED_SIZE = sizeof(U32) * 2
23  };
24 
25  TimeInterval() = default; // !< Default constructor
26  ~TimeInterval() = default; // !< Default destructor
27  TimeInterval(const TimeInterval& other); // !< Copy constructor
28  TimeInterval(U32 seconds, U32 useconds); // !< Constructor with member values 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  SerializeStatus serialize(SerializeBufferBase& buffer) const; // !< Serialize method
33  SerializeStatus deserialize(SerializeBufferBase& buffer); // !< Deserialize method
34  void add(U32 seconds, U32 mseconds); // !< Add seconds and microseconds to existing time interval
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  bool operator<=(const TimeInterval& other) const;
41  TimeInterval& operator=(const TimeInterval& other);
42 
44  typedef enum {
45  LT = -1,
46  EQ = 0,
47  GT = 1,
48  INCOMPARABLE = 2
50 
55  static Comparison compare(
56  const TimeInterval &time1,
57  const TimeInterval &time2
58  );
59 
63  static TimeInterval add(
64  const TimeInterval& a,
65  const TimeInterval& b
66  );
67 
73  static TimeInterval sub(
74  const TimeInterval& t1,
75  const TimeInterval& t2
76  );
77 
78 
79 
80 #ifdef BUILD_UT // Stream operators to support Googletest
81  friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val);
82 #endif
83  PRIVATE:
84  U32 m_seconds; // !< seconds portion of TimeInterval
85  U32 m_useconds; // !< microseconds portion of TimeInterval
86  };
87 
88 }
89 
90 #endif
C++-compatible configuration header for fprime configuration.
forward declaration
TimeInterval()=default
void add(U32 seconds, U32 mseconds)
TimeInterval & operator=(const TimeInterval &other)
static Comparison compare(const TimeInterval &time1, const TimeInterval &time2)
bool operator!=(const TimeInterval &other) const
bool operator<(const TimeInterval &other) const
U32 getSeconds() const
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialize contents
static TimeInterval sub(const TimeInterval &t1, const TimeInterval &t2)
bool operator>=(const TimeInterval &other) const
Comparison
The type of a comparison result.
bool operator==(const TimeInterval &other) const
~TimeInterval()=default
bool operator<=(const TimeInterval &other) const
SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialize to contents
void set(U32 seconds, U32 useconds)
bool operator>(const TimeInterval &other) const
U32 getUSeconds() const
SerializeStatus
forward declaration for string