Add first version
[ric-plt/sdl.git] / include / private / hostandport.hpp
1 /*
2    Copyright (c) 2018-2019 Nokia.
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
17 #ifndef SHAREDDATALAYER_HOSTANDPORT_HPP_
18 #define SHAREDDATALAYER_HOSTANDPORT_HPP_
19
20 #include <string>
21 #include <stdint.h>
22 #include <sdl/exception.hpp>
23
24 namespace shareddatalayer
25 {
26     class HostAndPort
27     {
28     public:
29         class InvalidPort;
30
31         class EmptyPort;
32
33         class EmptyHost;
34
35         HostAndPort() = delete;
36
37         /* defaultPort in network byte order */
38         HostAndPort(const std::string& addressAndOptionalPort, uint16_t defaultPort);
39
40         const std::string& getHost() const;
41
42         /* Returned port in network byte order */
43         uint16_t getPort() const;
44
45         std::string getString() const;
46
47         bool operator==(const HostAndPort& hp) const;
48
49         bool operator!=(const HostAndPort& hp) const;
50
51         bool operator<(const HostAndPort& hp) const;
52
53     private:
54         void parse(const std::string& addressAndOptionalPort, uint16_t defaultPort);
55
56         std::string host;
57         uint16_t port;
58         bool literalIPv6;
59     };
60
61     class HostAndPort::InvalidPort: public Exception
62     {
63     public:
64         InvalidPort() = delete;
65
66         explicit InvalidPort(const std::string& port);
67     };
68
69     class HostAndPort::EmptyPort: public Exception
70     {
71     public:
72         EmptyPort();
73     };
74
75     class HostAndPort::EmptyHost: public Exception
76     {
77     public:
78         EmptyHost();
79     };
80 }
81
82 #endif