From 5db91e52daeb8b7667ded744134554111834a422 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 12 Feb 2019 14:55:03 +0100 Subject: [PATCH] Fixes to logger templates --- src/ifcparse/IfcLogger.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/ifcparse/IfcLogger.cpp b/src/ifcparse/IfcLogger.cpp index d966edec53..a105e5bcf4 100644 --- a/src/ifcparse/IfcLogger.cpp +++ b/src/ifcparse/IfcLogger.cpp @@ -37,12 +37,15 @@ namespace { static const std::array, 3> value; }; + template <> const std::array, 3> severity_strings::value = { "Notice", "Warning", "Error" }; + + template <> const std::array, 3> severity_strings::value = { L"Notice", L"Warning", L"Error" }; template void plain_text_message(T& os, const boost::optional& current_product, Logger::Severity type, const std::string& message, IfcEntityInstanceData* entity) { - os << "[" << severity_strings::value[type] << "] "; + os << "[" << severity_strings::value[type] << "] "; if (current_product) { os << "{" << (*current_product)->GlobalId().c_str() << "} "; } @@ -65,21 +68,21 @@ namespace { template void json_message(T& os, const boost::optional& current_product, Logger::Severity type, const std::string& message, IfcEntityInstanceData* entity) { - boost::property_tree::basic_ptree, std::basic_string > pt; + boost::property_tree::basic_ptree, std::basic_string > pt; // @todo this is crazy - static const T::char_type level_string[] = { 'l', 'e', 'v', 'e', 'l', 0 }; - static const T::char_type product_string[] = { 'p', 'r', 'o', 'd', 'u', 'c', 't', 0 }; - static const T::char_type message_string[] = { 'm', 'e', 's', 's', 'a', 'g', 'e', 0 }; - static const T::char_type instance_string[] = { 'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 0 }; + static const typename T::char_type level_string[] = { 'l', 'e', 'v', 'e', 'l', 0 }; + static const typename T::char_type product_string[] = { 'p', 'r', 'o', 'd', 'u', 'c', 't', 0 }; + static const typename T::char_type message_string[] = { 'm', 'e', 's', 's', 'a', 'g', 'e', 0 }; + static const typename T::char_type instance_string[] = { 'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 0 }; - pt.put(level_string, severity_strings::value[type]); + pt.put(level_string, severity_strings::value[type]); if (current_product) { - pt.put(product_string, string_as((**current_product).entity->toString())); + pt.put(product_string, string_as((**current_product).entity->toString())); } - pt.put(message_string, string_as(message)); + pt.put(message_string, string_as(message)); if (entity) { - pt.put(instance_string, string_as(entity->toString())); + pt.put(instance_string, string_as(entity->toString())); } boost::property_tree::write_json(os, pt, false); } @@ -109,7 +112,7 @@ void Logger::SetOutput(std::wostream* l1, std::wostream* l2) { template void Logger::log(T& log2, Logger::Severity type, const std::string& message, IfcEntityInstanceData* entity) { - log2 << "[" << severity_strings[type] << "] "; + log2 << "[" << severity_strings::value[type] << "] "; if (current_product) { log2 << "{" << (*current_product)->GlobalId().c_str() << "} "; }