| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef FW_TIME_HPP | ||
| 2 | #define FW_TIME_HPP | ||
| 3 | |||
| 4 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 5 | #include <Fw/Time/TimeComparisonEnumAc.hpp> | ||
| 6 | #include <Fw/Time/TimeValueSerializableAc.hpp> | ||
| 7 | #include <Fw/Types/Assert.hpp> | ||
| 8 | #include <Fw/Types/Serializable.hpp> | ||
| 9 | #include <config/TimeBaseEnumAc.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 |
1/1✓ Branch 2 taken 3435 times.
|
3434 | Time(const Time& other) : Serializable(), m_val(other.m_val) {} // !< 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 | |||
| 27 | //! \brief Constructor with floating-point (F64) seconds | ||
| 28 | //! \warning Negative value (seconds < 0) results in undefined behavior (assert fail in Debug) | ||
| 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 | |||
| 39 | //! \brief Sets value of time stored | ||
| 40 | //! \warning Negative value (seconds < 0) results in undefined behavior (assert fail in Debug) | ||
| 41 | void set(F64 seconds); | ||
| 42 | |||
| 43 | void setTimeBase(TimeBase timeBase); | ||
| 44 | void setTimeContext(FwTimeContextStoreType context); | ||
| 45 | U32 getSeconds() const; // !< Gets seconds part of time | ||
| 46 | U32 getUSeconds() const; // !< Gets microseconds part of time | ||
| 47 | TimeBase getTimeBase() | ||
| 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 | ||
| 50 | SerializeStatus serializeTo(SerialBufferBase& buffer, | ||
| 51 | Fw::Endianness mode = Fw::Endianness::BIG) const override; // !< Serialize method | ||
| 52 | SerializeStatus deserializeFrom(SerialBufferBase& buffer, | ||
| 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 | |||
| 62 | //! \brief Assign this Time from floating-point (F64) seconds | ||
| 63 | //! \warning Negative value (seconds < 0) results in undefined behavior (assert fail in Debug mode) | ||
| 64 | Time& operator=(F64 seconds); | ||
| 65 | |||
| 66 | //! \brief Add floating-point (F64) value to this Time | ||
| 67 | //! \warning Negative value (seconds < 0) results in undefined behavior (assert fail in Debug mode) | ||
| 68 | Time& operator+=(F64 seconds); | ||
| 69 | |||
| 70 | //! \brief Convert object to floating point (F64) representation | ||
| 71 | //! \return The floating point (F64) representation of this Time | ||
| 72 | operator F64() const; | ||
| 73 | |||
| 74 | //! \brief get the underlying TimeValue | ||
| 75 | //! \return the TimeValue representation of this Time as a copy | ||
| 76 | TimeValue asTimeValue() const; | ||
| 77 | |||
| 78 | // Static methods: | ||
| 79 | //! The type of a comparison result | ||
| 80 | |||
| 81 | //! \return time zero | ||
| 82 | static Time zero(TimeBase timeBase = TimeBase::TB_NONE); | ||
| 83 | |||
| 84 | //! Compare two times | ||
| 85 | //! \return The result | ||
| 86 | static TimeComparison compare(const Time& time1, //!< Time 1 | ||
| 87 | const Time& time2 //!< Time 2 | ||
| 88 | ); | ||
| 89 | |||
| 90 | //! Add two times | ||
| 91 | //! \return The result | ||
| 92 | static Time add(const Time& a, //!< Time a | ||
| 93 | const Time& b //!< Time b | ||
| 94 | ); | ||
| 95 | |||
| 96 | //! Subtract subtrahend from minuend | ||
| 97 | //! \return The result | ||
| 98 | static Time sub(const Time& minuend, //!< Value being subtracted from | ||
| 99 | const Time& subtrahend //!< Value being subtracted | ||
| 100 | ); | ||
| 101 | |||
| 102 | //! \brief Extract seconds from a floating-point (F64) | ||
| 103 | //! \warning Negative value (seconds < 0) results in undefined behavior (assert fail in Debug mode) | ||
| 104 | //! \return Seconds count as U32 | ||
| 105 | static U32 parseSeconds(F64 seconds); | ||
| 106 | |||
| 107 | //! \brief Extract microseconds from a floating-point (F64) | ||
| 108 | //! \warning Negative value (seconds < 0) results in undefined behavior (assert fail in Debug) | ||
| 109 | //! \return Microseconds count as U32 | ||
| 110 | static U32 parseUSeconds(F64 seconds); | ||
| 111 | |||
| 112 | // add seconds and microseconds to existing time | ||
| 113 | void add(U32 seconds, U32 mseconds); | ||
| 114 | |||
| 115 | //! \brief Add floating-point (F64) seconds to existing time | ||
| 116 | //! \warning Negative value (seconds < 0) results in undefined behavior (assert fail in Debug) | ||
| 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 | ||
| 130 |