File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11set (DOMAIN_SOURCES
22 application_service.cpp
3+ domain_error.cpp
34 title.cpp
45 )
56
Original file line number Diff line number Diff line change 1+ #include " domain_error.hpp"
2+
3+ namespace fix ::domain {
4+ namespace {
5+
6+ std::string error_message (fix::domain::domain_error error) {
7+ switch (error) {
8+ case domain_error::MISSING_IMPLEMENTATION :
9+ return " feature is not implemented yet" ;
10+ }
11+ return " unknown domain error" ;
12+ }
13+
14+ // =========================================================
15+ // wiring to enable use of std::error_code with domain_error
16+ // =========================================================
17+
18+ struct fix_error_category_t : std::error_category {
19+ [[nodiscard]] char const * name () const noexcept override {
20+ return " fix_domain_error" ;
21+ }
22+
23+ [[nodiscard]] std::string message (int condition) const override {
24+ return error_message (static_cast <fix::domain::domain_error>(condition));
25+ };
26+ };
27+
28+ const fix_error_category_t fix_error_category;
29+ } // namespace
30+
31+ std::error_code make_error_code (domain_error error) {
32+ return {static_cast <int >(error), fix_error_category};
33+ }
34+
35+ } // namespace fix::domain
Original file line number Diff line number Diff line change 1+ #ifndef FIX_SRC_DOMAIN_DOMAIN_ERROR_HPP
2+ #define FIX_SRC_DOMAIN_DOMAIN_ERROR_HPP
3+
4+ #include < system_error>
5+
6+ namespace fix ::domain {
7+
8+ enum class domain_error {
9+ MISSING_IMPLEMENTATION = 1 ,
10+ };
11+
12+ }
13+
14+ // =========================================================
15+ // wiring to enable use of std::error_code with domain_error
16+ // =========================================================
17+ namespace std {
18+ template <>
19+ struct is_error_code_enum <fix::domain::domain_error> : true_type {};
20+ } // namespace std
21+
22+ namespace fix ::domain {
23+ std::error_code make_error_code (domain_error);
24+ }
25+
26+ #endif // FIX_SRC_DOMAIN_DOMAIN_ERROR_HPP
Original file line number Diff line number Diff line change 11set (DOMAIN_TEST_SOURCES
22 application_service_test.cpp
3+ domain_error_test.cpp
34 title_test.cpp
45 )
56
Original file line number Diff line number Diff line change 1+ #include < catch2/catch.hpp>
2+
3+ #include " domain_error.hpp"
4+
5+ using namespace fix ::domain;
6+
7+ TEST_CASE (" Domain errors can be used with std::error_code" ) {
8+ std::error_code error_code = domain_error::MISSING_IMPLEMENTATION ;
9+
10+ CHECK (error_code.message () == " feature is not implemented yet" );
11+ }
You can’t perform that action at this time.
0 commit comments