diff options
author | Patrick Venture <venture@google.com> | 2019-03-15 21:07:09 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2019-03-15 21:15:18 -0700 |
commit | 0ba794d959e6fca838c872cd75f2b2a1c6ddd511 (patch) | |
tree | 91b77b59d72f23415a611ea1440096a7846a795d /src/ipmiblob/ipmi_errors.hpp | |
parent | 1681f7ff9fe112a0c3c318d562f4b46489eea02c (diff) | |
download | ipmi-blob-tool-0ba794d959e6fca838c872cd75f2b2a1c6ddd511.tar.gz ipmi-blob-tool-0ba794d959e6fca838c872cd75f2b2a1c6ddd511.zip |
ipmi_errors: object cleanup
Cleanup the object to use a function to generate a constructor parameter
instead of a constructor body.
Change-Id: Ib9c9aea86212c67c1949d78e4105d6727557168b
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'src/ipmiblob/ipmi_errors.hpp')
-rw-r--r-- | src/ipmiblob/ipmi_errors.hpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/ipmiblob/ipmi_errors.hpp b/src/ipmiblob/ipmi_errors.hpp index 02bfe0b..e41b3cf 100644 --- a/src/ipmiblob/ipmi_errors.hpp +++ b/src/ipmiblob/ipmi_errors.hpp @@ -2,7 +2,6 @@ #include <exception> #include <map> -#include <sstream> #include <string> namespace ipmiblob @@ -11,37 +10,38 @@ namespace ipmiblob class IpmiException : public std::exception { public: - const std::map<int, std::string> commonFailures = { - {0xc0, "busy"}, - {0xc1, "invalid"}, - {0xc3, "timeout"}, - }; + explicit IpmiException(const std::string& message) : _message(message){}; - explicit IpmiException(int cc) + static std::string messageFromIpmi(int cc) { - std::ostringstream smessage; + const std::map<int, std::string> commonFailures = { + {0xc0, "busy"}, + {0xc1, "invalid"}, + {0xc3, "timeout"}, + }; auto search = commonFailures.find(cc); if (search != commonFailures.end()) { - smessage << "Received IPMI_CC: " << search->second; + return "Received IPMI_CC: " + search->second; } else { - smessage << "Received IPMI_CC: " << cc; + return "Received IPMI_CC: " + std::to_string(cc); } + } - message = smessage.str(); + explicit IpmiException(int cc) : IpmiException(messageFromIpmi(cc)) + { } - explicit IpmiException(const std::string& message) : message(message){}; virtual const char* what() const noexcept override { - return message.c_str(); + return _message.c_str(); } private: - std::string message; + std::string _message; }; } // namespace ipmiblob |