#pragma once namespace Framework { template< class A, class B > class Pair { private: A *va; B *vb; int ref; public: Pair() { ref = 1; va = 0; vb = 0; } Pair( A *a, B *b ) { ref = 1; va = a; vb = b; } ~Pair() { if( va ) va->release(); if( vb ) vb->release(); } A *getFirst() { return va ? va->getThis() : 0; } A *zFirst() { return va; } B *getSecond() { return vb ? 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; } Pair *getThis() { ref++; return this; } Pair *release() { if( !--ref ) delete this; return 0; } }; }