F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Time.hpp
Go to the documentation of this file.
1 #ifndef FW_TIME_HPP
2 #define FW_TIME_HPP
3 
6 #include <Fw/Types/Assert.hpp>
9 
10 namespace Fw {
11 class Time : public Serializable {
12  friend class TimeTester;
13 
14  public:
15  enum { SERIALIZED_SIZE = sizeof(FwTimeBaseStoreType) + sizeof(FwTimeContextStoreType) + sizeof(U32) + sizeof(U32) };
16 
17  Time(); // !< Default constructor
18  Time(const Time& other); // !< Copy constructor
19  Time(U32 seconds, U32 useconds); // !< Constructor with member values as arguments
20  Time(TimeBase timeBase, U32 seconds, U32 useconds); // !< Constructor with member values as arguments
21  Time(TimeBase timeBase,
22  FwTimeContextStoreType context,
23  U32 seconds,
24  U32 useconds); // !< Constructor with member values as arguments
25  virtual ~Time(); // !< Destructor
26  void set(U32 seconds, U32 useconds); // !< Sets value of time stored
27  void set(TimeBase timeBase, U32 seconds, U32 useconds); // !< Sets value of time stored
28  void set(TimeBase timeBase,
29  FwTimeContextStoreType context,
30  U32 seconds,
31  U32 useconds); // !< Sets value of time stored
32  void setTimeBase(TimeBase timeBase);
34  U32 getSeconds() const; // !< Gets seconds part of time
35  U32 getUSeconds() const; // !< Gets microseconds part of time
37  const; // !< Time base of time. This is project specific and is meant for indicating different sources of time
38  FwTimeContextStoreType getContext() const; // !< get the context value
39  SerializeStatus serializeTo(SerializeBufferBase& buffer) const override; // !< Serialize method
40  SerializeStatus deserializeFrom(SerializeBufferBase& buffer) override; // !< Deserialize method
41  bool operator==(const Time& other) const;
42  bool operator!=(const Time& other) const;
43  bool operator>(const Time& other) const;
44  bool operator<(const Time& other) const;
45  bool operator>=(const Time& other) const;
46  bool operator<=(const Time& other) const;
47  Time& operator=(const Time& other);
48 
49  // Static methods:
51  typedef enum { LT = -1, EQ = 0, GT = 1, INCOMPARABLE = 2 } Comparison;
52 
54  static Time zero(TimeBase timeBase = TimeBase::TB_NONE);
55 
58  static Comparison compare(const Time& time1,
59  const Time& time2
60  );
61 
64  static Time add(const Time& a,
65  const Time& b
66  );
67 
70  static Time sub(const Time& minuend,
71  const Time& subtrahend
72  );
73 
74  // add seconds and microseconds to existing time
75  void add(U32 seconds, U32 mseconds);
76 
77 #ifdef BUILD_UT // Stream operators to support Googletest
78  friend std::ostream& operator<<(std::ostream& os, const Time& val);
79 #endif
80  private:
81  TimeValue m_val; // !< Time value
82 };
83 extern const Time ZERO_TIME;
84 
85 } // namespace Fw
86 
87 #endif
bool operator<=(const Time &other) const
Definition: Time.cpp:75
Time & operator=(const Time &other)
Definition: Time.cpp:47
const Time ZERO_TIME
Definition: Time.cpp:5
TimeBase getTimeBase() const
Definition: Time.cpp:96
No time base has been established (Required)
friend class TimeTester
Definition: Time.hpp:12
U8 FwTimeContextStoreType
The type used to serialize a time context value.
static Time sub(const Time &minuend, const Time &subtrahend)
Definition: Time.cpp:157
Comparison
The type of a comparison result.
Definition: Time.hpp:51
bool operator==(const Time &other) const
Definition: Time.cpp:54
SerializeStatus
forward declaration for string
static Time zero(TimeBase timeBase=TimeBase::TB_NONE)
Definition: Time.cpp:104
bool operator!=(const Time &other) const
Definition: Time.cpp:58
void setTimeContext(FwTimeContextStoreType context)
Definition: Time.cpp:199
bool operator>(const Time &other) const
Definition: Time.cpp:62
bool operator>=(const Time &other) const
Definition: Time.cpp:70
U32 getSeconds() const
Definition: Time.cpp:88
void setTimeBase(TimeBase timeBase)
Definition: Time.cpp:195
Data structure for Time.
static Time add(const Time &a, const Time &b)
Definition: Time.cpp:134
FwTimeContextStoreType getContext() const
Definition: Time.cpp:100
U32 getUSeconds() const
Definition: Time.cpp:92
SerializeStatus deserializeFrom(SerializeBufferBase &buffer) override
deserialize contents from buffer
Definition: Time.cpp:84
SerializeStatus serializeTo(SerializeBufferBase &buffer) const override
serialize contents to buffer
Definition: Time.cpp:80
Time()
Definition: Time.cpp:7
static Comparison compare(const Time &time1, const Time &time2)
Definition: Time.cpp:109
forward declaration
U16 FwTimeBaseStoreType
The type used to serialize a time base value.
virtual ~Time()
Definition: Time.cpp:14
bool operator<(const Time &other) const
Definition: Time.cpp:66
Define enumeration for Time base types.