core/logic/NativeOwner.h
author Nicholas Hastings <skamonkey@gmail.com>
Wed Apr 23 21:40:50 2014 -0400 (2014-04-23)
changeset 4332 75c299312bec
parent 4109 10eb68d668af
permissions -rw-r--r--
Update CS:GO gamedata.
dvander@4107
     1
/**
dvander@4107
     2
 * vim: set ts=4 sw=4 tw=99 noet :
dvander@4107
     3
 * =============================================================================
dvander@4107
     4
 * SourcePawn
dvander@4107
     5
 * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
dvander@4107
     6
 * =============================================================================
dvander@4107
     7
 *
dvander@4107
     8
 * This program is free software; you can redistribute it and/or modify it under
dvander@4107
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
dvander@4107
    10
 * Free Software Foundation.
dvander@4107
    11
 * 
dvander@4107
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
dvander@4107
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@4107
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
dvander@4107
    15
 * details.
dvander@4107
    16
 *
dvander@4107
    17
 * You should have received a copy of the GNU General Public License along with
dvander@4107
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@4107
    19
 *
dvander@4107
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
dvander@4107
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
dvander@4107
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
dvander@4107
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
dvander@4107
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
dvander@4107
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
dvander@4107
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
dvander@4107
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@4107
    28
 *
dvander@4107
    29
 * Version: $Id$
dvander@4107
    30
 */
dvander@2088
    31
#ifndef _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
dvander@2088
    32
#define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
dvander@2088
    33
dvander@2088
    34
#include <sp_vm_types.h>
dvander@2088
    35
#include <sh_list.h>
dvander@4109
    36
#include <am-linkedlist.h>
dvander@4107
    37
#include <am-vector.h>
dvander@3872
    38
#include "common_logic.h"
dvander@4109
    39
#include "Native.h"
dvander@2088
    40
dvander@4109
    41
struct Native;
dvander@2088
    42
class CPlugin;
dvander@3872
    43
dvander@3872
    44
using namespace SourceMod;
dvander@2088
    45
dvander@2088
    46
struct WeakNative
dvander@2088
    47
{
dvander@3872
    48
	WeakNative(IPlugin *plugin, uint32_t index) : 
dvander@4109
    49
		pl(plugin), idx(index)
dvander@2088
    50
	{
dvander@2088
    51
		pl = plugin;
dvander@2088
    52
		idx = index;
dvander@2088
    53
	}
dvander@3872
    54
	IPlugin *pl;
dvander@2088
    55
	uint32_t idx;
dvander@2088
    56
};
dvander@2088
    57
dvander@2088
    58
using namespace SourceHook;
dvander@2088
    59
dvander@2088
    60
class CNativeOwner
dvander@2088
    61
{
dvander@2088
    62
public:
dvander@2226
    63
	CNativeOwner();
dvander@2226
    64
public:
dvander@2088
    65
	virtual void DropEverything();
dvander@2088
    66
public:
dvander@2088
    67
	void AddNatives(const sp_nativeinfo_t *info);
dvander@2088
    68
public:
dvander@2088
    69
	void SetMarkSerial(unsigned int serial);
dvander@2088
    70
	unsigned int GetMarkSerial();
dvander@3872
    71
	void PropagateMarkSerial(unsigned int serial);
dvander@2088
    72
public:
dvander@2088
    73
	void AddDependent(CPlugin *pPlugin);
dvander@2088
    74
	void AddWeakRef(const WeakNative & ref);
dvander@2088
    75
	void DropRefsTo(CPlugin *pPlugin);
dvander@2088
    76
private:
dvander@2088
    77
	void DropWeakRefsTo(CPlugin *pPlugin);
dvander@2088
    78
	void UnbindWeakRef(const WeakNative & ref);
dvander@2088
    79
protected:
dvander@2088
    80
	List<CPlugin *> m_Dependents;
dvander@2088
    81
	unsigned int m_nMarkSerial;
dvander@2088
    82
	List<WeakNative> m_WeakRefs;
dvander@4107
    83
	ke::Vector<const sp_nativeinfo_t *> m_natives;
dvander@4109
    84
	ke::Vector<ke::Ref<Native> > m_fakes;
dvander@2088
    85
};
dvander@2088
    86
dvander@3872
    87
extern CNativeOwner g_CoreNatives;
dvander@3872
    88
dvander@2088
    89
#endif //_INCLUDE_SOURCEMOD_NATIVE_OWNER_H_