Move semantics in SizeNotifiable.
This commit is contained in:
parent
6fe884cd5a
commit
2a4ae78374
4 changed files with 40 additions and 22 deletions
|
@ -33,6 +33,16 @@ namespace cloonel {
|
|||
assert(m_surface);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
Platform::Platform (Platform&& parOther) :
|
||||
m_screenRatio(std::move(parOther.m_screenRatio)),
|
||||
m_position(parOther.m_position),
|
||||
m_size(parOther.m_size),
|
||||
m_surface(parOther.m_surface)
|
||||
{
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void Platform::Draw() const {
|
||||
|
|
|
@ -30,8 +30,10 @@ namespace cloonel {
|
|||
class Platform : public Drawable {
|
||||
public:
|
||||
Platform ( SDLMain* parSdlMain, const float2& parPos, Texture* parTexture, const float2& parSize );
|
||||
Platform ( Platform&& parOther );
|
||||
Platform ( const Platform& ) = delete;
|
||||
virtual ~Platform ( void ) noexcept = default;
|
||||
Platform& operator= ( Platform&& parOther );
|
||||
Platform& operator= ( Platform&& parOther ) = delete;
|
||||
|
||||
virtual void Draw ( void ) const;
|
||||
|
||||
|
|
|
@ -25,16 +25,24 @@ namespace cloonel {
|
|||
///----------------------------------------------------------------------
|
||||
void AutoRegister::Unregister() noexcept {
|
||||
#if !defined(NDEBUG)
|
||||
assert(m_registered);
|
||||
assert(m_registered or not m_sdlmain);
|
||||
m_registered = false;
|
||||
#endif
|
||||
assert(m_sdlmain);
|
||||
m_sdlmain->UnregisterForResChange(m_id);
|
||||
if (m_registered) {
|
||||
assert(m_sdlmain);
|
||||
m_sdlmain->UnregisterForResChange(m_id);
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------
|
||||
///----------------------------------------------------------------------
|
||||
void AutoRegister::Swap (AutoRegister& parOther) noexcept {
|
||||
AutoRegister::AutoRegister (AutoRegister&& parOther) :
|
||||
m_sdlmain(nullptr),
|
||||
m_id(0)
|
||||
#if !defined(NDEBUG)
|
||||
, m_registered(false)
|
||||
#endif
|
||||
{
|
||||
std::swap(m_sdlmain, parOther.m_sdlmain);
|
||||
std::swap(m_id, parOther.m_id);
|
||||
#if !defined(NDEBUG)
|
||||
|
@ -48,11 +56,4 @@ namespace cloonel {
|
|||
void SizeNotifiableBase::NotifyResChanged (const SizeRatio& parSize) {
|
||||
m_scaleRatio = parSize.Ratio();
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void SizeNotifiableBase::swap (SizeNotifiableBase& parOther) noexcept {
|
||||
std::swap(m_scaleRatio.x(), parOther.m_scaleRatio.x());
|
||||
std::swap(m_scaleRatio.y(), parOther.m_scaleRatio.y());
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -34,17 +34,18 @@ namespace cloonel {
|
|||
enum { SDLMAIN_NEEDED = false };
|
||||
|
||||
DontRegister ( void ) = default;
|
||||
DontRegister ( DontRegister&& ) { }
|
||||
~DontRegister ( void ) noexcept = default;
|
||||
|
||||
void Register ( SizeNotifiableBase* ) const noexcept { return; }
|
||||
void Unregister ( void ) const noexcept { return; }
|
||||
void Swap ( DontRegister& ) noexcept { return; }
|
||||
};
|
||||
|
||||
class AutoRegister {
|
||||
public:
|
||||
enum { SDLMAIN_NEEDED = true };
|
||||
|
||||
AutoRegister ( AutoRegister&& parOther );
|
||||
explicit AutoRegister ( SDLMain* parMain ) :
|
||||
m_sdlmain(parMain)
|
||||
#if !defined(NDEBUG)
|
||||
|
@ -56,7 +57,6 @@ namespace cloonel {
|
|||
|
||||
void Register ( SizeNotifiableBase* parNotifiable );
|
||||
void Unregister ( void ) noexcept;
|
||||
void Swap ( AutoRegister& parOther ) noexcept;
|
||||
|
||||
private:
|
||||
SDLMain* m_sdlmain;
|
||||
|
@ -73,7 +73,7 @@ namespace cloonel {
|
|||
class SizeNotifiableBase {
|
||||
protected:
|
||||
SizeNotifiableBase ( void ) = default;
|
||||
SizeNotifiableBase ( const SizeNotifiableBase& ) = delete;
|
||||
SizeNotifiableBase ( const SizeNotifiableBase& ) = default;
|
||||
virtual ~SizeNotifiableBase ( void ) noexcept = default;
|
||||
SizeNotifiableBase& operator= ( const SizeNotifiableBase& ) = delete;
|
||||
|
||||
|
@ -81,9 +81,6 @@ namespace cloonel {
|
|||
virtual void NotifyResChanged ( const SizeRatio& parSize );
|
||||
const float2& Ratio ( void ) const noexcept { return m_scaleRatio; }
|
||||
|
||||
protected:
|
||||
void swap ( SizeNotifiableBase& parOther ) noexcept;
|
||||
|
||||
private:
|
||||
float2 m_scaleRatio;
|
||||
};
|
||||
|
@ -95,20 +92,30 @@ namespace cloonel {
|
|||
class SizeNotifiable<RegisterBehaviour, false> : private RegisterBehaviour, public SizeNotifiableBase {
|
||||
static_assert(RegisterBehaviour::SDLMAIN_NEEDED == false, "SdlMainNeeded mismatches expected value");
|
||||
public:
|
||||
SizeNotifiable ( const SizeNotifiable& ) = delete;
|
||||
SizeNotifiable ( SizeNotifiable&& parOther ) :
|
||||
RegisterBehaviour(parOther),
|
||||
SizeNotifiableBase(parOther)
|
||||
{
|
||||
}
|
||||
SizeNotifiable ( void ) {
|
||||
this->Register(this);
|
||||
}
|
||||
virtual ~SizeNotifiable ( void ) noexcept {
|
||||
this->Unregister();
|
||||
}
|
||||
|
||||
void swap ( SizeNotifiable& parOther ) noexcept { SizeNotifiableBase::swap(parOther); RegisterBehaviour::swap(parOther); }
|
||||
};
|
||||
|
||||
template <class RegisterBehaviour>
|
||||
class SizeNotifiable<RegisterBehaviour, true> : private RegisterBehaviour, public SizeNotifiableBase {
|
||||
static_assert(RegisterBehaviour::SDLMAIN_NEEDED == true, "SdlMainNeeded mismatches expected value");
|
||||
public:
|
||||
SizeNotifiable ( const SizeNotifiable& ) = delete;
|
||||
SizeNotifiable ( SizeNotifiable&& parOther ) :
|
||||
RegisterBehaviour(std::move(parOther)),
|
||||
SizeNotifiableBase(parOther)
|
||||
{
|
||||
}
|
||||
explicit SizeNotifiable ( SDLMain* parSdlMain ) :
|
||||
RegisterBehaviour(parSdlMain)
|
||||
{
|
||||
|
@ -117,8 +124,6 @@ namespace cloonel {
|
|||
virtual ~SizeNotifiable ( void ) noexcept {
|
||||
this->Unregister();
|
||||
}
|
||||
|
||||
void swap ( SizeNotifiable& parOther ) noexcept { SizeNotifiableBase::swap(parOther); RegisterBehaviour::swap(parOther); }
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
|
|
Loading…
Reference in a new issue