Telnet++ 4.0.0.9
A C++ library for interacting with Telnet streams
Loading...
Searching...
No Matches
negotiation.hpp
1#pragma once
2
3#include "telnetpp/core.hpp"
4#include "telnetpp/detail/hash.hpp"
5
6#include <iosfwd>
7#include <cassert>
8
9namespace telnetpp {
10
11//* =========================================================================
13//* =========================================================================
14class TELNETPP_EXPORT negotiation
15{
16 public:
17 //* =====================================================================
19 //* =====================================================================
20 constexpr negotiation(negotiation_type request, option_type option) noexcept
21 : request_(request), option_(option)
22 {
23 assert(
24 request == telnetpp::will || request == telnetpp::wont
25 || request == telnetpp::do_ || request == telnetpp::dont);
26 }
27
28 //* =====================================================================
31 //* =====================================================================
32 [[nodiscard]] constexpr negotiation_type request() const noexcept
33 {
34 return request_;
35 }
36
37 //* =====================================================================
39 //* =====================================================================
40 [[nodiscard]] constexpr option_type option_code() const noexcept
41 {
42 return option_;
43 }
44
45 //* =====================================================================
47 //* =====================================================================
48 constexpr void hash_combine(std::size_t &seed) const
49 {
50 telnetpp::detail::hash_combine(seed, request_, option_);
51 }
52
53 private:
54 negotiation_type request_;
55 option_type option_;
56};
57
58//* =========================================================================
60//* =========================================================================
61constexpr bool operator==(
62 negotiation const &lhs, negotiation const &rhs) noexcept
63{
64 return lhs.request() == rhs.request()
65 && lhs.option_code() == rhs.option_code();
66}
67
68//* =========================================================================
70//* =========================================================================
71constexpr bool operator<(
72 negotiation const &lhs, negotiation const &rhs) noexcept
73{
74 return lhs.request() < rhs.request()
75 || (!(rhs.request() < lhs.request())
76 && lhs.option_code() < rhs.option_code());
77}
78
79//* =========================================================================
81//* =========================================================================
82TELNETPP_EXPORT
83std::ostream &operator<<(std::ostream &out, negotiation const &neg);
84
85} // namespace telnetpp
86
87// This is necessary because the lookup for the recipient for a negotiation
88// in a session relies on both the request and the option type (will/wont
89// go to a different place than do/don't, for example). Therefore, the entire
90// negotiation is the key in the lookup and needs to be hashable to go to the
91// unordered map.
92TELNETPP_MAKE_INTRUSIVE_HASH(telnetpp::negotiation)
A class that encapsulates a Telnet negotiation.
Definition negotiation.hpp:15
constexpr negotiation(negotiation_type request, option_type option) noexcept
Constructor.
Definition negotiation.hpp:20
constexpr void hash_combine(std::size_t &seed) const
Combine a hash of the object.
Definition negotiation.hpp:48
constexpr option_type option_code() const noexcept
Returns the option code (e.g. echo, naws) of this negotiation.
Definition negotiation.hpp:40
constexpr negotiation_type request() const noexcept
Returns the request (will, wont, do, dont) of this negotiation.
Definition negotiation.hpp:32
An class that encapsulates one side of a Telnet option.
Definition option.hpp:46