Corelink CPP Client
Corelink C++ client library
 
Loading...
Searching...
No Matches
corelink_network_constants.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace corelink
8{
9 namespace core
10 {
11 namespace network
12 {
16 namespace constants
17 {
21 CORELINK_CPP_ATTR_MAYBE_UNUSED constexpr CORELINK_EXPORT ptr_to_const_val<char> IPV4_LOOP_BACK_ADDRESS{
22 "127.0.0.1"};
26 CORELINK_CPP_ATTR_MAYBE_UNUSED constexpr CORELINK_EXPORT ptr_to_const_val<char> IPV6_LOOP_BACK_ADDRESS{
27 "::1"};
28
33 namespace protocols
34 {
39 struct CORELINK_EXPORT protocol
40 {
41 public:
45 using bit_mask_pos_type = uint16_t;
49 using bit_mask_type = std::bitset<sizeof(bit_mask_pos_type) * 8>;
50
51 private:
59 const bit_mask_pos_type bit_pos{};
60
61 public:
68 template<size_t sz>
69 constexpr protocol(const char(&s)[sz], bit_mask_pos_type pos): name(s), bit_pos(pos)
70 {}
71
77 inline bool operator==(const protocol &rhs) const
78 {
79 return (std::strcmp(name, rhs.name) == 0) && bit_pos == rhs.bit_pos;
80 }
81
87 inline bool operator!=(const protocol &rhs) const
88 {
89 return !((*this) == rhs);
90 }
91
96 constexpr inline bit_mask_pos_type operator()() const
97 {
98 return bit_pos;
99 }
100
106 {
107 return name;
108 }
109
116 inline friend std::ostream &operator<<(std::ostream &os, const protocol &p)
117 {
118 os << "Name: " << p.name << ", Bit mask position: " << p.bit_pos;
119 return os;
120 }
121 };
122
126 static constexpr protocol unknown{"unknown",
127 8 * sizeof(protocol::bit_mask_pos_type)};
128
129#ifdef CORELINK_USE_TCP
133 static constexpr protocol tcp{"tcp", 0};
134#endif
135#ifdef CORELINK_USE_UDP
139 static constexpr protocol udp{"udp", 1};
140#endif
141#ifdef CORELINK_USE_WEBSOCKET
145 static constexpr protocol websocket{"ws", 2};
146#endif //CORELINK_USE_WEBSOCKET
147 }
148
153 enum class state : uint8_t
154 {
155 initialised = 0,
156 connected = 1,
157 stale = 2,
158 in_error = 3,
159 };
160 }
161 }
162 }
163}