Hazelcast C++ Client
Address.h
1 /*
2  * Copyright (c) 2008-2018, 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 #ifndef HAZELCAST_ADDRESS
17 #define HAZELCAST_ADDRESS
18 
19 #include "hazelcast/util/HazelcastDll.h"
20 #include "hazelcast/client/serialization/IdentifiedDataSerializable.h"
21 
22 #include <string>
23 #include <sstream>
24 
25 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
26 // We need to include this header before asio/ip/address.hpp
27 #include <winsock2.h>
28 #endif
29 
30 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
31 #pragma warning(push)
32 #pragma warning(disable: 4251) //for dll export
33 #endif
34 
35 namespace hazelcast {
36  namespace client {
37 
41  class HAZELCAST_API Address : public serialization::IdentifiedDataSerializable {
42  public:
43  Address(const std::string &hostname, int port, unsigned long scopeId);
44 
45  static const int ID;
46 
50  Address();
51 
55  Address(const std::string &url, int port);
56 
61  bool operator == (const Address &address) const;
62 
67  bool operator != (const Address &address) const;
68 
72  int getPort() const;
73 
78  bool isIpV4() const;
79 
83  const std::string& getHost() const;
84 
85  /***** serialization::IdentifiedDataSerializable interface implementation starts here *********************/
86  virtual int getFactoryId() const;
87 
88  virtual int getClassId() const;
89 
90  virtual void writeData(serialization::ObjectDataOutput &writer) const;
91 
92  virtual void readData(serialization::ObjectDataInput &reader);
93 
94  /***** serialization::IdentifiedDataSerializable interface implementation end here ************************/
95 
96  unsigned long getScopeId() const;
97 
98  bool operator<(const Address &rhs) const;
99 
100  std::string toString() const;
101  private:
102  std::string host;
103  int port;
104  byte type;
105  unsigned long scopeId;
106 
107  static const byte IPV4;
108  static const byte IPV6;
109  };
110 
111  typedef std::less<Address> addressComparator;
112 
113  std::ostream HAZELCAST_API &operator << (std::ostream &stream, const Address &address);
114 
115  }
116 };
117 
118 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
119 #pragma warning(pop)
120 #endif
121 
122 #endif /* HAZELCAST_ADDRESS */
Provides serialization methods for primitive types,a arrays of primitive types, Portable, IdentifiedDataSerializable and custom serializables.
Definition: ObjectDataOutput.h:54
IP Address.
Definition: Address.h:41
Classes that will be used with hazelcast data structures like IMap, IQueue etc should either inherit ...
Definition: IdentifiedDataSerializable.h:47
Provides deserialization methods for primitives types, arrays of primitive types Portable, IdentifiedDataSerializable and custom serializable types.
Definition: ObjectDataInput.h:70
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32