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 
5 #include <Fw/Types/Assert.hpp>
7 
8 namespace Fw {
9  class Time: public Serializable {
10 
11  friend class TimeTester;
12 
13  public:
14 
15  enum {
17  + sizeof(FwTimeContextStoreType)
18  + sizeof(U32) + sizeof(U32)
19  };
20 
21  Time(); // !< Default constructor
22  Time(const Time& other); // !< Copy constructor
23  Time(U32 seconds, U32 useconds); // !< Constructor with member values as arguments
24  Time(TimeBase timeBase, U32 seconds, U32 useconds); // !< Constructor with member values as arguments
25  Time(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds); // !< Constructor with member values as arguments
26  virtual ~Time(); // !< Destructor
27  void set(U32 seconds, U32 useconds); // !< Sets value of time stored
28  void set(TimeBase timeBase, U32 seconds, U32 useconds); // !< Sets value of time stored
29  void set(TimeBase timeBase, FwTimeContextStoreType context, U32 seconds, U32 useconds); // !< Sets value of time stored
30  void setTimeBase(TimeBase timeBase);
32  U32 getSeconds() const; // !< Gets seconds part of time
33  U32 getUSeconds() const; // !< Gets microseconds part of time
34  TimeBase getTimeBase() const; // !< Time base of time. This is project specific and is meant for indicating different sources of time
35  FwTimeContextStoreType getContext() const; // !< get the context value
36  SerializeStatus serialize(SerializeBufferBase& buffer) const; // !< Serialize method
37  SerializeStatus deserialize(SerializeBufferBase& buffer); // !< Deserialize method
38  bool operator==(const Time& other) const;
39  bool operator!=(const Time& other) const;
40  bool operator>(const Time& other) const;
41  bool operator<(const Time& other) const;
42  bool operator>=(const Time& other) const;
43  bool operator<=(const Time& other) const;
44  Time& operator=(const Time& other);
45 
46  // Static methods:
48  typedef enum {
49  LT = -1,
50  EQ = 0,
51  GT = 1,
53  } Comparison;
54 
56  static Time zero(TimeBase timeBase=TB_NONE);
57 
60  static Comparison compare(
61  const Time &time1,
62  const Time &time2
63  );
64 
67  static Time add(
68  const Time& a,
69  const Time& b
70  );
71 
74  static Time sub(
75  const Time& minuend,
76  const Time& subtrahend
77  );
78 
79  // add seconds and microseconds to existing time
80  void add(U32 seconds, U32 mseconds);
81 
82 #ifdef BUILD_UT // Stream operators to support Googletest
83  friend std::ostream& operator<<(std::ostream& os, const Time& val);
84 #endif
85  private:
86  U32 m_seconds; // !< seconds portion
87  U32 m_useconds; // !< microseconds portion
88  TimeBase m_timeBase; // !< basis of time (defined by system)
89  FwTimeContextStoreType m_timeContext; // !< user settable value. Could be reboot count, node, etc
90  };
91  extern const Time ZERO_TIME;
92 
93 }
94 
95 #endif
bool operator<=(const Time &other) const
Definition: Time.cpp:74
Definition: Time.hpp:9
Time & operator=(const Time &other)
Definition: Time.cpp:44
const Time ZERO_TIME
Definition: Time.cpp:5
TimeBase getTimeBase() const
Definition: Time.cpp:143
friend class TimeTester
Definition: Time.hpp:11
U8 FwTimeContextStoreType
The type used to serialize a time context value.
static Time sub(const Time &minuend, const Time &subtrahend)
Definition: Time.cpp:216
Comparison
The type of a comparison result.
Definition: Time.hpp:48
bool operator==(const Time &other) const
Definition: Time.cpp:53
SerializeStatus
forward declaration for string
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialize contents
Definition: Time.cpp:79
bool operator!=(const Time &other) const
Definition: Time.cpp:57
void setTimeContext(FwTimeContextStoreType context)
Definition: Time.cpp:255
TimeBase
Definition: FpConfig.h:29
bool operator>(const Time &other) const
Definition: Time.cpp:61
bool operator>=(const Time &other) const
Definition: Time.cpp:69
U32 getSeconds() const
Definition: Time.cpp:135
void setTimeBase(TimeBase timeBase)
Definition: Time.cpp:251
static Time add(const Time &a, const Time &b)
Definition: Time.cpp:193
FwTimeContextStoreType getContext() const
Definition: Time.cpp:147
U32 getUSeconds() const
Definition: Time.cpp:139
No time base has been established.
Definition: FpConfig.h:30
Time()
Definition: Time.cpp:7
static Comparison compare(const Time &time1, const Time &time2)
Definition: Time.cpp:159
forward declaration
static Time zero(TimeBase timeBase=TB_NONE)
Definition: Time.cpp:152
U16 FwTimeBaseStoreType
The type used to serialize a time base value.
SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialize to contents
Definition: Time.cpp:104
virtual ~Time()
Definition: Time.cpp:10
bool operator<(const Time &other) const
Definition: Time.cpp:65