Commit 2a4c1694 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils :
- In GenericType correct wrong cast from string to boolean with true/false string value.
- Update LoggerManager error message.
parent 793e8c13
......@@ -69,7 +69,13 @@ void LoggerManager::parseConfigurationFile(const std::string &filePath) {
for (it = data.begin(); it != data.end(); it++) {
if (StringUtils::equalsIgnoreCase(it->first, ENABLE_NAME)) {
m_active = GenericType(it->second).toBoolean();
try {
m_active = GenericType(it->second).toBoolean();
} catch (std::exception &e) {
throw std::runtime_error(
"Cannot instantiated LoggerManager wrong value for ["
+ ENABLE_NAME + "] parameter in logger.cfg file");
}
}
// retrieve default level value
else if (StringUtils::equalsIgnoreCase(it->first, DEFAULT_LEVEL_NAME)) {
......
......@@ -2,6 +2,8 @@
#include <stdexcept>
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h"
namespace ElemUtils {
GenericType::GenericType(const GenericType &other) {
......@@ -91,12 +93,17 @@ bool GenericType::toBoolean() const {
//create a temporary object to avoid empty m_stream after conversion with >> operator ; for multiple use of the same GenericType object
std::stringstream sstream;
sstream << m_stream.str();
bool b = false;
// if conversion failed then print an exception
if ((sstream >> b).fail()) {
throw std::runtime_error(
"[GenericType::toBoolean] cast from std::string to bool failed ! ");
if (StringUtils::equalsIgnoreCase(sstream.str(), "true")) {
b = 1;
} else if (!StringUtils::equalsIgnoreCase(sstream.str(), "false")) {
throw std::runtime_error(
"[GenericType::toBoolean] cast from std::string to bool failed ! ");
}
}
return b;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment