Qpid Proton C++  0.17.0
duration.hpp
1 #ifndef PROTON_DURATION_HPP
2 #define PROTON_DURATION_HPP
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 "./internal/export.hpp"
26 #include "./internal/comparable.hpp"
27 #include "./types_fwd.hpp"
28 
29 #include <proton/type_compat.h>
30 
31 #include <iosfwd>
32 
33 namespace proton {
34 
36 class duration : private internal::comparable<duration> {
37  public:
39  typedef int64_t numeric_type;
40 
42  explicit duration(numeric_type ms = 0) : ms_(ms) {}
43 
45  duration& operator=(numeric_type ms) { ms_ = ms; return *this; }
46 
48  numeric_type milliseconds() const { return ms_; }
49 
50  PN_CPP_EXTERN static const duration FOREVER;
51  PN_CPP_EXTERN static const duration IMMEDIATE;
52  PN_CPP_EXTERN static const duration SECOND;
53  PN_CPP_EXTERN static const duration MINUTE;
54 
55  private:
56  numeric_type ms_;
57 };
58 
60 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, duration);
61 
64 inline bool operator<(duration x, duration y) { return x.milliseconds() < y.milliseconds(); }
65 inline bool operator==(duration x, duration y) { return x.milliseconds() == y.milliseconds(); }
66 
67 inline duration operator+(duration x, duration y) { return duration(x.milliseconds() + y.milliseconds()); }
68 inline duration operator-(duration x, duration y) { return duration(x.milliseconds() - y.milliseconds()); }
69 inline duration operator*(duration d, uint64_t n) { return duration(d.milliseconds()*n); }
70 inline duration operator*(uint64_t n, duration d) { return d * n; }
72 
73 } // proton
74 
75 #endif // PROTON_DURATION_HPP
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.
duration(numeric_type ms=0)
Construct from milliseconds.
Definition: duration.hpp:42
A span of time in milliseconds.
Definition: duration.hpp:36
static const duration IMMEDIATE
Don&#39;t wait at all.
Definition: duration.hpp:51
Forward declarations for all the C++ types used by Proton to represent AMQP types.
int64_t numeric_type
Numeric type used to store milliseconds.
Definition: duration.hpp:39
static const duration SECOND
One second.
Definition: duration.hpp:52
numeric_type milliseconds() const
Return milliseconds.
Definition: duration.hpp:48
duration & operator=(numeric_type ms)
Assign.
Definition: duration.hpp:45
static const duration MINUTE
One minute.
Definition: duration.hpp:53
The main Proton namespace.
Definition: annotation_key.hpp:30
static const duration FOREVER
Wait forever.
Definition: duration.hpp:50