ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PropagatorError.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PropagatorError.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <iostream>
12 #include <string> // for string printing
13 #include <system_error> // bring in std::error_code et al
14 
15 namespace Acts {
16 // This is the custom error code enum
17 enum class PropagatorError { Failure = 1, WrongDirection = 2 };
18 
19 namespace detail {
20 // Define a custom error code category derived from std::error_category
21 class PropagatorErrorCategory : public std::error_category {
22  public:
23  // Return a short descriptive name for the category
24  const char* name() const noexcept final { return "PropagatorError"; }
25  // Return what each enum means in text
26  std::string message(int c) const final {
27  switch (static_cast<PropagatorError>(c)) {
28  case PropagatorError::Failure:
29  return "Propagation failed";
30  case PropagatorError::WrongDirection:
31  return "Propagation occurred in the wrong direction";
32  default:
33  return "unknown";
34  }
35  }
36 };
37 } // namespace detail
38 
39 // Declare a global function returning a static instance of the custom category
42  return c;
43 }
44 
45 inline std::error_code make_error_code(Acts::PropagatorError e) {
46  return {static_cast<int>(e), Acts::PropagatorErrorCategory()};
47 }
48 } // namespace Acts
49 
50 namespace std {
51 // register with STL
52 template <>
53 struct is_error_code_enum<Acts::PropagatorError> : std::true_type {};
54 } // namespace std