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