Ver a proveniência

*Use convert_cast instead of static_cast where feasible

master
bergmann há 4 anos
ascendente
cometimento
ebad81657f
4 ficheiros alterados com 24 adições e 11 eliminações
  1. +8
    -0
      cmake/config.h.in
  2. +5
    -0
      src/CMakeLists.txt
  3. +10
    -10
      src/cpplogging/manager/consumer/formatting.cpp
  4. +1
    -1
      test/CMakeLists.txt

+ 8
- 0
cmake/config.h.in Ver ficheiro

@@ -1,3 +1,11 @@
#pragma once #pragma once


#cmakedefine CPPLOGGING_HAS_CPPCORE
#cmakedefine CPPLOGGING_HAS_NLOHMANN_JSON #cmakedefine CPPLOGGING_HAS_NLOHMANN_JSON

#ifdef CPPCURL_HAS_CPPCORE
#include <cppcore/conversion/convert_cast.h>
#define cpplogging_convert_cast ::cppcore::convert_cast
#else
#define cpplogging_convert_cast static_cast
#endif

+ 5
- 0
src/CMakeLists.txt Ver ficheiro

@@ -4,6 +4,11 @@ Include ( cotire OPTIONAL RESULT_VARIABLE HAS_COTIRE
Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC ) Include ( pedantic OPTIONAL RESULT_VARIABLE HAS_PEDANTIC )
Include ( strip_symbols OPTIONAL RESULT_VARIABLE HAS_STRIP_SYMBOLS ) 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 ) Find_Package ( nlohmann_json QUIET )
If ( nlohmann_json_FOUND ) If ( nlohmann_json_FOUND )
Set ( CPPLOGGING_HAS_NLOHMANN_JSON true ) Set ( CPPLOGGING_HAS_NLOHMANN_JSON true )


+ 10
- 10
src/cpplogging/manager/consumer/formatting.cpp Ver ficheiro

@@ -144,7 +144,7 @@ consumer::format_type consumer::parse_format(const std::string& format)
if (s < c) if (s < c)
{ {
if (!ret.empty() && !ret.back().empty() && *ret.back().c_str() != '\0') if (!ret.empty() && !ret.back().empty() && *ret.back().c_str() != '\0')
ret.back() += std::string(s, static_cast<size_t>(c - s - 1));
ret.back() += std::string(s, cpplogging_convert_cast<size_t>(c - s - 1));
else else
ret.emplace_back(s, c - s); 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 (s + 1 < c)
{ {
if (!ret.empty() && !ret.back().empty() && *ret.back().c_str() != '\0') if (!ret.empty() && !ret.back().empty() && *ret.back().c_str() != '\0')
ret.back() += std::string(s, static_cast<size_t>(c - s - 1));
ret.back() += std::string(s, cpplogging_convert_cast<size_t>(c - s - 1));
else else
ret.emplace_back(s, c - s - 1); 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' */ /* if we are in 'is_in_token' we extract the token and switch to 'is_in_format' */
case parser_state::is_in_token: case parser_state::is_in_token:
state = parser_state::is_in_format; state = parser_state::is_in_format;
item.token = value_token_map.get_token(std::string(x, static_cast<size_t>(c - x)));
item.token = value_token_map.get_token(std::string(x, cpplogging_convert_cast<size_t>(c - x)));
if (item.token == value_token::unknown) if (item.token == value_token::unknown)
{ {
state = parser_state::is_text; state = parser_state::is_text;
@@ -270,7 +270,7 @@ consumer::format_type consumer::parse_format(const std::string& format)
} }
else else
{ {
item.width = static_cast<uint8_t>(u);
item.width = cpplogging_convert_cast<uint8_t>(u);
x = c + 1; x = c + 1;
state = parser_state::is_in_format_dot; state = parser_state::is_in_format_dot;
} }
@@ -326,9 +326,9 @@ consumer::format_type consumer::parse_format(const std::string& format)
else else
{ {
if (state == parser_state::is_in_format_dot) if (state == parser_state::is_in_format_dot)
item.precision = static_cast<uint8_t>(u);
item.precision = cpplogging_convert_cast<uint8_t>(u);
else else
item.width = static_cast<uint8_t>(u);
item.width = cpplogging_convert_cast<uint8_t>(u);


/* set the type and switch to 'is_in_format_type' */ /* set the type and switch to 'is_in_format_type' */
x = c + 1; 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' */ /* 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: case parser_state::is_in_token:
state = parser_state::is_text; state = parser_state::is_text;
item.token = value_token_map.get_token(std::string(x, static_cast<size_t>(c - x)));
item.token = value_token_map.get_token(std::string(x, cpplogging_convert_cast<size_t>(c - x)));
if (item.token == value_token::unknown) if (item.token == value_token::unknown)
{ {
state = parser_state::is_text; 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 (x != tmp && x <= c)
{ {
if (state == parser_state::is_in_format_dot) if (state == parser_state::is_in_format_dot)
item.precision = static_cast<uint8_t>(u);
item.precision = cpplogging_convert_cast<uint8_t>(u);
else else
item.width = static_cast<uint8_t>(u);
item.width = cpplogging_convert_cast<uint8_t>(u);
ret.emplace_back(item.as_string()); ret.emplace_back(item.as_string());
} }
item.reset(); item.reset();
@@ -482,7 +482,7 @@ void consumer::write_formatted(const log_entry& e, const format_type& f, std::os
switch (i.format) switch (i.format)
{ {
case value_format::decimal: case value_format::decimal:
os << static_cast<int>(e.level);
os << cpplogging_convert_cast<int>(e.level);
break; break;
case value_format::string_upper: case value_format::string_upper:
switch (e.level) switch (e.level)


+ 1
- 1
test/CMakeLists.txt Ver ficheiro

@@ -45,7 +45,7 @@ ForEach ( FILE IN LISTS CPPLOGGING_TEST_SOURCE_FILES )


# test # test
If ( HAS_CMAKE_TESTS ) 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 ( ) Else ( )
Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) Add_Test ( NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
EndIf ( ) EndIf ( )


Carregando…
Cancelar
Guardar