i6engine  1.0
IPKey.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_CORE_IPKEY_H__
26 #define __I6ENGINE_CORE_IPKEY_H__
27 
28 #include <cstdint>
29 #include <string>
30 #include <utility>
31 
33 
34 #if ISIXE_MPLATFORM == ISIXE_MPLATFORM_WIN32
35  #pragma warning(disable : 4351)
36 #endif
37 
38 namespace boost {
39 namespace serialization {
40  class access;
41 } /* namespace serialization */
42 } /* namespace boost */
43 
44 namespace i6e {
45 namespace core {
46 
53  friend class boost::serialization::access;
54  friend ISIXE_CORE_API std::ostream & operator<<(std::ostream & stream, const IPKey & key);
55 
56  public:
60  IPKey() : _ip(), _port(0) {
61  }
62 
66  IPKey(const std::string & ip, uint16_t port);
67 
72  explicit IPKey(const std::string & str);
73 
77  ~IPKey() {}
78 
82  bool operator==(const IPKey & other) const;
83  bool operator!=(const IPKey & other) const;
84 
88  std::string getIP() const;
89 
93  uint16_t getPort() const {
94  return _port;
95  }
96 
103  bool isValid() const;
104 
110  std::string toString() const;
111 
115  class Hash {
116  public:
117  std::size_t operator()(const IPKey & key) const {
118  return std::hash<std::string>()(key.toString());
119  }
120  };
121 
122  private:
126  template <typename Archive>
127  void serialize(Archive & ar, const unsigned int /*version*/) {
128  ar & _ip;
129  ar & _port;
130  }
131 
132  uint32_t _ip;
133  uint16_t _port;
134  };
135 
136  ISIXE_CORE_API std::ostream & operator<<(std::ostream & stream, const IPKey & key);
137 
138 } /* namespace core */
139 } /* namespace i6e */
140 
141 #endif /* __I6ENGINE_CORE_IPKEY_H__ */
142 
std::enable_if< std::is_integral< T >::value, bool >::type operator==(const i6eVector2< T > &first, const i6eVector2< T > &second)
Definition: i6eVector2.h:261
uint16_t getPort() const
returns the port of the key
Definition: IPKey.h:93
std::string toString() const
Returns the string representation of this IPKey.
IPKey()
default constructor, constructs an invalid Key
Definition: IPKey.h:60
~IPKey()
destructor
Definition: IPKey.h:77
#define ISIXE_CORE_API
std::size_t operator()(const IPKey &key) const
Definition: IPKey.h:117
ISIXE_CORE_API std::ostream & operator<<(std::ostream &stream, const IPKey &key)