forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathehandle.h
169 lines (127 loc) · 3.07 KB
/
ehandle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef EHANDLE_H
#define EHANDLE_H
#ifdef _WIN32
#pragma once
#endif
#if defined( _DEBUG ) && defined( GAME_DLL )
#include "tier0/dbg.h"
#include "cbase.h"
#endif
#include "const.h"
#include "basehandle.h"
#include "entitylist_base.h"
class IHandleEntity;
// -------------------------------------------------------------------------------------------------- //
// Game-code CBaseHandle implementation.
// -------------------------------------------------------------------------------------------------- //
inline IHandleEntity* CBaseHandle::Get() const
{
extern CBaseEntityList *g_pEntityList;
return g_pEntityList->LookupEntity( *this );
}
// -------------------------------------------------------------------------------------------------- //
// CHandle.
// -------------------------------------------------------------------------------------------------- //
template< class T >
class CHandle : public CBaseHandle
{
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<T> 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<class T>
CHandle<T>::CHandle()
{
}
template<class T>
CHandle<T>::CHandle( int iEntry, int iSerialNumber )
{
Init( iEntry, iSerialNumber );
}
template<class T>
CHandle<T>::CHandle( const CBaseHandle &handle )
: CBaseHandle( handle )
{
}
template<class T>
CHandle<T>::CHandle( T *pObj )
{
Term();
Set( pObj );
}
template<class T>
inline CHandle<T> CHandle<T>::FromIndex( int index )
{
CHandle<T> ret;
ret.m_Index = index;
return ret;
}
template<class T>
inline T* CHandle<T>::Get() const
{
return (T*)CBaseHandle::Get();
}
template<class T>
inline CHandle<T>::operator T *()
{
return Get( );
}
template<class T>
inline CHandle<T>::operator T *() const
{
return Get( );
}
template<class T>
inline bool CHandle<T>::operator !() const
{
return !Get();
}
template<class T>
inline bool CHandle<T>::operator==( T *val ) const
{
return Get() == val;
}
template<class T>
inline bool CHandle<T>::operator!=( T *val ) const
{
return Get() != val;
}
template<class T>
void CHandle<T>::Set( const T* pVal )
{
CBaseHandle::Set( reinterpret_cast<const IHandleEntity*>(pVal) );
}
template<class T>
inline const CBaseHandle& CHandle<T>::operator=( const T *val )
{
Set( val );
return *this;
}
template<class T>
T* CHandle<T>::operator -> () const
{
return Get();
}
#endif // EHANDLE_H