Apache Ignite C++ Client
Loading...
Searching...
No Matches
ignite_duration.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <cstdint>
21
22namespace ignite {
23
30public:
34 constexpr ignite_duration() noexcept = default;
35
42 constexpr ignite_duration(std::int64_t seconds, std::int32_t nanos)
43 : seconds(seconds)
44 , nanos(nanos) {
45 // TODO: check that arguments are in valid ranges.
46 }
47
51 constexpr std::int64_t get_seconds() const noexcept { return seconds; }
52
56 constexpr std::int32_t get_nano() const noexcept { return nanos; }
57
64 constexpr int compare(const ignite_duration &other) const noexcept {
65 if (seconds != other.seconds) {
66 return seconds < other.seconds ? -1 : 1;
67 }
68 return nanos - other.nanos;
69 }
70
71private:
73 std::int64_t seconds = 0;
74
76 std::int32_t nanos = 0;
77};
78
86constexpr bool operator==(const ignite_duration &lhs, const ignite_duration &rhs) noexcept {
87 return lhs.compare(rhs) == 0;
88}
89
97constexpr bool operator!=(const ignite_duration &lhs, const ignite_duration &rhs) noexcept {
98 return lhs.compare(rhs) != 0;
99}
100
108constexpr bool operator<(const ignite_duration &lhs, const ignite_duration &rhs) noexcept {
109 return lhs.compare(rhs) < 0;
110}
111
119constexpr bool operator<=(const ignite_duration &lhs, const ignite_duration &rhs) noexcept {
120 return lhs.compare(rhs) <= 0;
121}
122
130constexpr bool operator>(const ignite_duration &lhs, const ignite_duration &rhs) noexcept {
131 return lhs.compare(rhs) > 0;
132}
133
141constexpr bool operator>=(const ignite_duration &lhs, const ignite_duration &rhs) noexcept {
142 return lhs.compare(rhs) >= 0;
143}
144
145} // namespace ignite
A time-based amount of time.
Definition ignite_duration.h:29
constexpr std::int32_t get_nano() const noexcept
Definition ignite_duration.h:56
constexpr int compare(const ignite_duration &other) const noexcept
Definition ignite_duration.h:64
constexpr ignite_duration() noexcept=default
constexpr std::int64_t get_seconds() const noexcept
Definition ignite_duration.h:51