2015-06-30 12:46:07 +03:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class CUtlSymbolTable;
|
|
|
|
|
|
|
|
typedef unsigned short UtlSymId_t;
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
#define UTL_INVAL_SYMBOL ((UtlSymId_t)~0)
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
struct LessCtx_t
|
|
|
|
{
|
|
|
|
char const *m_pUserString;
|
|
|
|
CUtlSymbolTable *m_pTable;
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
LessCtx_t() : m_pUserString(0), m_pTable(0) {}
|
2016-02-04 03:18:26 +03:00
|
|
|
};
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
class CUtlSymbol
|
|
|
|
{
|
|
|
|
public:
|
2017-10-12 17:50:56 +03:00
|
|
|
// Constructor, Destructor
|
2015-06-30 12:46:07 +03:00
|
|
|
CUtlSymbol() : m_Id(UTL_INVAL_SYMBOL) {}
|
|
|
|
CUtlSymbol(UtlSymId_t id) : m_Id(id) {}
|
|
|
|
CUtlSymbol(const char* pStr);
|
|
|
|
CUtlSymbol(CUtlSymbol const &sym) : m_Id(sym.m_Id) {}
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
// operator=
|
|
|
|
CUtlSymbol &operator=(CUtlSymbol const &src)
|
|
|
|
{
|
|
|
|
m_Id = src.m_Id;
|
2017-10-12 17:50:56 +03:00
|
|
|
return (*this);
|
2015-06-30 12:46:07 +03:00
|
|
|
}
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
// operator==
|
2016-02-04 03:18:26 +03:00
|
|
|
bool operator==(CUtlSymbol const &src) const { return m_Id == src.m_Id; }
|
2015-06-30 12:46:07 +03:00
|
|
|
bool operator==(const char *pStr) const;
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
// Is valid?
|
2016-02-04 03:18:26 +03:00
|
|
|
bool IsValid() const { return m_Id != UTL_INVAL_SYMBOL; }
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
operator UtlSymId_t/* const*/() const { return m_Id; } // Gets at the symbol
|
|
|
|
const char *String() const; // Gets the string associated with the symbol
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
protected:
|
2017-10-12 17:50:56 +03:00
|
|
|
static void Initialize(); // Initializes the symbol table
|
|
|
|
static CUtlSymbolTable *CurrTable(); // returns the current symbol table
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
UtlSymId_t m_Id;
|
|
|
|
static CUtlSymbolTable *s_pSymbolTable;
|
2016-02-04 03:18:26 +03:00
|
|
|
};
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
class CUtlSymbolTable
|
|
|
|
{
|
|
|
|
public:
|
2017-10-12 17:50:56 +03:00
|
|
|
// Constructor, Destructor
|
2015-06-30 12:46:07 +03:00
|
|
|
CUtlSymbolTable(int growSize = 0,int initSize = 32,bool caseInsensitive = false);
|
|
|
|
~CUtlSymbolTable();
|
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
CUtlSymbol AddString(const char *pString); // Finds and/or creates a symbol based on the string
|
|
|
|
CUtlSymbol Find(const char *pString) const; // Finds the symbol for pString
|
2015-06-30 12:46:07 +03:00
|
|
|
|
2017-10-12 17:50:56 +03:00
|
|
|
const char *String(CUtlSymbol id) const; // Look up the string associated with a particular symbol
|
|
|
|
void RemoveAll(); // Remove all symbols in the table
|
2015-06-30 12:46:07 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
static bool SymLess(const unsigned int &i1, const unsigned int &i2);
|
|
|
|
static bool SymLessi(const unsigned int &i1, const unsigned int &i2);
|
2016-02-04 03:18:26 +03:00
|
|
|
|
2015-06-30 12:46:07 +03:00
|
|
|
protected:
|
2017-10-12 17:50:56 +03:00
|
|
|
CUtlRBTree<unsigned int, UtlSymId_t> m_Lookup;
|
2015-06-30 12:46:07 +03:00
|
|
|
CUtlVector<char> m_Strings;
|
2016-02-04 03:18:26 +03:00
|
|
|
};
|