diff --git a/cmake/config.h.in b/cmake/config.h.in index 2770b9c..78d63af 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -1,3 +1,11 @@ #pragma once +#cmakedefine CPPLOGGING_HAS_CPPCORE #cmakedefine CPPLOGGING_HAS_NLOHMANN_JSON + +#ifdef CPPCURL_HAS_CPPCORE + #include + #define cpplogging_convert_cast ::cppcore::convert_cast +#else + #define cpplogging_convert_cast static_cast +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11ab077..fc2ef72 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,11 @@ Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) +Find_Package ( cppcore QUIET ) +If ( cppcore ) + Set ( CPPLOGGING_HAS_CPPCORE true ) +EndIf ( ) + Find_Package ( nlohmann_json QUIET ) If ( nlohmann_json_FOUND ) Set ( CPPLOGGING_HAS_NLOHMANN_JSON true ) diff --git a/src/cpplogging/manager/consumer/formatting.cpp b/src/cpplogging/manager/consumer/formatting.cpp index a21b0a1..9f8edba 100644 --- a/src/cpplogging/manager/consumer/formatting.cpp +++ b/src/cpplogging/manager/consumer/formatting.cpp @@ -144,7 +144,7 @@ consumer::format_type consumer::parse_format(const std::string& format) if (s < c) { if (!ret.empty() && !ret.back().empty() && *ret.back().c_str() != '\0') - ret.back() += std::string(s, static_cast(c - s - 1)); + ret.back() += std::string(s, cpplogging_convert_cast(c - s - 1)); else ret.emplace_back(s, c - s); } @@ -174,7 +174,7 @@ consumer::format_type consumer::parse_format(const std::string& format) if (s + 1 < c) { if (!ret.empty() && !ret.back().empty() && *ret.back().c_str() != '\0') - ret.back() += std::string(s, static_cast(c - s - 1)); + ret.back() += std::string(s, cpplogging_convert_cast(c - s - 1)); else ret.emplace_back(s, c - s - 1); } @@ -197,7 +197,7 @@ consumer::format_type consumer::parse_format(const std::string& format) /* if we are in 'is_in_token' we extract the token and switch to 'is_in_format' */ case parser_state::is_in_token: state = parser_state::is_in_format; - item.token = value_token_map.get_token(std::string(x, static_cast(c - x))); + item.token = value_token_map.get_token(std::string(x, cpplogging_convert_cast(c - x))); if (item.token == value_token::unknown) { state = parser_state::is_text; @@ -270,7 +270,7 @@ consumer::format_type consumer::parse_format(const std::string& format) } else { - item.width = static_cast(u); + item.width = cpplogging_convert_cast(u); x = c + 1; state = parser_state::is_in_format_dot; } @@ -326,9 +326,9 @@ consumer::format_type consumer::parse_format(const std::string& format) else { if (state == parser_state::is_in_format_dot) - item.precision = static_cast(u); + item.precision = cpplogging_convert_cast(u); else - item.width = static_cast(u); + item.width = cpplogging_convert_cast(u); /* set the type and switch to 'is_in_format_type' */ x = c + 1; @@ -360,7 +360,7 @@ consumer::format_type consumer::parse_format(const std::string& format) /* if we are in 'is_in_token' we extract the token, add the item and switch to 'is_text' */ case parser_state::is_in_token: state = parser_state::is_text; - item.token = value_token_map.get_token(std::string(x, static_cast(c - x))); + item.token = value_token_map.get_token(std::string(x, cpplogging_convert_cast(c - x))); if (item.token == value_token::unknown) { state = parser_state::is_text; @@ -390,9 +390,9 @@ consumer::format_type consumer::parse_format(const std::string& format) if (x != tmp && x <= c) { if (state == parser_state::is_in_format_dot) - item.precision = static_cast(u); + item.precision = cpplogging_convert_cast(u); else - item.width = static_cast(u); + item.width = cpplogging_convert_cast(u); ret.emplace_back(item.as_string()); } item.reset(); @@ -482,7 +482,7 @@ void consumer::write_formatted(const log_entry& e, const format_type& f, std::os switch (i.format) { case value_format::decimal: - os << static_cast(e.level); + os << cpplogging_convert_cast(e.level); break; case value_format::string_upper: switch (e.level) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 427a008..aa7abc8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,7 +45,7 @@ ForEach ( FILE IN LISTS CPPLOGGING_TEST_SOURCE_FILES ) # test If ( HAS_CMAKE_TESTS ) - Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} ) + Add_CMake_Test ( NAME ${TEST_NAME} TARGET ${TEST_NAME} GROUP cpplogging ) Else ( ) Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) EndIf ( )