diff --git a/src/sizenotifiable.cpp b/src/sizenotifiable.cpp index 88ebb7b..3ba17ad 100644 --- a/src/sizenotifiable.cpp +++ b/src/sizenotifiable.cpp @@ -3,6 +3,7 @@ #include "sdlmain.hpp" #include #include +#include namespace cloonel { namespace implem { @@ -30,6 +31,16 @@ namespace cloonel { assert(m_sdlmain); m_sdlmain->UnregisterForResChange(m_id); } + + ///---------------------------------------------------------------------- + ///---------------------------------------------------------------------- + void AutoRegister::Swap (AutoRegister& parOther) noexcept { + std::swap(m_sdlmain, parOther.m_sdlmain); + std::swap(m_id, parOther.m_id); +#if !defined(NDEBUG) + std::swap(m_registered, parOther.m_registered); +#endif + } } //namespace regbehaviuors ///-------------------------------------------------------------------------- @@ -37,4 +48,11 @@ 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 diff --git a/src/sizenotifiable.hpp b/src/sizenotifiable.hpp index a945f06..0dea646 100644 --- a/src/sizenotifiable.hpp +++ b/src/sizenotifiable.hpp @@ -38,6 +38,7 @@ namespace cloonel { void Register ( SizeNotifiableBase* ) const noexcept { return; } void Unregister ( void ) const noexcept { return; } + void Swap ( DontRegister& ) noexcept { return; } }; class AutoRegister { @@ -55,9 +56,10 @@ namespace cloonel { void Register ( SizeNotifiableBase* parNotifiable ); void Unregister ( void ) noexcept; + void Swap ( AutoRegister& parOther ) noexcept; private: - SDLMain* const m_sdlmain; + SDLMain* m_sdlmain; size_t m_id; #if !defined(NDEBUG) bool m_registered; @@ -71,12 +73,17 @@ namespace cloonel { class SizeNotifiableBase { protected: SizeNotifiableBase ( void ) = default; + SizeNotifiableBase ( const SizeNotifiableBase& ) = delete; virtual ~SizeNotifiableBase ( void ) noexcept = default; + SizeNotifiableBase& operator= ( const SizeNotifiableBase& ) = delete; public: 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; }; @@ -94,6 +101,8 @@ namespace cloonel { virtual ~SizeNotifiable ( void ) noexcept { this->Unregister(); } + + void swap ( SizeNotifiable& parOther ) noexcept { SizeNotifiableBase::swap(parOther); RegisterBehaviour::swap(parOther); } }; template @@ -108,6 +117,8 @@ namespace cloonel { virtual ~SizeNotifiable ( void ) noexcept { this->Unregister(); } + + void swap ( SizeNotifiable& parOther ) noexcept { SizeNotifiableBase::swap(parOther); RegisterBehaviour::swap(parOther); } }; } //namespace cloonel