Hazelcast C++ Client
Hazelcast C++ Client Library
address.h
1 /*
2  * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include "hazelcast/util/byte.h"
19 #include "hazelcast/util/export.h"
20 #include "hazelcast/client/serialization/serialization.h"
21 
22 #include <string>
23 #include <sstream>
24 
25 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
26 #pragma warning(push)
27 #pragma warning(disable : 4251) // for dll export
28 #endif
29 
30 namespace hazelcast {
31 namespace client {
32 
36 class HAZELCAST_API address
37 {
39  friend struct std::hash<hazelcast::client::address>;
40 
41 public:
42  address(std::string hostname, int port, unsigned long scope_id);
43 
44  static constexpr int ID = 0;
45 
49  address();
50 
51  address(std::string url, int port);
52 
56  bool operator==(const address& address) const;
57 
61  bool operator!=(const address& address) const;
62 
66  int get_port() const;
67 
72  bool is_ip_v4() const;
73 
77  const std::string& get_host() const;
78 
79  unsigned long get_scope_id() const;
80 
81  bool operator<(const address& rhs) const;
82 
83  std::string to_string() const;
84 
85 private:
86  std::string host_;
87  int port_;
88  byte type_;
89  unsigned long scope_id_;
90 
91  static constexpr byte IPV4 = 4;
92  static constexpr byte IPV6 = 6;
93 };
94 
95 namespace serialization {
96 template<>
97 struct hz_serializer<address> : public identified_data_serializer
98 {
99  static constexpr int32_t F_ID = 0;
100  static constexpr int32_t ADDRESS = 1;
101  static int32_t get_factory_id();
102  static int32_t get_class_id();
103  static void write_data(const address& object, object_data_output& out);
104  static address read_data(object_data_input& in);
105 };
106 } // namespace serialization
107 
108 std::ostream HAZELCAST_API&
109 operator<<(std::ostream& stream, const address& address);
110 } // namespace client
111 } // namespace hazelcast
112 
113 namespace std {
114 template<>
115 struct HAZELCAST_API hash<hazelcast::client::address>
116 {
117  std::size_t operator()(
118  const hazelcast::client::address& address) const noexcept;
119 };
120 } // namespace std
121 
122 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
123 #pragma warning(pop)
124 #endif
Represents an address of a client or member in the cluster.
Definition: address.h:37