Hazelcast C++ Client
Hazelcast C++ Client Library
address.h
1 /*
2  * Copyright (c) 2008-2021, 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 {
38  friend struct std::hash<hazelcast::client::address>;
39  public:
40  address(std::string hostname, int port, unsigned long scope_id);
41 
42  static constexpr int ID = 0;
43 
47  address();
48 
49  address(std::string url, int port);
50 
54  bool operator == (const address &address) const;
55 
59  bool operator != (const address &address) const;
60 
64  int get_port() const;
65 
70  bool is_ip_v4() const;
71 
75  const std::string& get_host() const;
76 
77  unsigned long get_scope_id() const;
78 
79  bool operator<(const address &rhs) const;
80 
81  std::string to_string() const;
82  private:
83  std::string host_;
84  int port_;
85  byte type_;
86  unsigned long scope_id_;
87 
88  static constexpr byte IPV4 = 4;
89  static constexpr byte IPV6 = 6;
90  };
91 
92  namespace serialization {
93  template<>
94  struct hz_serializer<address> : public identified_data_serializer {
95  static constexpr int32_t F_ID = 0;
96  static constexpr int32_t ADDRESS = 1;
97  static int32_t get_factory_id();
98  static int32_t get_class_id();
99  static void write_data(const address &object, object_data_output &out);
100  static address read_data(object_data_input &in);
101  };
102  }
103 
104  std::ostream HAZELCAST_API &operator << (std::ostream &stream, const address &address);
105  }
106 }
107 
108 namespace std {
109  template<>
110  struct HAZELCAST_API hash<hazelcast::client::address> {
111  std::size_t operator()(const hazelcast::client::address &address) const noexcept;
112  };
113 }
114 
115 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
116 #pragma warning(pop)
117 #endif
118 
119 
Represents an address of a client or member in the cluster.
Definition: address.h:36