summaryrefslogtreecommitdiff
path: root/ACE/ace/Time_Value_T.h
blob: 32b32df3d41fda56590cf1b6c25e6fadd78bc4ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Time_Value_T.h
 *
 *  @author Martin Corino <mcorino@remedy.nl>
 */
//=============================================================================

#ifndef ACE_TIME_VALUE_T_H
#define ACE_TIME_VALUE_T_H

#include /**/ "ace/pre.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Time_Value.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @class ACE_Time_Value
 *
 * @brief Operations on "timeval" structures, which express time in
 * seconds (secs) and microseconds (usecs).
 *
 * This class centralizes all the time related processing in
 * ACE.  These time values are typically used in conjunction with OS
 * mechanisms like <select>, <poll>, or <cond_timedwait>.
 */
template <class TIME_POLICY>
class ACE_Time_Value_T : public ACE_Time_Value
{
public:
  typedef TIME_POLICY time_policy_t;

  /// Default Constructor.
  ACE_Time_Value_T () {}

  /// Constructor.
  explicit ACE_Time_Value_T (time_t sec, suseconds_t usec = 0)
    : ACE_Time_Value (sec, usec) {}

  // = Methods for converting to/from various time formats.

  /// Construct the ACE_Time_Value from a timeval.
  explicit ACE_Time_Value_T (const struct timeval &t)
    : ACE_Time_Value (t) {}

  /// Construct the ACE_Time_Value object from a timespec_t.
  explicit ACE_Time_Value_T (const timespec_t &t)
    : ACE_Time_Value (t) {}

  /// Construct from ACE_Time_Value_T<TIME_POLICY>
  ACE_Time_Value_T(const ACE_Time_Value_T<TIME_POLICY>& tv)
    : ACE_Time_Value (tv),
      time_policy_ (tv.time_policy_)
  {}

  /// Construct from ACE_Time_Value
  explicit ACE_Time_Value_T(const ACE_Time_Value& tv,
                            const TIME_POLICY& tp = TIME_POLICY ())
    : ACE_Time_Value (tv),
      time_policy_ (tp)
  {}

  /// Destructor
  virtual ~ACE_Time_Value_T () {}

  /// Add @a tv to this.
  ACE_Time_Value_T<TIME_POLICY> &operator += (const ACE_Time_Value &tv);

  /// Add @a tv to this.
  ACE_Time_Value_T<TIME_POLICY> &operator += (time_t tv);

  /// Assign @ tv to this
  ACE_Time_Value_T<TIME_POLICY> &operator = (const ACE_Time_Value_T<TIME_POLICY> &tv);

  /// Assign @ tv to this
  ACE_Time_Value_T<TIME_POLICY> &operator = (const ACE_Time_Value &tv);

  /// Assign @ tv to this
  ACE_Time_Value_T<TIME_POLICY> &operator = (time_t tv);

  /// Subtract @a tv to this.
  ACE_Time_Value_T<TIME_POLICY> &operator -= (const ACE_Time_Value &tv);

  /// Subtract @a tv to this.
  ACE_Time_Value_T<TIME_POLICY> &operator -= (time_t tv);

  /**
    \brief Multiply the time value by the @a d factor.
    \note The result of the operator is valid for results from range
    < (ACE_INT32_MIN, -999999), (ACE_INT32_MAX, 999999) >. Result
    outside this range are saturated to a limit.
     */
  ACE_Time_Value_T<TIME_POLICY> &operator *= (double d);

  /// Increment microseconds as postfix.
  /**
   * @note The only reason this is here is to allow the use of ACE_Atomic_Op
   * with ACE_Time_Value.
   */
  ACE_Time_Value_T<TIME_POLICY> operator++ (int);

  /// Increment microseconds as prefix.
  /**
   * @note The only reason this is here is to allow the use of ACE_Atomic_Op
   * with ACE_Time_Value.
   */
  ACE_Time_Value_T<TIME_POLICY> &operator++ ();

  /// Decrement microseconds as postfix.
  /**
   * @note The only reason this is here is to allow the use of ACE_Atomic_Op
   * with ACE_Time_Value.
   */
  ACE_Time_Value_T<TIME_POLICY> operator-- (int);

  /// Decrement microseconds as prefix.
  /**
   * @note The only reason this is here is to allow the use of ACE_Atomic_Op
   * with ACE_Time_Value.
   */
  ACE_Time_Value_T<TIME_POLICY> &operator-- ();

  /// Get current time of day according to time policy.
  /**
   * @return  Time value representing current time of day according to time policy.
   */
  virtual ACE_Time_Value now () const;

  /// Converts absolute time value to time value relative to current time of day.
  /**
   * @return  Relative time value.
   *
   * @note    This method uses it's time_policy_ member to get the current
   *          time of day.
   *          The developer is responsible for making sure this is an absolute
   *          time value compatible with the active time policy.
   *          Note that the returned time value has no notion of the time policy
   *          on which it is based anymore.
   */
  virtual ACE_Time_Value to_relative_time () const;

  /// Converts relative time value to absolute time value based on current time of day.
  /**
   * @return  Absolute time value.
   *
   * @note    This method uses it's time_policy_ member to get the current
   *          time of day.
   *          The developer is responsible for making sure this is a relative
   *          time value.
   *          Note that the returned time value has no notion of the time policy
   *          on which it is based anymore.
   */
  virtual ACE_Time_Value to_absolute_time () const;

  /// Duplicates this time value (incl. time policy).
  /**
   * @return  Dynamically allocated time value copy.
   *
   * @note    The caller is responsible for freeing the copy when it's not needed
   *          anymore.
   */
  virtual ACE_Time_Value * duplicate () const;

private:
  TIME_POLICY time_policy_;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "ace/Time_Value_T.inl"
#endif /* __ACE_INLINE__ */

#include "ace/Time_Value_T.cpp"

#include /**/ "ace/post.h"
#endif /* ACE_TIME_VALUE_T_H */