| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef FW_TIME_INTERVAL_HPP | ||
| 2 | #define FW_TIME_INTERVAL_HPP | ||
| 3 | |||
| 4 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 5 | #include <Fw/Time/Time.hpp> | ||
| 6 | #include <Fw/Time/TimeIntervalValueSerializableAc.hpp> | ||
| 7 | #include <Fw/Types/Assert.hpp> | ||
| 8 | #include <Fw/Types/Serializable.hpp> | ||
| 9 | |||
| 10 | //! | ||
| 11 | //! @class TimeInterval | ||
| 12 | //! @brief A class to represent a time interval holding two U32 seconds and microseconds values. | ||
| 13 | //! | ||
| 14 | //! The TimeInterval class is designed to hold a time interval and provides various methods | ||
| 15 | //! to manipulate and compare time intervals. It supports serialization and deserialization | ||
| 16 | //! for easy storage and transmission. | ||
| 17 | //! | ||
| 18 | namespace Fw { | ||
| 19 | |||
| 20 | class TimeInterval : public Serializable { | ||
| 21 | public: | ||
| 22 | enum { SERIALIZED_SIZE = sizeof(U32) * 2 }; | ||
| 23 | |||
| 24 |
1/1✓ Branch 2 taken 412 times.
|
412 | TimeInterval() = default; // !< Default constructor |
| 25 | 850 | ~TimeInterval() = default; // !< Default destructor | |
| 26 | TimeInterval(const TimeInterval& other); // !< Copy constructor | ||
| 27 | TimeInterval(U32 seconds, U32 useconds); // !< Constructor with member values as arguments | ||
| 28 | TimeInterval(const Time& start, const Time& end); // !< Constructor with start / end times as arguments | ||
| 29 | void set(U32 seconds, U32 useconds); // !< Sets value of time stored | ||
| 30 | U32 getSeconds() const; // !< Gets seconds part of time | ||
| 31 | U32 getUSeconds() const; // !< Gets microseconds part of time | ||
| 32 | |||
| 33 | SerializeStatus serializeTo(SerialBufferBase& buffer, | ||
| 34 | Fw::Endianness mode = Fw::Endianness::BIG) const override; // !< Serialize method | ||
| 35 | SerializeStatus deserializeFrom(SerialBufferBase& buffer, | ||
| 36 | Fw::Endianness mode = Fw::Endianness::BIG) override; // !< Deserialize method | ||
| 37 | void add(U32 seconds, U32 mseconds); // !< Add seconds and microseconds to existing time interval | ||
| 38 | bool operator==(const TimeInterval& other) const; | ||
| 39 | bool operator!=(const TimeInterval& other) const; | ||
| 40 | bool operator>(const TimeInterval& other) const; | ||
| 41 | bool operator<(const TimeInterval& other) const; | ||
| 42 | bool operator>=(const TimeInterval& other) const; | ||
| 43 | bool operator<=(const TimeInterval& other) const; | ||
| 44 | TimeInterval& operator=(const TimeInterval& other); | ||
| 45 | |||
| 46 | //! \brief get the underlying TimeIntervalValue | ||
| 47 | //! \return the TimeIntervalValue representation of this TimeInterval as a copy | ||
| 48 | TimeIntervalValue asTimeIntervalValue() const; | ||
| 49 | |||
| 50 | //! The type of a comparison result | ||
| 51 | typedef enum { LT = -1, EQ = 0, GT = 1, INCOMPARABLE = 2 } Comparison; | ||
| 52 | |||
| 53 | //! Compare two time intervals | ||
| 54 | //! A time interval is considered greater than another if it spans a longer duration | ||
| 55 | //! The comparison is done on the seconds first, then the microseconds if the seconds are equal | ||
| 56 | //! \return TimeInterval result | ||
| 57 | static Comparison compare(const TimeInterval& time1, //!< TimeInterval 1 | ||
| 58 | const TimeInterval& time2 //!< TimeInterval 2 | ||
| 59 | ); | ||
| 60 | |||
| 61 | //! Add two time intervals | ||
| 62 | //! Adds the seconds and microseconds fields of two time intervals together | ||
| 63 | //! \return TimeInterval result | ||
| 64 | static TimeInterval add(const TimeInterval& a, //!< TimeInterval a | ||
| 65 | const TimeInterval& b //!< TimeInterval b | ||
| 66 | ); | ||
| 67 | |||
| 68 | //! Subtract two time intervals | ||
| 69 | //! This computes the absolute value of the difference between two time intervals | ||
| 70 | //! For example if t1=(0s, 5us) and t2=(0s, 3us), the result is (0s, 2us). | ||
| 71 | //! This operation is commutative, i.e. the result is the same regardless of the order of the arguments. | ||
| 72 | //! \return TimeInterval result | ||
| 73 | static TimeInterval sub(const TimeInterval& t1, //!< TimeInterval 1 | ||
| 74 | const TimeInterval& t2 //!< TimeInterval 2 | ||
| 75 | ); | ||
| 76 | |||
| 77 | #ifdef BUILD_UT // Stream operators to support Googletest | ||
| 78 | friend std::ostream& operator<<(std::ostream& os, const TimeInterval& val); | ||
| 79 | #endif | ||
| 80 | private: | ||
| 81 | TimeIntervalValue m_val; // !< TimeInterval value | ||
| 82 | }; | ||
| 83 | |||
| 84 | } // namespace Fw | ||
| 85 | |||
| 86 | #endif | ||
| 87 |