#pragma once

#include "ReferenceCounter.h"

namespace Framework
{
    template< class A, class B >
    class Pair : public virtual ReferenceCounter
    {
    private:
        A *va;
        B *vb;

    public:
        Pair()
            : ReferenceCounter()
        {
            va = 0;
            vb = 0;
        }

        Pair( A *a, B *b )
            : ReferenceCounter()
        {
            va = a;
            vb = b;
        }

        ~Pair()
        {
            if( va )
                va->release();
            if( vb )
                vb->release();
        }

        A *getFirst()
        {
            return va ? dynamic_cast<A *>( va->getThis() ) : 0;
        }

        A *zFirst()
        {
            return va;
        }

        B *getSecond()
        {
            return vb ? dynamic_cast<B *>( vb->getThis() ) : 0;
        }

        B *zSecond()
        {
            return vb;
        }

        void setFirst( A *a )
        {
            if( va )
                va->release();
            va = a;
        }

        void setSecond( B *b )
        {
            if( vb )
                vb->release();
            vb = b;
        }
    };
}