dconv 2.0
C++14 library for printing and parsing floating point numbers
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1
25#ifndef __DCONV_ERROR_HPP__
26#define __DCONV_ERROR_HPP__
27
28// C++.
29#include <system_error>
30#include <string>
31
32namespace dconv
33{
37 enum class Errc
38 {
39 Success = 0,
41 NotDouble,
42 };
43
47 class ErrorCategory : public std::error_category
48 {
49 public:
54 const char* name () const noexcept override
55 {
56 return "dconv";
57 }
58
64 std::string message (int code) const override
65 {
66 switch (static_cast<Errc> (code))
67 {
69 return "number is invalid";
70 case Errc::NotDouble:
71 return "number is an integer";
72 default:
73 return "success";
74 }
75 }
76 };
77
80
85 inline const std::error_category& errorCategory () noexcept
86 {
88 }
89
95 inline std::error_code make_error_code (Errc code) noexcept
96 {
97 return std::error_code (static_cast<int> (code), errorCategory ());
98 }
99
105 inline std::error_condition make_error_condition (Errc code) noexcept
106 {
107 return std::error_condition (static_cast<int> (code), errorCategory ());
108 }
109}
110
111namespace std
112{
114 template <>
115 struct is_error_code_enum<dconv::Errc> : public true_type
116 {
117 };
118}
119
120#endif
conversion error category.
Definition error.hpp:48
std::string message(int code) const override
translate conversion error code to human readable error string.
Definition error.hpp:64
const char * name() const noexcept override
get conversion error category name.
Definition error.hpp:54
Definition atod.hpp:47
const std::error_category & errorCategory() noexcept
get error category.
Definition error.hpp:85
Errc
conversion error codes.
Definition error.hpp:38
std::error_code make_error_code(Errc code) noexcept
create an std::error_code object.
Definition error.hpp:95
std::error_condition make_error_condition(Errc code) noexcept
create an std::error_condition object.
Definition error.hpp:105
const ErrorCategory errorCategoryInstance
conversion error category instance.
Definition error.hpp:79
Definition error.hpp:112