Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
Time.h
Go to the documentation of this file.
1 #ifndef _sys_Time_h
2 #define _sys_Time_h
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include "qpid/sys/IntegerTypes.h"
26 /*
27  * The platform defines its notion of time as a TimePrivate type. The
28  * platform's implementation knows how to handle this type.
29  */
30 #if defined (_WIN32)
31 # include "windows/Time.h"
32 #else
33 # include "posix/Time.h"
34 #endif
35 
37 
38 #include <limits>
39 #include <iosfwd>
40 
41 namespace qpid {
42 namespace sys {
43 
44 class Duration;
45 
80 class AbsTime {
81  friend class Duration;
82  friend class Condition;
83 
84  TimePrivate timepoint;
85 
86 public:
87 
88  inline AbsTime() : timepoint() {}
89  QPID_COMMON_EXTERN AbsTime(const AbsTime& time0, const Duration& duration);
90  // Default assignment operation fine
91  // Default copy constructor fine
92 
96 
97  bool operator==(const AbsTime& t) const { return t.timepoint == timepoint; }
98 
99  friend bool operator<(const AbsTime& a, const AbsTime& b);
100  friend bool operator>(const AbsTime& a, const AbsTime& b);
101  QPID_COMMON_EXTERN friend std::ostream& operator << (std::ostream&, const AbsTime&);
102 };
103 
104 QPID_COMMON_EXTERN std::ostream& operator << (std::ostream&, const AbsTime&);
105 
115 class Duration {
116  static int64_t max() { return std::numeric_limits<int64_t>::max(); }
117  int64_t nanosecs;
118 
119  friend class AbsTime;
120 
121 public:
122  QPID_COMMON_INLINE_EXTERN inline Duration(int64_t time0 = 0);
123  QPID_COMMON_EXTERN explicit Duration(const AbsTime& start, const AbsTime& finish);
124  inline operator int64_t() const;
125 };
126 
127 QPID_COMMON_EXTERN std::ostream& operator << (std::ostream&, const Duration&);
128 QPID_COMMON_EXTERN std::istream& operator >> (std::istream&, Duration&);
129 
130 inline AbsTime now() { return AbsTime::now(); }
131 
132 inline bool operator<(const AbsTime& a, const AbsTime& b)
133 { return a.timepoint < b.timepoint; }
134 inline bool operator>(const AbsTime& a, const AbsTime& b)
135 { return a.timepoint > b.timepoint; }
136 
137 Duration::Duration(int64_t time0) :
138  nanosecs(time0)
139 {}
140 
141 Duration::operator int64_t() const
142 { return nanosecs; }
143 
145 const Duration TIME_SEC = 1000*1000*1000;
147 const Duration TIME_MSEC = 1000*1000;
149 const Duration TIME_USEC = 1000;
151 const Duration TIME_NSEC = 1;
152 
154 const Duration TIME_INFINITE = std::numeric_limits<int64_t>::max();
155 
158 
161 
163 QPID_COMMON_EXTERN void sleep(int secs);
164 
166 QPID_COMMON_EXTERN void usleep(uint64_t usecs);
167 
169 void outputFormattedNow(std::ostream&);
170 
172 void outputHiresNow(std::ostream&);
173 
174 }}
175 
176 #endif
const Duration TIME_USEC
Nanoseconds per microseconds.
Definition: Time.h:149
AbsTime now()
Definition: Time.h:130
A condition variable for thread synchronization.
Definition: Condition.h:40
int64_t TimePrivate
Class to represent an instant in time.
Definition: Time.h:30
std::ostream & operator<<(std::ostream &, const AbsTime &)
friend bool operator<(const AbsTime &a, const AbsTime &b)
Definition: Time.h:132
static AbsTime Epoch()
#define QPID_COMMON_INLINE_EXTERN
static AbsTime now()
static AbsTime FarFuture()
Class to represent the duration between instants of time.
Definition: Time.h:115
bool operator==(const AbsTime &t) const
Definition: Time.h:97
const Duration TIME_NSEC
Nanoseconds per nanosecond.
Definition: Time.h:151
bool operator>(const AbsTime &a, const AbsTime &b)
Definition: Time.h:134
void outputHiresNow(std::ostream &)
Output unformatted nanosecond-resolution time for now.
void sleep(int secs)
Portable sleep for a number of seconds.
const Duration TIME_MSEC
Nanoseconds per millisecond.
Definition: Time.h:147
std::istream & operator>>(std::istream &, Duration &)
bool operator<(const AbsTime &a, const AbsTime &b)
Definition: Time.h:132
const Duration TIME_INFINITE
Value to represent an infinite timeout.
Definition: Time.h:154
friend bool operator>(const AbsTime &a, const AbsTime &b)
Definition: Time.h:134
const AbsTime FAR_FUTURE
Time greater than any other time.
Definition: Time.h:160
const AbsTime EPOCH
Absolute time point for the Unix epoch: 1970-01-01T00:00:00.
Definition: Time.h:157
QPID_COMMON_INLINE_EXTERN Duration(int64_t time0=0)
Definition: Time.h:137
void outputFormattedNow(std::ostream &)
Output formatted date/time for now.
friend std::ostream & operator<<(std::ostream &, const AbsTime &)
void usleep(uint64_t usecs)
Portable sleep for a number of microseconds.
const Duration TIME_SEC
Nanoseconds per second.
Definition: Time.h:145
Class to represent an instant in time.
Definition: Time.h:80
#define QPID_COMMON_EXTERN

Qpid C++ API Reference
Generated on Tue Apr 14 2020 for Qpid C++ Client API by doxygen 1.8.5