error.h
1 #ifndef GARLIC_ERROR_H
2 #define GARLIC_ERROR_H
3 
4 #include "garlic.h"
5 
6 namespace garlic {
7 
11  enum class GarlicError {
12  Redefinition = 1,
13  UndefinedObject = 2,
14  InvalidModule = 3,
15  };
16 
17  namespace error {
18 
19  class GarlicErrorCategory : public std::error_category {
20  public:
21  const char* name() const noexcept override { return "garlic"; }
22  std::string message(int code) const override {
23  switch (static_cast<GarlicError>(code)) {
24  case GarlicError::Redefinition:
25  return "An element with the same identification is already defined. Redifinition is not allowed.";
26  case GarlicError::UndefinedObject:
27  return "Use of an undefined/unresolved object.";
28  case GarlicError::InvalidModule:
29  return "Module description is invalid and could not be used to create a Module.";
30  default:
31  return "unknown";
32  }
33  }
34  };
35 
36  }
37 
38  inline std::error_code
39  make_error_code(garlic::GarlicError error) {
40  static const garlic::error::GarlicErrorCategory category{};
41  return {static_cast<int>(error), category};
42  }
43 
44 
45 }
46 
47 namespace std {
48  template<>
49  struct is_error_code_enum<garlic::GarlicError> : true_type {};
50 }
51 
52 #endif /* end of include guard: GARLIC_ERROR_H */
GarlicError
Garlic Model global error code enum.