|
pred@2224
|
1 |
/** |
|
pred@2224
|
2 |
* vim: set ts=4 : |
|
pred@2224
|
3 |
* ============================================================================= |
|
pred@2224
|
4 |
* SourceMod Sample Extension |
|
pred@2224
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
pred@2224
|
6 |
* ============================================================================= |
|
pred@2224
|
7 |
* |
|
pred@2224
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
pred@2224
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
pred@2224
|
10 |
* Free Software Foundation. |
|
pred@2224
|
11 |
* |
|
pred@2224
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
pred@2224
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
pred@2224
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
pred@2224
|
15 |
* details. |
|
pred@2224
|
16 |
* |
|
pred@2224
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
pred@2224
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
pred@2224
|
19 |
* |
|
pred@2224
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
pred@2224
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
pred@2224
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
pred@2224
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
pred@2224
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
pred@2224
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
pred@2224
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
pred@2224
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
pred@2224
|
28 |
* |
|
pred@2224
|
29 |
* Version: $Id$ |
|
pred@2224
|
30 |
*/ |
|
pred@2224
|
31 |
|
|
pred@2224
|
32 |
#include "StructManager.h" |
|
pred@2224
|
33 |
#include "extension.h" |
|
pred@2224
|
34 |
|
|
pred@2224
|
35 |
StructManager g_StructManager; |
|
pred@2224
|
36 |
|
|
pred@2224
|
37 |
void StructManager::AddStruct( const char *name, StructInfo *str ) |
|
pred@2224
|
38 |
{ |
|
pred@2224
|
39 |
structs.insert(name, str); |
|
pred@2224
|
40 |
structsList.push_back(str); |
|
pred@2224
|
41 |
} |
|
pred@2224
|
42 |
|
|
pred@2224
|
43 |
StructManager::~StructManager() |
|
pred@2224
|
44 |
{ |
|
pred@2224
|
45 |
SourceHook::List<StructInfo *>::iterator iter; |
|
pred@2224
|
46 |
|
|
pred@2224
|
47 |
iter = structsList.begin(); |
|
pred@2224
|
48 |
|
|
pred@2224
|
49 |
while (iter != structsList.end()) |
|
pred@2224
|
50 |
{ |
|
pred@2224
|
51 |
delete (MemberInfo *)*iter; |
|
pred@2224
|
52 |
iter = structsList.erase(iter); |
|
pred@2224
|
53 |
} |
|
pred@2224
|
54 |
|
|
pred@2224
|
55 |
structs.clear(); |
|
pred@2224
|
56 |
} |
|
pred@2224
|
57 |
|
|
pred@2224
|
58 |
Handle_t StructManager::CreateStructHandle( const char *type, void *str ) |
|
pred@2224
|
59 |
{ |
|
pred@2224
|
60 |
StructInfo **pInfo = structs.retrieve(type); |
|
pred@2224
|
61 |
|
|
pred@2224
|
62 |
if (pInfo == NULL) |
|
pred@2224
|
63 |
{ |
|
pred@2224
|
64 |
return BAD_HANDLE; |
|
pred@2224
|
65 |
} |
|
pred@2224
|
66 |
|
|
pred@2224
|
67 |
StructHandle *pHandle = new StructHandle; |
|
pred@2224
|
68 |
|
|
pred@2224
|
69 |
pHandle->canDelete = false; |
|
pred@2224
|
70 |
pHandle->data = str; |
|
pred@2224
|
71 |
pHandle->info = *pInfo; |
|
pred@2224
|
72 |
|
|
pred@2224
|
73 |
return handlesys->CreateHandle(g_StructHandle, |
|
pred@2224
|
74 |
pHandle, |
|
pred@2224
|
75 |
NULL, |
|
pred@2224
|
76 |
myself->GetIdentity(), |
|
pred@2224
|
77 |
NULL); |
|
pred@2224
|
78 |
} |