OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
OpenDDS::DCPS::TimeDuration Class Reference

#include <TimeDuration.h>

Inheritance diagram for OpenDDS::DCPS::TimeDuration:
Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::TimeDuration:
Collaboration graph
[legend]

Public Member Functions

 TimeDuration ()
 
 TimeDuration (const TimeDuration &other)
 
 TimeDuration (const ACE_Time_Value &ace_time_value)
 
 TimeDuration (time_t sec, suseconds_t usec=0)
 
 TimeDuration (const DDS::Duration_t &dds_duration)
 
const ACE_Time_Valuevalue () const
 
void value (const ACE_Time_Value &ace_time_value)
 
bool is_zero () const
 
bool is_max () const
 
DDS::Duration_t to_dds_duration () const
 
bool boolean_test () const
 
String str (unsigned decimal_places=3, bool just_sec=false) const
 
String sec_str (unsigned decimal_places=3) const
 
TimeDurationoperator+= (const TimeDuration &other)
 
TimeDurationoperator-= (const TimeDuration &other)
 
TimeDurationoperator= (const TimeDuration &other)
 
TimeDurationoperator= (const time_t &other)
 
TimeDurationoperator*= (double other)
 
TimeDurationoperator/= (double other)
 
- Public Member Functions inherited from OpenDDS::DCPS::SafeBool_T< TimeDuration >
 operator BoolType () const
 
- Public Member Functions inherited from OpenDDS::DCPS::SafeBoolBase
void this_type_does_not_support_comparisons () const
 

Static Public Member Functions

static TimeDuration from_msec (const ACE_UINT64 &ms)
 
static TimeDuration from_double (double duration)
 

Static Public Attributes

static const TimeDuration zero_value
 
static const TimeDuration max_value
 

Protected Attributes

ACE_Time_Value value_
 

Additional Inherited Members

- Public Types inherited from OpenDDS::DCPS::SafeBoolBase
typedef void(SafeBoolBase::* BoolType) () const
 
- Protected Member Functions inherited from OpenDDS::DCPS::SafeBool_T< TimeDuration >
 ~SafeBool_T ()
 
- Protected Member Functions inherited from OpenDDS::DCPS::SafeBoolBase
 SafeBoolBase ()
 
 SafeBoolBase (const SafeBoolBase &)
 
SafeBoolBaseoperator= (const SafeBoolBase &)
 
 ~SafeBoolBase ()
 

Detailed Description

Represents a length of time and based on C++11 std::chrono::duration.

This wraps an ACE_Time_Value, and is designed to work with TimePoint_T.

See https://opendds.readthedocs.io/en/master/internal/dev_guidelines.html#time (or docs/internal/dev_guidelines.rst) for background and reasoning for this class.

Definition at line 29 of file TimeDuration.h.

Constructor & Destructor Documentation

◆ TimeDuration() [1/5]

ACE_INLINE OpenDDS::DCPS::TimeDuration::TimeDuration ( )

◆ TimeDuration() [2/5]

ACE_INLINE OpenDDS::DCPS::TimeDuration::TimeDuration ( const TimeDuration other)

Definition at line 35 of file TimeDuration.inl.

References ACE_INLINE.

36 : value_(other.value_)
37 {
38 }

◆ TimeDuration() [3/5]

ACE_INLINE OpenDDS::DCPS::TimeDuration::TimeDuration ( const ACE_Time_Value ace_time_value)
explicit

Copy the ACE_Time_Value directly.

Warning
It will accept a ACE_Time_Value that represents a specific point in time, but it is wrong to do so. Use one of the TimePoint_T classes defined in TimeTypes.h that match the clock type.

Definition at line 41 of file TimeDuration.inl.

References ACE_INLINE.

42 : value_(ace_time_value)
43 {
44 }

◆ TimeDuration() [4/5]

ACE_INLINE OpenDDS::DCPS::TimeDuration::TimeDuration ( time_t  sec,
suseconds_t  usec = 0 
)
explicit

Define the number of seconds and optionally microseconds, passed to ACE_Time_Value's constructor of the same signature.

Definition at line 47 of file TimeDuration.inl.

References ACE_INLINE.

48 : value_(sec, usec)
49 {
50 }

◆ TimeDuration() [5/5]

ACE_INLINE OpenDDS::DCPS::TimeDuration::TimeDuration ( const DDS::Duration_t dds_duration)
explicit

Converts the DDS Duration into the equivalent value.

Definition at line 53 of file TimeDuration.inl.

References ACE_INLINE.

54 : value_(duration_to_time_value(dds_duration))
55 {
56 }
ACE_INLINE OpenDDS_Dcps_Export ACE_Time_Value duration_to_time_value(const DDS::Duration_t &t)

Member Function Documentation

◆ boolean_test()

bool OpenDDS::DCPS::TimeDuration::boolean_test ( ) const
inline

