Skip to content

Commit

Permalink
Fix some code smells (#9276)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-derevenetz authored Nov 18, 2024
1 parent b1b5357 commit ff3337c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 93 deletions.
46 changes: 2 additions & 44 deletions src/engine/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@ namespace
const size_t minBufferCapacity = 1024;
}

StreamBase::StreamBase( StreamBase && stream ) noexcept
{
std::swap( _flags, stream._flags );
}

StreamBase & StreamBase::operator=( StreamBase && stream ) noexcept
{
if ( this == &stream ) {
return *this;
}

std::swap( _flags, stream._flags );

return *this;
}

void StreamBase::setBigendian( bool f )
{
if ( f ) {
Expand All @@ -72,17 +56,6 @@ void StreamBase::setFail( bool f )
}
}

IStreamBase & IStreamBase::operator=( IStreamBase && stream ) noexcept
{
if ( this == &stream ) {
return *this;
}

StreamBase::operator=( std::move( stream ) );

return *this;
}

uint16_t IStreamBase::get16()
{
return bigendian() ? getBE16() : getLE16();
Expand Down Expand Up @@ -253,21 +226,6 @@ RWStreamBuf::RWStreamBuf( const size_t size )
setBigendian( IS_BIGENDIAN );
}

RWStreamBuf & RWStreamBuf::operator=( RWStreamBuf && stream ) noexcept
{
if ( this == &stream ) {
return *this;
}

// Only the StreamBufTmpl move assignment operator should be called to avoid multiple calls
// of the StreamBase move assignment operator due to the multiple inheritance scheme
StreamBufTmpl::operator=( std::move( stream ) );

std::swap( _buf, stream._buf );

return *this;
}

void RWStreamBuf::putBE16( uint16_t v )
{
put8( v >> 8 );
Expand Down Expand Up @@ -336,14 +294,14 @@ void RWStreamBuf::put8( const uint8_t v )
++_itput;
}

size_t RWStreamBuf::tellp()
size_t RWStreamBuf::tellp() const
{
assert( _itbeg <= _itput );

return _itput - _itbeg;
}

size_t RWStreamBuf::sizep()
size_t RWStreamBuf::sizep() const
{
assert( _itput <= _itend );

Expand Down
56 changes: 7 additions & 49 deletions src/engine/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ class StreamBase
protected:
StreamBase() = default;

StreamBase( StreamBase && stream ) noexcept;

StreamBase & operator=( StreamBase && stream ) noexcept;

void setFail( bool f );

private:
Expand Down Expand Up @@ -268,15 +264,6 @@ class IStreamBase : virtual public StreamBase
protected:
IStreamBase() = default;

IStreamBase( IStreamBase && ) = default;

// All this operator does is call the corresponding base class operator. It is not recommended to
// declare these operators as default in the case of a virtual base, even if they are trivial, to
// catch a situation where, in the case of the diamond inheritance, the corresponding operator of
// the base class will be called multiple times. GCC has a special warning for this case (see the
// description of the -Wno-virtual-move-assign switch).
IStreamBase & operator=( IStreamBase && stream ) noexcept;

virtual uint8_t get8() = 0;
};

Expand Down Expand Up @@ -372,8 +359,6 @@ class OStreamBase : virtual public StreamBase
protected:
OStreamBase() = default;

OStreamBase( OStreamBase && ) = default;

virtual void put8( const uint8_t ) = 0;
};

Expand All @@ -382,7 +367,7 @@ class IStreamBuf : public IStreamBase
{
public:
virtual const uint8_t * data() const = 0;
virtual size_t size() = 0;
virtual size_t size() const = 0;

protected:
IStreamBuf() = default;
Expand All @@ -404,12 +389,12 @@ class StreamBufTmpl : public IStreamBuf
return _itget;
}

size_t size() override
size_t size() const override
{
return sizeg();
}

size_t tell()
size_t tell() const
{
return tellg();
}
Expand Down Expand Up @@ -501,39 +486,14 @@ class StreamBufTmpl : public IStreamBuf
protected:
StreamBufTmpl() = default;

StreamBufTmpl( StreamBufTmpl && stream ) noexcept
: IStreamBuf( std::move( stream ) )
{
std::swap( _itbeg, stream._itbeg );
std::swap( _itget, stream._itget );
std::swap( _itput, stream._itput );
std::swap( _itend, stream._itend );
}

StreamBufTmpl & operator=( StreamBufTmpl && stream ) noexcept
{
if ( this == &stream ) {
return *this;
}

IStreamBuf::operator=( std::move( stream ) );

std::swap( _itbeg, stream._itbeg );
std::swap( _itget, stream._itget );
std::swap( _itput, stream._itput );
std::swap( _itend, stream._itend );

return *this;
}

size_t sizeg()
size_t sizeg() const
{
assert( _itget <= _itput );

return _itput - _itget;
}

size_t tellg()
size_t tellg() const
{
assert( _itbeg <= _itget );

Expand Down Expand Up @@ -575,12 +535,10 @@ class RWStreamBuf final : public StreamBufTmpl<uint8_t>, public OStreamBase
explicit RWStreamBuf( const size_t size );

RWStreamBuf( const RWStreamBuf & ) = delete;
RWStreamBuf( RWStreamBuf && ) = default;

~RWStreamBuf() override = default;

RWStreamBuf & operator=( const RWStreamBuf & ) = delete;
RWStreamBuf & operator=( RWStreamBuf && stream ) noexcept;

void putBE32( uint32_t v ) override;
void putLE32( uint32_t v ) override;
Expand All @@ -592,8 +550,8 @@ class RWStreamBuf final : public StreamBufTmpl<uint8_t>, public OStreamBase
private:
void put8( const uint8_t v ) override;

size_t sizep();
size_t tellp();
size_t sizep() const;
size_t tellp() const;

void reallocBuf( size_t size );

Expand Down
6 changes: 6 additions & 0 deletions src/fheroes2/monster/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ class Monster
explicit Monster( const Spell & sp );
Monster( const int race, const uint32_t dw );

Monster( const Monster & ) = default;
Monster( Monster && ) = default;

virtual ~Monster() = default;

Monster & operator=( const Monster & ) = default;
Monster & operator=( Monster && ) = default;

bool operator==( const Monster & m ) const
{
return id == m.id;
Expand Down

0 comments on commit ff3337c

Please sign in to comment.