Apache Ignite C++ Client
Loading...
Searching...
No Matches
end_point.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#include <string>
22
23namespace ignite {
24
28struct end_point {
29 // Default
30 end_point() = default;
31
38 end_point(std::string host, uint16_t port)
39 : host(std::move(host))
40 , port(port) {}
41
47 [[nodiscard]] std::string to_string() const { return host + ":" + std::to_string(port); }
48
56 [[nodiscard]] int compare(const end_point &other) const {
57 if (port < other.port)
58 return -1;
59
60 if (port > other.port)
61 return 1;
62
63 return host.compare(other.host);
64 }
65
67 std::string host;
68
70 uint16_t port{0};
71};
72
80inline bool operator==(const end_point &val1, const end_point &val2) {
81 return val1.port == val2.port && val1.host == val2.host;
82}
83
91inline bool operator!=(const end_point &val1, const end_point &val2) {
92 return !(val1 == val2);
93}
94
102inline bool operator<(const end_point &val1, const end_point &val2) {
103 return val1.compare(val2) < 0;
104}
105
113inline bool operator<=(const end_point &val1, const end_point &val2) {
114 return val1.compare(val2) <= 0;
115}
116
124inline bool operator>(const end_point &val1, const end_point &val2) {
125 return val1.compare(val2) > 0;
126}
127
135inline bool operator>=(const end_point &val1, const end_point &val2) {
136 return val1.compare(val2) >= 0;
137}
138
139} // namespace ignite
Definition end_point.h:28
end_point(std::string host, uint16_t port)
Definition end_point.h:38
std::string to_string() const
Definition end_point.h:47
int compare(const end_point &other) const
Definition end_point.h:56
uint16_t port
Definition end_point.h:70
std::string host
Definition end_point.h:67