Qpid Proton C++ API  0.37.0
duration.hpp
Go to the documentation of this file.
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 
35 
36 namespace proton {
37 
39 class duration : private internal::comparable<duration> {
40  public:
42  typedef int64_t numeric_type;
43 
45  explicit duration(numeric_type ms = 0) : ms_(ms) {}
46 
48  duration& operator=(numeric_type ms) { ms_ = ms; return *this; }
49 
51  numeric_type milliseconds() const { return ms_; }
52 
53  PN_CPP_EXTERN static const duration FOREVER;
54  PN_CPP_EXTERN static const duration IMMEDIATE;
55  PN_CPP_EXTERN static const duration SECOND;
56  PN_CPP_EXTERN static const duration MILLISECOND;
57  PN_CPP_EXTERN static const duration MINUTE;
58 
59  private:
60  numeric_type ms_;
61 };
62 
64 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, duration);
65 
68 inline bool operator<(duration x, duration y) { return x.milliseconds() < y.milliseconds(); }
69 inline bool operator==(duration x, duration y) { return x.milliseconds() == y.milliseconds(); }
70 
71 inline duration operator+(duration x, duration y) { return duration(x.milliseconds() + y.milliseconds()); }
72 inline duration operator-(duration x, duration y) { return duration(x.milliseconds() - y.milliseconds()); }
73 inline duration operator*(duration d, uint64_t n) { return duration(d.milliseconds()*n); }
74 inline duration operator*(uint64_t n, duration d) { return d * n; }
75 inline duration operator/(duration d, uint64_t n) { return duration(d.milliseconds() / n); }
77 
78 } // proton
79 
80 #endif // PROTON_DURATION_HPP
A span of time in milliseconds.
Definition: duration.hpp:39
duration & operator=(numeric_type ms)
Assign a value in milliseconds.
Definition: duration.hpp:48
static const duration MINUTE
One minute.
Definition: duration.hpp:57
int64_t numeric_type
A numeric type holding a value in milliseconds.
Definition: duration.hpp:42
duration(numeric_type ms=0)
Construct from a value in milliseconds.
Definition: duration.hpp:45
static const duration IMMEDIATE
Don't wait at all.
Definition: duration.hpp:54
static const duration FOREVER
Wait forever.
Definition: duration.hpp:53
static const duration SECOND
One second.
Definition: duration.hpp:55
static const duration MILLISECOND
One millisecond.
Definition: duration.hpp:56
numeric_type milliseconds() const
Get the value in milliseconds.
Definition: duration.hpp:51
The main Proton namespace.
Definition: annotation_key.hpp:33
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.
Forward declarations for Proton types used to represent AMQP types.