Skip to content

Commit

Permalink
clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Apr 28, 2023
1 parent 79d5ffa commit 22a7c30
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Expand Up @@ -29,6 +29,7 @@ Checks: >-
performance-*,
readability-*,
-readability-avoid-const-params-in-decls,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-magic-numbers,
Expand Down
30 changes: 15 additions & 15 deletions include/tao/json/cbor/events/to_stream.hpp
Expand Up @@ -34,35 +34,35 @@ namespace tao::json::cbor::events

void null()
{
os.put( char( std::uint8_t( internal::major::OTHER ) + 22 ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OTHER ) + 22 ) );
}

void boolean( const bool v )
{
os.put( char( std::uint8_t( internal::major::OTHER ) + 20 + std::uint8_t( v ) ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OTHER ) + 20 + static_cast< std::uint8_t >( v ) ) );
}

void number( const internal::major m, const std::uint64_t v )
{
if( v < 24 ) {
os.put( char( std::uint8_t( m ) + v ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + v ) );
}
else if( v < 256 ) {
os.put( char( std::uint8_t( m ) + 24 ) );
os.put( char( v ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 24 ) );
os.put( static_cast< char >( v ) );
}
else if( v < 65536 ) {
os.put( char( std::uint8_t( m ) + 25 ) );
const std::uint16_t x = json::internal::h_to_be( std::uint16_t( v ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 25 ) );
const std::uint16_t x = json::internal::h_to_be( static_cast< std::uint16_t >( v ) );
os.write( reinterpret_cast< const char* >( &x ), sizeof( x ) );
}
else if( v < 4294967296ULL ) {
os.put( char( std::uint8_t( m ) + 26 ) );
const std::uint32_t x = json::internal::h_to_be( std::uint32_t( v ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 26 ) );
const std::uint32_t x = json::internal::h_to_be( static_cast< std::uint32_t >( v ) );
os.write( reinterpret_cast< const char* >( &x ), sizeof( x ) );
}
else {
os.put( char( std::uint8_t( m ) + 27 ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( m ) + 27 ) );
const std::uint64_t x = json::internal::h_to_be( v );
os.write( reinterpret_cast< const char* >( &x ), sizeof( x ) );
}
Expand All @@ -88,7 +88,7 @@ namespace tao::json::cbor::events
std::uint64_t n;
std::memcpy( &n, &v, sizeof( n ) );
n = json::internal::h_to_be( n );
os.put( char( std::uint8_t( internal::major::OTHER ) + 27 ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OTHER ) + 27 ) );
os.write( reinterpret_cast< const char* >( &n ), sizeof( n ) );
}

Expand All @@ -106,7 +106,7 @@ namespace tao::json::cbor::events

void begin_array()
{
os.put( char( std::uint8_t( internal::major::ARRAY ) + internal::minor_mask ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::ARRAY ) + internal::minor_mask ) );
}

void begin_array( const std::size_t size )
Expand All @@ -119,15 +119,15 @@ namespace tao::json::cbor::events

void end_array()
{
os.put( char( 0xff ) );
os.put( static_cast< char >( 0xff ) );
}

void end_array( const std::size_t /*unused*/ ) noexcept
{}

void begin_object()
{
os.put( char( std::uint8_t( internal::major::OBJECT ) + internal::minor_mask ) );
os.put( static_cast< char >( static_cast< std::uint8_t >( internal::major::OBJECT ) + internal::minor_mask ) );
}

void begin_object( const std::size_t size )
Expand All @@ -145,7 +145,7 @@ namespace tao::json::cbor::events

void end_object()
{
os.put( char( 0xff ) );
os.put( static_cast< char >( 0xff ) );
}

