SSP21-CPP
ErrorCategory.h
1 
2 #ifndef SSP21_ERRORCATEGORY_H
3 #define SSP21_ERRORCATEGORY_H
4 
5 #include <system_error>
6 #include <string>
7 
8 #if (defined _MSC_VER && (_MSC_VER < 1900))
9 #define NOEXCEPT
10 #else
11 #define NOEXCEPT noexcept
12 #endif
13 
14 namespace ssp21
15 {
16 
17  template <class EnumSpec>
18  class ErrorCategory final : public std::error_category
19  {
20  public:
21 
22  static const std::error_category& get()
23  {
24  static ErrorCategory instance;
25  return instance;
26  }
27 
28  virtual const char* name() const NOEXCEPT
29  {
30  return EnumSpec::name;
31  }
32 
33  virtual std::string message(int ev) const
34  {
35  return EnumSpec::to_string(static_cast<typename EnumSpec::enum_type_t>(ev));
36  }
37 
38  private:
39 
40  ErrorCategory() {}
41  ErrorCategory(const ErrorCategory&) = delete;
42  };
43 }
44 
45 #endif
SSP21-cpp main namespace.
Definition: BufferTypes.h:12