2017-11-01 20:14:23 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
/* REGISTRATION SUPPORT - INLINE CODE *****************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-12-23 18:29:11 +01:00
|
|
|
#ifndef _H_EBCL_INLINE_REGISTRATION
|
|
|
|
#define _H_EBCL_INLINE_REGISTRATION
|
|
|
|
#include <ebcl/Registration.hh>
|
|
|
|
namespace ebcl {
|
2017-11-01 20:14:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*= T_RegisteredItem ============================================================*/
|
|
|
|
|
|
|
|
inline T_RegisteredItem::T_RegisteredItem( ) noexcept
|
|
|
|
: automatic_( false ) , unregisterFunction_( ) ,
|
|
|
|
data_( nullptr ) , dataDestructor_( )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
inline T_RegisteredItem::T_RegisteredItem(
|
|
|
|
SP_Unregister& unregisterFunction ,
|
|
|
|
void* data ,
|
|
|
|
F_Destructor_ destructor ) noexcept
|
|
|
|
: automatic_( true ) , unregisterFunction_( unregisterFunction ) ,
|
|
|
|
data_( data ) , dataDestructor_( destructor )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
inline T_RegisteredItem::T_RegisteredItem(
|
|
|
|
SP_Unregister& unregisterFunction ,
|
|
|
|
T* data ) noexcept
|
|
|
|
: T_RegisteredItem( unregisterFunction , data ,
|
|
|
|
[]( void* d ) {
|
|
|
|
reinterpret_cast< T* >( d )->~T( );
|
|
|
|
::operator delete( d );
|
|
|
|
} )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template< >
|
|
|
|
inline T_RegisteredItem::T_RegisteredItem(
|
|
|
|
SP_Unregister& unregisterFunction ,
|
|
|
|
void* data ) noexcept
|
|
|
|
: T_RegisteredItem( unregisterFunction , data , [](void*){} )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
inline T_RegisteredItem::~T_RegisteredItem( )
|
|
|
|
{
|
|
|
|
clear( );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
inline T_RegisteredItem::T_RegisteredItem(
|
|
|
|
T_RegisteredItem&& other ) noexcept
|
|
|
|
: T_RegisteredItem( )
|
|
|
|
{
|
|
|
|
swap( *this , other );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline T_RegisteredItem& T_RegisteredItem::operator =(
|
|
|
|
T_RegisteredItem&& other ) noexcept
|
|
|
|
{
|
|
|
|
clear( );
|
|
|
|
swap( *this , other );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline M_DECLARE_SWAP( T_RegisteredItem )
|
|
|
|
{
|
|
|
|
using std::swap;
|
|
|
|
swap( lhs.automatic_ , rhs.automatic_ );
|
|
|
|
swap( lhs.unregisterFunction_ , rhs.unregisterFunction_ );
|
|
|
|
swap( lhs.data_ , rhs.data_ );
|
|
|
|
swap( lhs.dataDestructor_ , rhs.dataDestructor_ );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
inline void T_RegisteredItem::automatic(
|
|
|
|
const bool v ) noexcept
|
|
|
|
{
|
|
|
|
automatic_ = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool T_RegisteredItem::automatic( ) const noexcept
|
|
|
|
{
|
|
|
|
return automatic_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
inline void T_RegisteredItem::unregister( ) noexcept
|
|
|
|
{
|
|
|
|
if ( data_ && unregisterFunction_ ) {
|
|
|
|
(*unregisterFunction_)( data_ );
|
|
|
|
deleteData( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline T_RegisteredItem::operator bool( ) const noexcept
|
|
|
|
{
|
|
|
|
return bool( data_ );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void T_RegisteredItem::clear( ) noexcept
|
|
|
|
{
|
|
|
|
if ( automatic_ ) {
|
|
|
|
unregister( );
|
|
|
|
} else {
|
|
|
|
deleteData( );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void T_RegisteredItem::deleteData( ) noexcept
|
|
|
|
{
|
|
|
|
if ( data_ != nullptr ) {
|
|
|
|
if ( dataDestructor_ ) {
|
|
|
|
dataDestructor_( data_ );
|
|
|
|
}
|
|
|
|
data_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-23 18:29:11 +01:00
|
|
|
} // namespace
|
|
|
|
#endif // _H_EBCL_INLINE_REGISTRATION
|