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>
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 @@
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(const std::string& message) : message(message){};
+
+ explicit IpmiException(int cc) : IpmiException(messageFromIpmi(cc))
+ {
+ }
virtual const char* what() const noexcept override
{
- return message.c_str();
+ return _message.c_str();
}
private:
- std::string message;
+ std::string _message;
};
} // namespace ipmiblob