//========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============// // // Purpose: // // $NoKeywords: $ //=============================================================================// #ifndef EHANDLE_H #define EHANDLE_H #ifdef _WIN32 #pragma once #endif #include "entity2/entitysystem.h" #include "entityhandle.h" // -------------------------------------------------------------------------------------------------- // // Game-code CBaseHandle implementation. // -------------------------------------------------------------------------------------------------- // inline CEntityInstance* CEntityHandle::Get() const { extern CEntitySystem *g_pEntitySystem; return g_pEntitySystem->GetBaseEntity( *this ); } // -------------------------------------------------------------------------------------------------- // // CHandle. // -------------------------------------------------------------------------------------------------- // template< class T > class CHandle : public CEntityHandle { public: CHandle(); CHandle( int iEntry, int iSerialNumber ); CHandle( const CBaseHandle &handle ); CHandle( T *pVal ); // The index should have come from a call to ToInt(). If it hasn't, you're in trouble. static CHandle FromIndex( int index ); T* Get() const; void Set( const T* pVal ); operator T*(); operator T*() const; bool operator !() const; bool operator==( T *val ) const; bool operator!=( T *val ) const; const CBaseHandle& operator=( const T *val ); T* operator->() const; }; // ----------------------------------------------------------------------- // // Inlines. // ----------------------------------------------------------------------- // template CHandle::CHandle() { } template CHandle::CHandle( int iEntry, int iSerialNumber ) { Init( iEntry, iSerialNumber ); } template CHandle::CHandle( const CBaseHandle &handle ) : CBaseHandle( handle ) { } template CHandle::CHandle( T *pObj ) { Term(); Set( pObj ); } template inline CHandle CHandle::FromIndex( int index ) { CHandle ret; ret.m_Index = index; return ret; } template inline T* CHandle::Get() const { return (T*)CBaseHandle::Get(); } template inline CHandle::operator T *() { return Get( ); } template inline CHandle::operator T *() const { return Get( ); } template inline bool CHandle::operator !() const { return !Get(); } template inline bool CHandle::operator==( T *val ) const { return Get() == val; } template inline bool CHandle::operator!=( T *val ) const { return Get() != val; } template void CHandle::Set( const T* pVal ) { CBaseHandle::Set(pVal); } template inline const CBaseHandle& CHandle::operator=( const T *val ) { Set( val ); return *this; } template T* CHandle::operator -> () const { return Get(); } #endif // EHANDLE_H