emlabcpp
modern opinionated embedded C++ library
error.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #ifdef EMLABCPP_USE_MAGIC_ENUM
27 #include "../../enum.h"
28 #endif
29 #include "../../protocol/streams.h"
30 #include "../../visit.h"
31 #include "./protocol.h"
32 
33 #include <variant>
34 
35 namespace emlabcpp::testing
36 {
37 
39 {
41 };
42 
44 {
46 };
47 
49 {
51 };
52 
54 {
56 };
57 
58 using error_variant = std::variant<
63 
64 #ifdef EMLABCPP_USE_OSTREAM
65 inline std::ostream& operator<<( std::ostream& os, reactor_protocol_error const& e )
66 {
67  return os << e.rec;
68 }
69 
70 inline std::ostream& operator<<( std::ostream& os, controller_protocol_error const& e )
71 {
72  return os << e.rec;
73 }
74 
75 inline std::ostream& operator<<( std::ostream& os, internal_reactor_error const& e )
76 {
77  match( e.val, [&os]< typename T >( T const& ) {
78 #ifdef EMLABCPP_USE_MAGIC_ENUM
79  os << convert_enum( T::id );
80 #else
81  os << static_cast<std::underlying_type_t<decltype(T::id)>>(T::id);
82 #endif
83  } );
84  return os;
85 }
86 
87 inline std::ostream& operator<<( std::ostream& os, controller_internal_error const& e )
88 {
89 #ifdef EMLABCPP_USE_MAGIC_ENUM
90  return os << convert_enum( e.msg_id );
91 #else
92  return os << static_cast< std::underlying_type_t< msgid > >( e.msg_id );
93 #endif
94 }
95 
96 inline std::ostream& operator<<( std::ostream& os, error_variant const& var )
97 {
99  [&os]( auto const& item ) {
100  os << item;
101  },
102  var );
103  return os;
104 }
105 #endif
106 
107 } // namespace emlabcpp::testing
Definition: error.h:39
MIT License.
Definition: base.h:37
reactor_error_variant val
Definition: error.h:50
std::variant< error< TEST_IS_RUNING_E >, error< TEST_NOT_FOUND_E >, error< BAD_TEST_ID_E >, error< UNDESIRED_MSG_E >, no_response_error, wrong_type_error, tree_error_reply, error< WRONG_MESSAGE_E >, input_message_protocol_error > reactor_error_variant
Definition: protocol.h:184
std::variant< reactor_protocol_error, controller_protocol_error, internal_reactor_error, controller_internal_error > error_variant
Definition: error.h:62
protocol::error_record rec
Definition: error.h:45
protocol::error_record rec
Definition: error.h:40
msgid
Definition: protocol.h:48
decltype(auto) match(Variant &&var, Callables &&... cals)
Definition: match.h:55
decltype(auto) visit(Visitor &&vis, Variant &&var)
Reimplementation of std::visit.
Definition: visit.h:44
std::ostream & operator<<(std::ostream &os, string_buffer< N > const &sb)
Definition: string_buffer.h:112