ipv6_address.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2009 zooml.com
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 #ifndef __TERRALIB_COMMON_INTERNAL_IPV6_ADDRESS_H
23 #define __TERRALIB_COMMON_INTERNAL_IPV6_ADDRESS_H
24 #include "../Config.h"
25 #include <string>
26 #include <iostream>
27 namespace te
28 {
29  namespace common
30  {
31  namespace uri
32  {
33  /* \brief IP v6 address.
34  *
35  * Syntax: Note that leading 0's are not valid.
36  * <pre>
37  * IPv6address = 6( h16 ":" ) ls32
38  * | "::" 5( h16 ":" ) ls32
39  * | [ h16 ] "::" 4( h16 ":" ) ls32
40  * | [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
41  * | [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
42  * | [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
43  * | [ *4( h16 ":" ) h16 ] "::" ls32
44  * | [ *5( h16 ":" ) h16 ] "::" h16
45  * | [ *6( h16 ":" ) h16 ] "::"
46  * ls32 = ( h16 ":" h16 ) | IPv4address
47  * ; least-significant 32 bits of address
48  * h16 = 1*4HEXDIG
49  * ; 16 bits of address represented in hexadecimal
50  * </pre>
51  * @see http://tools.ietf.org/html/rfc3986#section-3.2.2 */
53  public:
54  ipv6_address(); ///< Construct null.
55  /// Construct from string. Note that the string cannot
56  /// be empty, it must contain valid chars.
57  /// @exception std::invalid_argument if invalid
58  ipv6_address(const std::string& v);
59  /// Test if null (all 0's).
60  bool is_null() const;
61  /// Calculate string representation.
62  /// Leading zeros are dropped, i.e. "3F" instead of "003F".
63  /// Compress the longest run of 0's into "::" if
64  /// \p compress is true.
65  std::string string(bool compress = false) const;
66  /// Stream out.
67  /// @see string()
68  std::ostream& write(std::ostream& os, bool compress = false) const;
69  static const char SEPARATOR_CHAR; ///< separator (':')
70  private:
71  friend bool TECOMMONEXPORT parse(std::string::const_iterator& first, std::string::const_iterator last, ipv6_address& v);
72  bool zero_run(size_t& first, size_t& last) const;
73  unsigned short hextets_[8];
74  };
75  /// Stream out IP v6 address.
76  inline std::ostream& operator <<(std::ostream& os, const ipv6_address& v) {return v.write(os);}
77  /// Parse IP v6 address, returning whether found or not
78  /// and advancing first and setting address if found.
79  /// Does not skip leading space.
80  bool TECOMMONEXPORT parse(std::string::const_iterator& first, std::string::const_iterator last, ipv6_address& v);
81  }
82  }
83 }
84 #endif
std::ostream & operator<<(std::ostream &os, const authority &v)
Stream out URI authority.
Definition: authority.h:95
std::ostream & write(std::ostream &os, bool compress=false) const
Stream out.
bool TECOMMONEXPORT parse(std::string::const_iterator &first, std::string::const_iterator last, authority &v)
Parse URI authority, returning whether found or not and advancing first and setting authority if foun...
URI C++ Library.
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
static const char SEPARATOR_CHAR
separator (':')
Definition: ipv6_address.h:69