core/sm_memtable.h
author Michael McKoy <ferret99gt@gmail.com>
Sat Nov 24 03:28:33 2007 +0000 (2007-11-24)
changeset 1719 c9d5e55f0899
parent 1330 ab94316bb52b
child 1766 d30c252089be
permissions -rw-r--r--
The current map played shouldn't appear in MapChooser votes or RTV votes now. It can still be nominated in RTV though.
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@370
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@370
    28
 *
dvander@370
    29
 * Version: $Id$
dvander@370
    30
 */
dvander@370
    31
dvander@203
    32
#ifndef _INCLUDE_SOURCEMOD_CORE_STRINGTABLE_H_
dvander@203
    33
#define _INCLUDE_SOURCEMOD_CORE_STRINGTABLE_H_
dvander@203
    34
dvander@203
    35
class BaseMemTable
dvander@203
    36
{
dvander@203
    37
public:
dvander@203
    38
	BaseMemTable(unsigned int init_size);
dvander@203
    39
	~BaseMemTable();
dvander@203
    40
public:
dvander@203
    41
	/**
dvander@203
    42
	 * Allocates 'size' bytes of memory.
dvander@203
    43
	 * Optionally outputs the address through 'addr'.
dvander@203
    44
	 * Returns an index >= 0 on success, < 0 on failure.
dvander@203
    45
	 */
dvander@203
    46
	int CreateMem(unsigned int size, void **addr);
dvander@203
    47
dvander@203
    48
	/**
dvander@203
    49
	 * Given an index into the memory table, returns its address.
dvander@203
    50
	 * Returns NULL if invalid.
dvander@203
    51
	 */
dvander@203
    52
	void *GetAddress(int index);
dvander@203
    53
dvander@203
    54
	/**
dvander@203
    55
	 * Scraps the memory table.  For caching purposes, the memory 
dvander@203
    56
	 * is not freed, however subsequent calls to CreateMem() will 
dvander@203
    57
	 * begin at the first index again.
dvander@203
    58
	 */
dvander@203
    59
	void Reset();
dvander@404
    60
dvander@404
    61
dvander@203
    62
private:
dvander@203
    63
	unsigned char *membase;
dvander@203
    64
	unsigned int size;
dvander@203
    65
	unsigned int tail;
dvander@203
    66
};
dvander@203
    67
dvander@203
    68
class BaseStringTable
dvander@203
    69
{
dvander@203
    70
public:
dvander@203
    71
	BaseStringTable(unsigned int init_size);
dvander@203
    72
	~BaseStringTable();
dvander@203
    73
public:
dvander@203
    74
	/** 
dvander@203
    75
	 * Adds a string to the string table and returns its index.
dvander@203
    76
	 */
dvander@203
    77
	int AddString(const char *string);
dvander@203
    78
dvander@203
    79
	/**
dvander@203
    80
	 * Given an index into the string table, returns the associated string.
dvander@203
    81
	 */
dvander@293
    82
	inline const char *GetString(int str)
dvander@293
    83
	{
dvander@293
    84
		return (const char *)m_table.GetAddress(str);
dvander@293
    85
	}
dvander@203
    86
dvander@203
    87
	/**
dvander@203
    88
	 * Scraps the string table.  For caching purposes, the memory
dvander@203
    89
	 * is not freed, however subsequent calls to AddString() will 
dvander@203
    90
	 * begin at the first index again.
dvander@203
    91
	 */
dvander@203
    92
	void Reset();
dvander@203
    93
dvander@203
    94
	/**
dvander@203
    95
	 * Returns the parent BaseMemTable that this string table uses.
dvander@203
    96
	 */
dvander@203
    97
	inline BaseMemTable *GetMemTable()
dvander@203
    98
	{
dvander@203
    99
		return &m_table;
dvander@203
   100
	}
dvander@203
   101
private:
dvander@203
   102
	BaseMemTable m_table;
dvander@203
   103
};
dvander@203
   104
dvander@203
   105
#endif //_INCLUDE_SOURCEMOD_CORE_STRINGTABLE_H_