Definition at line 77 of file TimeDuration.h.

References value(), and value_.

78  {
79  return value_ != zero_value.value();
80  }
static const TimeDuration zero_value
Definition: TimeDuration.h:31
const ACE_Time_Value & value() const

◆ from_double()

ACE_INLINE TimeDuration OpenDDS::DCPS::TimeDuration::from_double ( double  duration)
static

Return a TimeDuration from fractional seconds.

Definition at line 21 of file TimeDuration.inl.

References ACE_INLINE, ACE_Time_Value::set(), and TimeDuration().

Referenced by OpenDDS::RTPS::RtpsDiscovery::Config::discovery_config().

22 {
23  ACE_Time_Value rv;
24  rv.set(duration);
25  return TimeDuration(rv);
26 }
void set(time_t sec, suseconds_t usec)

◆ from_msec()

ACE_INLINE TimeDuration OpenDDS::DCPS::TimeDuration::from_msec ( const ACE_UINT64 ms)
static

◆ is_max()

ACE_INLINE bool OpenDDS::DCPS::TimeDuration::is_max ( ) const

Definition at line 81 of file TimeDuration.inl.

References ACE_INLINE, and max_value.

Referenced by OpenDDS::DCPS::DomainParticipantImpl::LivelinessTimer::execute().

82 {
83  return *this == max_value;
84 }
static const TimeDuration max_value
Definition: TimeDuration.h:32

◆ is_zero()

ACE_INLINE bool OpenDDS::DCPS::TimeDuration::is_zero ( ) const

◆ operator*=()

ACE_INLINE TimeDuration & OpenDDS::DCPS::TimeDuration::operator*= ( double  other)

Definition at line 111 of file TimeDuration.inl.

References ACE_INLINE, and value_.

112 {
113  value_ *= other;
114  return *this;
115 }

◆ operator+=()

ACE_INLINE TimeDuration & OpenDDS::DCPS::TimeDuration::operator+= ( const TimeDuration other)

Definition at line 95 of file TimeDuration.inl.

References ACE_INLINE, value(), and value_.

96 {
97  value_ += other.value();
98  return *this;
99 }

◆ operator-=()

ACE_INLINE TimeDuration & OpenDDS::DCPS::TimeDuration::operator-= ( const TimeDuration other)

Definition at line 103 of file TimeDuration.inl.

References ACE_INLINE, value(), and value_.

104 {
105  value_ -= other.value();
106  return *this;
107 }

◆ operator/=()

ACE_INLINE TimeDuration & OpenDDS::DCPS::TimeDuration::operator/= ( double  other)

Definition at line 118 of file TimeDuration.inl.

References ACE_INLINE, and value_.

119 {
120  value_ *= (1.0 / other);
121  return *this;
122 }

◆ operator=() [1/2]

ACE_INLINE TimeDuration & OpenDDS::DCPS::TimeDuration::operator= ( const TimeDuration other)

Definition at line 126 of file TimeDuration.inl.

References ACE_INLINE, value(), and value_.

127 {
128  value_ = other.value();
129  return *this;
130 }

◆ operator=() [2/2]

ACE_INLINE TimeDuration & OpenDDS::DCPS::TimeDuration::operator= ( const time_t &  other)

Definition at line 134 of file TimeDuration.inl.

References ACE_INLINE, and value_.

135 {
136  value_ = other;
137  return *this;
138 }

◆ sec_str()

String OpenDDS::DCPS::TimeDuration::sec_str ( unsigned  decimal_places = 3) const
inline

Definition at line 93 of file TimeDuration.h.

References OpenDDS::DCPS::operator+=().

94  {
95  return str(decimal_places, true);
96  }
String str(unsigned decimal_places=3, bool just_sec=false) const

◆ str()

String OpenDDS::DCPS::TimeDuration::str ( unsigned  decimal_places = 3,
bool  just_sec = false 
) const

Convert to a string in a humanized format: SECONDS.FRACTIONAL s if the time is less than a minute or just_sec is true, else: [[HOURS:]MINUTES:]SECONDS.FRACTIONAL

decimal_places is the number of decimal places to round to in the fractional seconds.

Definition at line 54 of file TimeDuration.cpp.

References OPENDDS_END_VERSIONED_NAMESPACE_DECL, ACE_Time_Value::sec(), OpenDDS::DCPS::to_dds_string(), ACE_Time_Value::usec(), and value().

Referenced by OpenDDS::DCPS::ShmemInst::dump_to_str(), OpenDDS::DCPS::RtpsUdpInst::dump_to_str(), OpenDDS::DCPS::TransportInst::dump_to_str(), OpenDDS::DCPS::MulticastInst::dump_to_str(), OpenDDS::RTPS::Spdp::handle_participant_data(), OpenDDS::DCPS::DataReaderImpl::process_latency(), and OpenDDS::DCPS::TcpTransport::release_datalink().

