Swapping support added to SizeNotifiable.
This commit is contained in:
parent
79fbf0faf7
commit
4d9190b0db
2 changed files with 30 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "sdlmain.hpp"
|
#include "sdlmain.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace cloonel {
|
namespace cloonel {
|
||||||
namespace implem {
|
namespace implem {
|
||||||
|
@ -30,6 +31,16 @@ namespace cloonel {
|
||||||
assert(m_sdlmain);
|
assert(m_sdlmain);
|
||||||
m_sdlmain->UnregisterForResChange(m_id);
|
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
|
} //namespace regbehaviuors
|
||||||
|
|
||||||
///--------------------------------------------------------------------------
|
///--------------------------------------------------------------------------
|
||||||
|
@ -37,4 +48,11 @@ namespace cloonel {
|
||||||
void SizeNotifiableBase::NotifyResChanged (const SizeRatio& parSize) {
|
void SizeNotifiableBase::NotifyResChanged (const SizeRatio& parSize) {
|
||||||
m_scaleRatio = parSize.Ratio();
|
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
|
} //namespace cloonel
|
||||||
|
|
|
@ -38,6 +38,7 @@ namespace cloonel {
|
||||||
|
|
||||||
void Register ( SizeNotifiableBase* ) const noexcept { return; }
|
void Register ( SizeNotifiableBase* ) const noexcept { return; }
|
||||||
void Unregister ( void ) const noexcept { return; }
|
void Unregister ( void ) const noexcept { return; }
|
||||||
|
void Swap ( DontRegister& ) noexcept { return; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class AutoRegister {
|
class AutoRegister {
|
||||||
|
@ -55,9 +56,10 @@ namespace cloonel {
|
||||||
|
|
||||||
void Register ( SizeNotifiableBase* parNotifiable );
|
void Register ( SizeNotifiableBase* parNotifiable );
|
||||||
void Unregister ( void ) noexcept;
|
void Unregister ( void ) noexcept;
|
||||||
|
void Swap ( AutoRegister& parOther ) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDLMain* const m_sdlmain;
|
SDLMain* m_sdlmain;
|
||||||
size_t m_id;
|
size_t m_id;
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
bool m_registered;
|
bool m_registered;
|
||||||
|
@ -71,12 +73,17 @@ namespace cloonel {
|
||||||
class SizeNotifiableBase {
|
class SizeNotifiableBase {
|
||||||
protected:
|
protected:
|
||||||
SizeNotifiableBase ( void ) = default;
|
SizeNotifiableBase ( void ) = default;
|
||||||
|
SizeNotifiableBase ( const SizeNotifiableBase& ) = delete;
|
||||||
virtual ~SizeNotifiableBase ( void ) noexcept = default;
|
virtual ~SizeNotifiableBase ( void ) noexcept = default;
|
||||||
|
SizeNotifiableBase& operator= ( const SizeNotifiableBase& ) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void NotifyResChanged ( const SizeRatio& parSize );
|
virtual void NotifyResChanged ( const SizeRatio& parSize );
|
||||||
const float2& Ratio ( void ) const noexcept { return m_scaleRatio; }
|
const float2& Ratio ( void ) const noexcept { return m_scaleRatio; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void swap ( SizeNotifiableBase& parOther ) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float2 m_scaleRatio;
|
float2 m_scaleRatio;
|
||||||
};
|
};
|
||||||
|
@ -94,6 +101,8 @@ namespace cloonel {
|
||||||
virtual ~SizeNotifiable ( void ) noexcept {
|
virtual ~SizeNotifiable ( void ) noexcept {
|
||||||
this->Unregister();
|
this->Unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void swap ( SizeNotifiable& parOther ) noexcept { SizeNotifiableBase::swap(parOther); RegisterBehaviour::swap(parOther); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class RegisterBehaviour>
|
template <class RegisterBehaviour>
|
||||||
|
@ -108,6 +117,8 @@ namespace cloonel {
|
||||||
virtual ~SizeNotifiable ( void ) noexcept {
|
virtual ~SizeNotifiable ( void ) noexcept {
|
||||||
this->Unregister();
|
this->Unregister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void swap ( SizeNotifiable& parOther ) noexcept { SizeNotifiableBase::swap(parOther); RegisterBehaviour::swap(parOther); }
|
||||||
};
|
};
|
||||||
} //namespace cloonel
|
} //namespace cloonel
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue