RESTinio
common_types.hpp
Go to the documentation of this file.
1 /*
2  restinio
3 */
4 
5 /*!
6  Restinio common types.
7 */
8 
9 #pragma once
10 
11 #include <cstdint>
12 
13 #include <restinio/asio_include.hpp>
14 
15 namespace restinio
16 {
17 
18 //! Request handling status.
19 /*!
20  If handler handles request it must return accepted.
21 
22  If handler refuses to handle request
23  it must return rejected.
24 */
26 {
27  //! Request accepted for handling.
28  accepted,
29 
30  //! Request wasn't accepted for handling.
31  rejected
32 };
33 
34 //! @name Helper funcs for working with request_handling_status_t
35 //! \see request_handling_status_t.
36 ///@{
38 request_accepted() noexcept
39 {
41 }
42 
44 request_rejected() noexcept
45 {
47 }
48 ///@}
49 
50 //! Request id in scope of single connection.
51 using request_id_t = unsigned int;
52 
53 //! Attribute for parts.
55 {
56  //! Intermediate parts (more parts of response to follow).
58  //! Final parts (response ands with these parts).
60 };
61 
62 inline std::ostream &
64 {
65  if( response_parts_attr_t::not_final_parts == attr )
66  o << "not_final_parts";
67  else
68  o << "final_parts";
69 
70  return o;
71 }
72 
73 //! Attribute for parts.
75 {
76  //! This response says to keep connection.
78  //! This response says to close connection.
80 };
81 
82 inline std::ostream &
84 {
85  if( response_connection_attr_t::connection_keepalive == attr )
86  o << "connection_keepalive";
87  else
88  o << "connection_close";
89 
90  return o;
91 }
92 
94 response_connection_attr( bool should_keep_alive )
95 {
96  if( should_keep_alive )
98 
100 }
101 
102 //! Response output flags for buffers commited to response-coordinator
104 {
106  response_parts_attr_t response_parts,
107  response_connection_attr_t response_connection ) noexcept
108  : m_response_parts{ response_parts }
109  , m_response_connection{ response_connection }
110  {}
111 
114 };
115 
116 inline std::ostream &
118 {
119  return o << "{ " << flags.m_response_parts << ", "
120  << flags.m_response_connection << " }";
121 }
122 
123 //
124 // nullable_pointer_t
125 //
126 /*!
127  * @brief Type for pointer that can be nullptr.
128  *
129  * This type is used in methods which return raw pointers. It indicates
130  * that returned value should be checked for nullptr.
131  *
132  * @since v.0.4.9
133  */
134 template< typename T >
135 using nullable_pointer_t = T*;
136 
137 //
138 // not_null_pointer_t
139 //
140 /*!
141  * @brief Type for pointer that is not null by design.
142  *
143  * @note
144  * There is no any compile-time or run-time checks for a value of the pointer.
145  * It is just a flag that we don't expect a nullptr here by design.
146  *
147  * @since v.0.4.9
148  */
149 template< typename T >
150 using not_null_pointer_t = T*;
151 
152 /*!
153  * @brief Type for ID of connection.
154  */
156 
157 //! An alias for endpoint type from Asio.
159 
160 } /* namespace restinio */
response_output_flags_t(response_parts_attr_t response_parts, response_connection_attr_t response_connection) noexcept
std::ostream & operator<<(std::ostream &o, const response_output_flags_t &flags)
This response says to close connection.
Final parts (response ands with these parts).
This response says to keep connection.
response_connection_attr_t m_response_connection
Request wasn&#39;t accepted for handling.
response_connection_attr_t response_connection_attr(bool should_keep_alive)
response_connection_attr_t
Attribute for parts.
request_handling_status_t
Request handling status.
std::ostream & operator<<(std::ostream &o, response_parts_attr_t attr)
std::ostream & operator<<(std::ostream &o, response_connection_attr_t attr)
response_parts_attr_t m_response_parts
Intermediate parts (more parts of response to follow).
constexpr request_handling_status_t request_rejected() noexcept
Request accepted for handling.
response_parts_attr_t
Attribute for parts.
Response output flags for buffers commited to response-coordinator.
constexpr request_handling_status_t request_accepted() noexcept
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
Definition: value_or.hpp:64