void end_object( const std::size_t /*unused*/ ) noexcept
Expand Down
25 changes: 12 additions & 13 deletions include/tao/json/cbor/parts_parser.hpp
Expand Up @@ -62,10 +62,10 @@ namespace tao::json::cbor
{
const auto b = json::internal::peek_uint8( in );
switch( b ) {
case std::uint8_t( major::OTHER ) + 20:
case std::uint8_t( major::OTHER ) + 21:
case static_cast< std::uint8_t >( major::OTHER ) + 20:
case static_cast< std::uint8_t >( major::OTHER ) + 21:
in.bump_in_this_line( 1 );
return bool( b - std::uint8_t( major::OTHER ) - 20 );
return static_cast< bool >( b - static_cast< std::uint8_t >( major::OTHER ) - 20 );
default:
throw pegtl::parse_error( "expected boolean", in );
}
Expand All @@ -84,8 +84,7 @@ namespace tao::json::cbor
template< typename... Ts >
explicit basic_parts_parser( Ts&&... ts )
: m_input( std::forward< Ts >( ts )... )
{
}
{}

[[nodiscard]] bool empty()
{
Expand All @@ -94,7 +93,7 @@ namespace tao::json::cbor

[[nodiscard]] bool null()
{
if( json::internal::peek_uint8( m_input ) == std::uint8_t( internal::major::OTHER ) + 22 ) {
if( json::internal::peek_uint8( m_input ) == static_cast< std::uint8_t >( internal::major::OTHER ) + 22 ) {
m_input.bump_in_this_line( 1 );
return true;
}
Expand Down Expand Up @@ -144,7 +143,7 @@ namespace tao::json::cbor
[[nodiscard]] std::string_view string_view()
{
const auto b = json::internal::peek_uint8( m_input );
if( b != std::uint8_t( internal::major::STRING ) + internal::minor_mask ) {
if( b != static_cast< std::uint8_t >( internal::major::STRING ) + internal::minor_mask ) {
throw pegtl::parse_error( "expected definitive string", m_input );
}
return internal::read_string_1< V, std::string_view >( m_input );
Expand All @@ -153,7 +152,7 @@ namespace tao::json::cbor
[[nodiscard]] tao::binary_view binary_view()
{
const auto b = json::internal::peek_uint8( m_input );
if( b != std::uint8_t( internal::major::BINARY ) + internal::minor_mask ) {
if( b != static_cast< std::uint8_t >( internal::major::BINARY ) + internal::minor_mask ) {
throw pegtl::parse_error( "expected definitive binary", m_input );
}
return internal::read_string_1< utf8_mode::trust, tao::binary_view >( m_input );
Expand All @@ -171,7 +170,7 @@ namespace tao::json::cbor
if( u > 9223372036854775807ULL ) {
throw pegtl::parse_error( "positive integer overflow", m_input );
}
return std::int64_t( u );
return static_cast< std::int64_t >( u );
}

[[nodiscard]] std::int64_t number_signed_negative()
Expand All @@ -180,7 +179,7 @@ namespace tao::json::cbor
if( u > 9223372036854775808ULL ) {
throw pegtl::parse_error( "negative integer overflow", m_input );
}
return std::int64_t( ~u );
return static_cast< std::int64_t >( ~u );
}

#if defined( _MSC_VER )
Expand Down Expand Up @@ -215,11 +214,11 @@ namespace tao::json::cbor
{
const auto b = json::internal::peek_uint8( m_input );
switch( b ) {
case std::uint8_t( internal::major::OTHER ) + 25:
case static_cast< std::uint8_t >( internal::major::OTHER ) + 25:
return internal::read_fp16( m_input );
case std::uint8_t( internal::major::OTHER ) + 26:
case static_cast< std::uint8_t >( internal::major::OTHER ) + 26:
return json::internal::read_big_endian_number< float >( m_input + 1 );
case std::uint8_t( internal::major::OTHER ) + 27:
case static_cast< std::uint8_t >( internal::major::OTHER ) + 27:
return json::internal::read_big_endian_number< double >( m_input + 1 );
default:
throw pegtl::parse_error( "expected floating point number", m_input );
Expand Down
1 change: 1 addition & 0 deletions include/tao/json/contrib/deque_traits.hpp
Expand Up @@ -5,6 +5,7 @@
#define TAO_JSON_CONTRIB_DEQUE_TRAITS_HPP

#include <deque>
#include <vector>

#include "../consume.hpp"
#include "../forward.hpp"
Expand Down

0 comments on commit 22a7c30

Please sign in to comment.