Swapping support added to SizeNotifiable.

This commit is contained in:
King_DuckZ 2014-03-26 10:42:43 +01:00
parent 79fbf0faf7
commit 4d9190b0db
2 changed files with 30 additions and 1 deletions

View file

@ -3,6 +3,7 @@
#include "sdlmain.hpp"
#include <cassert>
#include <ciso646>
#include <algorithm>
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

View file

@ -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 <class RegisterBehaviour>
@ -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