Add extra line about src files are part of RIC platform project
[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 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20 */
21
22 #ifndef SHAREDDATALAYER_HOSTANDPORT_HPP_
23 #define SHAREDDATALAYER_HOSTANDPORT_HPP_
24
25 #include <string>
26 #include <stdint.h>
27 #include <sdl/exception.hpp>
28 #include <iosfwd>
29
30 namespace shareddatalayer
31 {
32     class HostAndPort
33     {
34     public:
35         class InvalidPort;
36
37         class EmptyPort;
38
39         class EmptyHost;
40
41         HostAndPort() = delete;
42
43         /* defaultPort in network byte order */
44         HostAndPort(const std::string& addressAndOptionalPort, uint16_t defaultPort);
45
46         const std::string& getHost() const;
47
48         /* Returned port in network byte order */
49         uint16_t getPort() const;
50
51         std::string getString() const;
52
53         bool operator==(const HostAndPort& hp) const;
54
55         bool operator!=(const HostAndPort& hp) const;
56
57         bool operator<(const HostAndPort& hp) const;
58
59     private:
60         void parse(const std::string& addressAndOptionalPort, uint16_t defaultPort);
61
62         std::string host;
63         uint16_t port;
64         bool literalIPv6;
65     };
66
67     class HostAndPort::InvalidPort: public Exception
68     {
69     public:
70         InvalidPort() = delete;
71
72         explicit InvalidPort(const std::string& port);
73     };
74
75     class HostAndPort::EmptyPort: public Exception
76     {
77     public:
78         EmptyPort();
79     };
80
81     class HostAndPort::EmptyHost: public Exception
82     {
83     public:
84         EmptyHost();
85     };
86
87     std::ostream& operator << (std::ostream& os, const HostAndPort& hostAndPort);
88 }
89
90 #endif