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 
7 #include <Fw/Types/Assert.hpp>
10 
11 namespace Fw {
12 class Time : public Serializable {
13  friend class TimeTester;
14 
15  public:
16  enum { SERIALIZED_SIZE = sizeof(FwTimeBaseStoreType) + sizeof(FwTimeContextStoreType) + sizeof(U32) + sizeof(U32) };
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,
23  FwTimeContextStoreType context,
24  U32 seconds,
25  U32 useconds); // !< Constructor with member values as arguments
26 
29  explicit Time(F64 seconds);
30 
31  virtual ~Time(); // !< Destructor
32  void set(U32 seconds, U32 useconds); // !< Sets value of time stored
33  void set(TimeBase timeBase, U32 seconds, U32 useconds); // !< Sets value of time stored
34  void set(TimeBase timeBase,
35  FwTimeContextStoreType context,
36  U32 seconds,
37  U32 useconds); // !< Sets value of time stored
38 
41  void set(F64 seconds);
42 
43  void setTimeBase(TimeBase timeBase);
45  U32 getSeconds() const; // !< Gets seconds part of time
46  U32 getUSeconds() const; // !< Gets microseconds part of time
48  const; // !< Time base of time. This is project specific and is meant for indicating different sources of time
49  FwTimeContextStoreType getContext() const; // !< get the context value
51  Fw::Endianness mode = Fw::Endianness::BIG) const override; // !< Serialize method
53  Fw::Endianness mode = Fw::Endianness::BIG) override; // !< Deserialize method
54  bool operator==(const Time& other) const;
55  bool operator!=(const Time& other) const;
56  bool operator>(const Time& other) const;
57  bool operator<(const Time& other) const;
58  bool operator>=(const Time& other) const;
59  bool operator<=(const Time& other) const;
60  Time& operator=(const Time& other);
61 
64  Time& operator=(F64 seconds);
65 
68  Time& operator+=(F64 seconds);
69 
72  operator F64() const;
73 
76  TimeValue asTimeValue() const;
77 
78  // Static methods:
80 
82  static Time zero(TimeBase timeBase = TimeBase::TB_NONE);
83 
86  static TimeComparison compare(const Time& time1,
87  const Time& time2
88  );
89 
92  static Time add(const Time& a,
93  const Time& b
94  );
95 
98  static Time sub(const Time& minuend,
99  const Time& subtrahend
100  );
101 
105  static U32 parseSeconds(F64 seconds);
106 
110  static U32 parseUSeconds(F64 seconds);
111 
112  // add seconds and microseconds to existing time
113  void add(U32 seconds, U32 mseconds);
114 
117  void add(F64 seconds);
118 
119 #ifdef BUILD_UT // Stream operators to support Googletest
120  friend std::ostream& operator<<(std::ostream& os, const Time& val);
121 #endif
122  private:
123  TimeValue m_val; // !< Time value
124 };
125 extern const Time ZERO_TIME;
126 
127 } // namespace Fw
128 
129 #endif
bool operator<=(const Time &other) const
Definition: Time.cpp:95
Time & operator=(const Time &other)
Definition: Time.cpp:57
TimeValue asTimeValue() const
get the underlying TimeValue
Definition: Time.cpp:106
const Time ZERO_TIME
Definition: Time.cpp:5
TimeBase getTimeBase() const
Definition: Time.cpp:126
No time base has been established (Required)
friend class TimeTester
Definition: Time.hpp:13
U8 FwTimeContextStoreType
The type used to serialize a time context value.
static Time sub(const Time &minuend, const Time &subtrahend)
Definition: Time.cpp:187
bool operator==(const Time &other) const
Definition: Time.cpp:74
SerializeStatus
forward declaration for string
static Time zero(TimeBase timeBase=TimeBase::TB_NONE)
The type of a comparison result.
Definition: Time.cpp:134
bool operator!=(const Time &other) const
Definition: Time.cpp:78
void setTimeContext(FwTimeContextStoreType context)
Definition: Time.cpp:252
static U32 parseUSeconds(F64 seconds)
Extract microseconds from a floating-point (F64)
Definition: Time.cpp:220
Time & operator+=(F64 seconds)
Add floating-point (F64) value to this Time.
Definition: Time.cpp:69
bool operator>(const Time &other) const
Definition: Time.cpp:82
bool operator>=(const Time &other) const
Definition: Time.cpp:90
static U32 parseSeconds(F64 seconds)
Extract seconds from a floating-point (F64)
Definition: Time.cpp:214
U32 getSeconds() const
Definition: Time.cpp:118
void setTimeBase(TimeBase timeBase)
Definition: Time.cpp:248
Data structure for Time.
static TimeComparison compare(const Time &time1, const Time &time2)
Definition: Time.cpp:139
static Time add(const Time &a, const Time &b)
Definition: Time.cpp:164
FwTimeContextStoreType getContext() const
Definition: Time.cpp:130
U32 getUSeconds() const
Definition: Time.cpp:122
Time()
Definition: Time.cpp:7
double F64
64-bit floating point (double). Required for compiler-supplied double promotion.
Definition: BasicTypes.h:85
SerializeStatus serializeTo(SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) const override
Serialize the contents of this object to a buffer.
Definition: Time.cpp:110
U16 FwTimeBaseStoreType
The type used to serialize a time base value.
Implementation of malloc based allocator.
Endianness
virtual ~Time()
Definition: Time.cpp:14
bool operator<(const Time &other) const
Definition: Time.cpp:86
Define enumeration for Time base types.
SerializeStatus deserializeFrom(SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) override
Deserialize the contents of this object from a buffer.
Definition: Time.cpp:114
Big endian serialization.