LCOV - code coverage report
Current view: top level - DCPS - TimeDuration.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2023-04-30 01:32:43 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #ifndef OPENDDS_DCPS_TIMEDURATION_H
       2             : #define OPENDDS_DCPS_TIMEDURATION_H
       3             : 
       4             : #include "PoolAllocator.h"
       5             : #include "SafeBool_T.h"
       6             : 
       7             : #include <dds/DdsDcpsCoreC.h>
       8             : 
       9             : #include <ace/Time_Value.h>
      10             : 
      11             : #ifndef ACE_LACKS_PRAGMA_ONCE
      12             : #  pragma once
      13             : #endif
      14             : 
      15             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      16             : 
      17             : namespace OpenDDS {
      18             : namespace DCPS {
      19             : 
      20             : /**
      21             :  * Represents a length of time and based on C++11 std::chrono::duration.
      22             :  *
      23             :  * This wraps an ACE_Time_Value, and is designed to work with TimePoint_T.
      24             :  *
      25             :  * See https://opendds.readthedocs.io/en/master/internal/dev_guidelines.html#time
      26             :  * (or docs/internal/dev_guidelines.rst) for background and reasoning for this
      27             :  * class.
      28             :  */
      29             : class OpenDDS_Dcps_Export TimeDuration : public SafeBool_T<TimeDuration> {
      30             : public:
      31             :   const static TimeDuration zero_value;
      32             :   const static TimeDuration max_value;
      33             : 
      34             :   /**
      35             :    * Return a TimeDuration equivalent to the given number of milliseconds.
      36             :    */
      37             :   static TimeDuration from_msec(const ACE_UINT64& ms);
      38             : 
      39             :   /**
      40             :    * Return a TimeDuration from fractional seconds.
      41             :    */
      42             :   static TimeDuration from_double(double duration);
      43             : 
      44             :   /**
      45             :    * Initialized to zero
      46             :    */
      47             :   TimeDuration();
      48             : 
      49             :   TimeDuration(const TimeDuration& other);
      50             : 
      51             :   /**
      52             :    * Copy the ACE_Time_Value directly.
      53             :    *
      54             :    * \warning It will accept a ACE_Time_Value that represents a specific point
      55             :    * in time, but it is wrong to do so. Use one of the TimePoint_T classes
      56             :    * defined in TimeTypes.h that match the clock type.
      57             :    */
      58             :   explicit TimeDuration(const ACE_Time_Value& ace_time_value);
      59             : 
      60             :   /**
      61             :    * Define the number of seconds and optionally microseconds, passed to
      62             :    * ACE_Time_Value's constructor of the same signature.
      63             :    */
      64             :   explicit TimeDuration(time_t sec, suseconds_t usec = 0);
      65             : 
      66             :   /**
      67             :    * Converts the DDS Duration into the equivalent value.
      68             :    */
      69             :   explicit TimeDuration(const DDS::Duration_t& dds_duration);
      70             : 
      71             :   const ACE_Time_Value& value() const;
      72             :   void value(const ACE_Time_Value& ace_time_value);
      73             :   bool is_zero() const;
      74             :   bool is_max() const;
      75             :   DDS::Duration_t to_dds_duration() const;
      76             : 
      77             :   bool boolean_test() const
      78             :   {
      79             :     return value_ != zero_value.value();
      80             :   }
      81             : 
      82             :   /**
      83             :    * Convert to a string in a humanized format:
      84             :    *    SECONDS.FRACTIONAL s
      85             :    * if the time is less than a minute or just_sec is true, else:
      86             :    *    [[HOURS:]MINUTES:]SECONDS.FRACTIONAL
      87             :    *
      88             :    * decimal_places is the number of decimal places to round to in the
      89             :    * fractional seconds.
      90             :    */
      91             :   String str(unsigned decimal_places = 3, bool just_sec = false) const;
      92             : 
      93           1 :   String sec_str(unsigned decimal_places = 3) const
      94             :   {
      95           1 :     return str(decimal_places, true);
      96             :   }
      97             : 
      98             :   TimeDuration& operator+=(const TimeDuration& other);
      99             :   TimeDuration& operator-=(const TimeDuration& other);
     100             :   TimeDuration& operator=(const TimeDuration& other);
     101             :   TimeDuration& operator=(const time_t& other);
     102             :   TimeDuration& operator*=(double other);
     103             :   TimeDuration& operator/=(double other);
     104             : 
     105             : protected:
     106             :   ACE_Time_Value value_;
     107             : };
     108             : 
     109             : OpenDDS_Dcps_Export TimeDuration operator+(const TimeDuration& x, const TimeDuration& y);
     110             : OpenDDS_Dcps_Export TimeDuration operator-(const TimeDuration& x, const TimeDuration& y);
     111             : OpenDDS_Dcps_Export TimeDuration operator-(const TimeDuration& x);
     112             : OpenDDS_Dcps_Export TimeDuration operator*(double x, const TimeDuration& y);
     113             : OpenDDS_Dcps_Export TimeDuration operator*(const TimeDuration& x, double y);
     114             : OpenDDS_Dcps_Export TimeDuration operator/(const TimeDuration& x, double y);
     115             : OpenDDS_Dcps_Export double operator/(const TimeDuration& x, const TimeDuration& y);
     116             : OpenDDS_Dcps_Export bool operator<(const TimeDuration& x, const TimeDuration& y);
     117             : OpenDDS_Dcps_Export bool operator>(const TimeDuration& x, const TimeDuration& y);
     118             : OpenDDS_Dcps_Export bool operator<=(const TimeDuration& x, const TimeDuration& y);
     119             : OpenDDS_Dcps_Export bool operator>=(const TimeDuration& x, const TimeDuration& y);
     120             : OpenDDS_Dcps_Export bool operator==(const TimeDuration& x, const TimeDuration& y);
     121             : OpenDDS_Dcps_Export bool operator!=(const TimeDuration& x, const TimeDuration& y);
     122             : 
     123             : } // namespace DCPS
     124             : } // namespace OpenDDS
     125             : 
     126             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     127             : 
     128             : #ifdef __ACE_INLINE__
     129             : #  include "TimeDuration.inl"
     130             : #endif
     131             : 
     132             : #endif

Generated by: LCOV version 1.16