Apache Ignite C++ Client
Loading...
Searching...
No Matches
cluster_node.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 "ignite/common/end_point.h"
21#include "ignite/common/uuid.h"
22
23#include <type_traits>
24
25namespace ignite {
26
30class cluster_node {
31public:
32 // Default
33 cluster_node() = default;
34
42 cluster_node(uuid id, std::string name, end_point address)
43 : m_id(id)
44 , m_name(std::move(name))
45 , m_address(std::move(address)) {}
46
52 [[nodiscard]] const uuid &get_id() const { return m_id; }
53
59 [[nodiscard]] const std::string &get_name() const { return m_name; }
60
66 [[nodiscard]] const end_point &get_address() const { return m_address; }
67
75 [[nodiscard]] int compare(const cluster_node &other) const {
76 auto name_comp = m_name.compare(other.m_name);
77 if (name_comp)
78 return name_comp;
79
80 auto id_comp = m_id.compare(other.m_id);
81 if (id_comp)
82 return id_comp;
83
84 return m_address.compare(other.m_address);
85 }
86
87private:
89 uuid m_id{};
90
92 std::string m_name{};
93
95 end_point m_address{};
96};
97
105inline bool operator==(const cluster_node &val1, const cluster_node &val2) {
106 return val1.compare(val2) == 0;
107}
108
116inline bool operator!=(const cluster_node &val1, const cluster_node &val2) {
117 return !(val1 == val2);
118}
119
127inline bool operator<(const cluster_node &val1, const cluster_node &val2) {
128 return val1.compare(val2) < 0;
129}
130
138inline bool operator<=(const cluster_node &val1, const cluster_node &val2) {
139 return val1.compare(val2) <= 0;
140}
141
149inline bool operator>(const cluster_node &val1, const cluster_node &val2) {
150 return val1.compare(val2) > 0;
151}
152
160inline bool operator>=(const cluster_node &val1, const cluster_node &val2) {
161 return val1.compare(val2) >= 0;
162}
163
164} // namespace ignite
Definition cluster_node.h:30
const uuid & get_id() const
Definition cluster_node.h:52
int compare(const cluster_node &other) const
Definition cluster_node.h:75
const end_point & get_address() const
Definition cluster_node.h:66
const std::string & get_name() const
Definition cluster_node.h:59
cluster_node(uuid id, std::string name, end_point address)
Definition cluster_node.h:42
Universally unique identifier (UUID).
Definition uuid.h:32
constexpr int compare(const uuid &other) const noexcept
Definition uuid.h:109
Definition end_point.h:28