55 {
56  String rv;
57  time_t sec = value().sec();
58  suseconds_t usec = value().usec();
59  bool negative = false;
60  if (sec < 0) {
61  negative = true;
62  sec = -sec;
63  }
64  if (usec < 0) {
65  negative = true;
66  usec = -usec;
67  }
68  if (negative) {
69  rv += "-";
70  }
71  time_t carry;
72  const time_t numerator = usec_to_rounded_frac(usec, decimal_places, carry);
73  const time_t seconds_total = sec + carry;
74  const time_t minutes_total = seconds_total / 60;
75  just_sec = just_sec || minutes_total == 0;
76  if (just_sec) {
77  rv += to_dds_string(seconds_total);
78  } else {
79  const time_t seconds = seconds_total % 60;
80  const time_t minutes = minutes_total % 60;
81  const time_t hours = minutes_total / 60;
82  if (hours > 0) {
83  rv += to_dds_string(hours) + ":" + to_zero_pad_str(minutes);
84  } else {
85  rv += to_dds_string(minutes);
86  }
87  rv += ":" + to_zero_pad_str(seconds);
88  }
89  if (decimal_places > 0) {
90  rv += "." + to_zero_pad_str(numerator, decimal_places);
91  }
92  if (just_sec) {
93  rv += " s";
94  }
95  return rv;
96 }
const ACE_Time_Value & value() const
time_t sec(void) const
suseconds_t usec(void) const
std::string String
String to_dds_string(unsigned short to_convert)

◆ to_dds_duration()

ACE_INLINE DDS::Duration_t OpenDDS::DCPS::TimeDuration::to_dds_duration ( ) const

◆ value() [1/2]

ACE_INLINE const ACE_Time_Value & OpenDDS::DCPS::TimeDuration::value ( void  ) const

Definition at line 60 of file TimeDuration.inl.

References ACE_INLINE, and value_.

Referenced by OpenDDS::DCPS::WriterStats::add_stat(), boolean_test(), OpenDDS::RTPS::Spdp::build_local_pdata(), OpenDDS::DCPS::DataReaderImpl::LivelinessTimer::check_liveliness_i(), OpenDDS::DCPS::DataWriterImpl::enable(), OpenDDS::DCPS::PeriodicTask::enable_i(), OpenDDS::DCPS::MultiTask::enable_i(), OpenDDS::ICE::ScheduleTimerCommand::execute(), OpenDDS::DCPS::SporadicTask::execute_i(), OpenDDS::DCPS::DataReaderImpl::filter_sample(), OpenDDS::DCPS::DomainParticipantImpl::find_topic(), OpenDDS::DCPS::DataLink::handle_exception(), OpenDDS::RTPS::Spdp::handle_participant_data(), OpenDDS::DCPS::DataWriterImpl::handle_timeout(), OpenDDS::DCPS::Service_Participant::initializeScheduling(), OpenDDS::DCPS::DataDurabilityCache::insert(), OpenDDS::DCPS::UdpDataLink::open(), OpenDDS::DCPS::operator!=(), OpenDDS::DCPS::operator*(), OpenDDS::DCPS::operator+(), operator+=(), OpenDDS::DCPS::TimePoint_T< SystemClock >::operator+=(), OpenDDS::DCPS::operator-(), operator-=(), OpenDDS::DCPS::TimePoint_T< SystemClock >::operator-=(), OpenDDS::DCPS::operator/(), OpenDDS::DCPS::operator<(), OpenDDS::DCPS::operator<=(), operator=(), OpenDDS::DCPS::operator==(), OpenDDS::DCPS::operator>(), OpenDDS::DCPS::operator>=(), OpenDDS::DCPS::TcpConnection::passive_reconnect_i(), OpenDDS::DCPS::resend_data_expired(), str(), to_dds_duration(), and OpenDDS::DCPS::ThreadSynchResource::wait_to_unclog().

61 {
62  return value_;
63 }

◆ value() [2/2]

ACE_INLINE void OpenDDS::DCPS::TimeDuration::value ( const ACE_Time_Value ace_time_value)

Definition at line 67 of file TimeDuration.inl.

References ACE_INLINE, and value_.

68 {
69  value_ = ace_time_value;
70 }

Member Data Documentation

◆ max_value

const TimeDuration OpenDDS::DCPS::TimeDuration::max_value
static

◆ value_

ACE_Time_Value OpenDDS::DCPS::TimeDuration::value_
protected

Definition at line 106 of file TimeDuration.h.

Referenced by operator*=(), operator+=(), operator-=(), operator/=(), operator=(), and value().

◆ zero_value

const TimeDuration OpenDDS::DCPS::TimeDuration::zero_value
static

The documentation for this class was generated from the following files: