libutil++  1.9.3
 All Classes Functions Variables
IPAddress.h
1 /*
2 ** libutil++
3 ** $Id: IPAddress.h 1702 2016-08-13 23:26:06Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__variant__IPAddress_H__
10 #define __libutilxx__sella__variant__IPAddress_H__
11 
12 #include "../../common.h"
13 #include "TypeCastException.h"
14 #include "Nullable.h"
15 #include "../net/IPAddress.h"
16 
17 #include <memory>
18 
19 #include <boost/regex.hpp>
20 
21 namespace sella {
22  namespace variant {
23  class IPAddress;
24  }
25 }
26 
28  public:
29  // http://blog.markhatton.co.uk/2011/03/15/regular-expressions-for-ip-addresses-cidr-ranges-and-hostnames/
30  static const boost::regex & Pattern(void) { static boost::regex regex("^((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])|((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?)$"); return regex; }
31  static const int Type = 0x10;
32 
33  /* Constructors */
34  IPAddress() throw ();
35  IPAddress(const std::string &value) throw (TypeCastException);
36  IPAddress(const sella::net::IPAddress &value) throw ();
37  IPAddress(sella::net::IPAddress &&value) throw ();
38 
39  IPAddress(const IPAddress &other) throw ();
40  IPAddress(IPAddress &&other) throw ();
41  virtual ~IPAddress() throw ();
42 
43  /* Operators */
44  bool operator==(const IPAddress &other) const throw ();
45  bool operator!=(const IPAddress &other) const throw ();
46  bool operator>(const IPAddress &other) const throw ();
47  bool operator<(const IPAddress &other) const throw ();
48  IPAddress& operator=(const IPAddress &other) throw ();
49  IPAddress& operator=(IPAddress &&other) throw ();
50  IPAddress& operator=(const sella::net::IPAddress &other) throw ();
51 
52  /* Public Member Functions */
53  const sella::net::IPAddress& get() const throw (UnsupportedOperatorException);
54  sella::net::IPAddress& get() throw (UnsupportedOperatorException);
55 
56  void clear() throw();
57 
58  virtual void msgpack(sella::util::MessagePack &mpack, uint32_t &offset) const throw (TypeCastException);
59  virtual void msgpackBufferSize(size_t &size) const throw ();
60  virtual std::string str(int type) const throw ();
61  virtual int getType(void) throw () { return Type; }
62 
63  static bool isType(const std::string &value) throw () { return isType(value.c_str(), value.size()); }
64  static bool isType(const char *value, size_t size) throw ();
65 };
66 
67 #endif
68 
69 /*
70 ** vim: noet ts=3 sw=3
71 */