#pragma once


namespace mof
{
    
    
    //TODO コンテナに代入できないようにする
    class Finalizer 
    {
        mutable void (*m_finalize)( );
        
        public:
        Finalizer( )
        : m_finalize(NULL)
        {
            // do nothing
        }
        
        Finalizer( void (*finalize_)() )
        : m_finalize(finalize_)
        {
            // do nothing
        }
        
        Finalizer( const Finalizer& obj){
            if( this == &obj)return;
            m_finalize = obj.m_finalize;
            obj.m_finalize = NULL;
        }
        
        ~Finalizer( )
        {
            if( m_finalize )m_finalize();
        }
        
        void cancel( )
        {
            m_finalize = NULL;
        }
        
        Finalizer& operator = ( const Finalizer& obj )
        {
            if( this == &obj)return *this;
            if( m_finalize )m_finalize();
            m_finalize = obj.m_finalize;
            obj.m_finalize = NULL;
            return *this;
        }
        
        
    };
}