Qpid Proton C++ API  0.18.1
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 MINUTE;
57 
58  private:
59  numeric_type ms_;
60 };
61 
63 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, duration);
64 
67 inline bool operator<(duration x, duration y) { return x.milliseconds() < y.milliseconds(); }
68 inline bool operator==(duration x, duration y) { return x.milliseconds() == y.milliseconds(); }
69 
70 inline duration operator+(duration x, duration y) { return duration(x.milliseconds() + y.milliseconds()); }
71 inline duration operator-(duration x, duration y) { return duration(x.milliseconds() - y.milliseconds()); }
72 inline duration operator*(duration d, uint64_t n) { return duration(d.milliseconds()*n); }
73 inline duration operator*(uint64_t n, duration d) { return d * n; }
75 
76 } // proton
77 
78 #endif // PROTON_DURATION_HPP
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.
duration(numeric_type ms=0)
Construct from a value in milliseconds.
Definition: duration.hpp:45
A span of time in milliseconds.
Definition: duration.hpp:39
static const duration IMMEDIATE
Don&#39;t wait at all.
Definition: duration.hpp:54
numeric_type milliseconds() const
Get the value in milliseconds.
Definition: duration.hpp:51
Forward declarations for Proton types used to represent AMQP types.
int64_t numeric_type
A numeric type holding a value in milliseconds.
Definition: duration.hpp:42
static const duration SECOND
One second.
Definition: duration.hpp:55
duration & operator=(numeric_type ms)
Assign a value in milliseconds.
Definition: duration.hpp:48
static const duration MINUTE
One minute.
Definition: duration.hpp:56
The main Proton namespace.
Definition: annotation_key.hpp:33
static const duration FOREVER
Wait forever.
Definition: duration.hpp:53