vkdoom_m/src/name.h
Randy Heit c8cdb52863 - Removed generational garbage collection from the string pool because it didn't
actually work.
- Turned the list of TabCommands into a TArray because I saw lots of console
  commands in the memory leak report at exit. Then I realized those were actually
  key bindings, so I changed the Bindings and DoubleBindings arrays into FString
  arrays.
- Fixed: FStringCVar was missing a destructor.
- Added TArray::Insert().
- Fixed: TArray::Delete() used memmove().
- Renamed Malloc(), Realloc(), and Calloc() to M_Malloc(), M_Realloc(), and
  M_Calloc() so that the debug versions can be defined as macros.
- Enabled the CRT's memory leak detection in WinMain().
- Moved contents of PO_DeInit() into P_FreeLevelData().
- Removed "PolyBlockMap = NULL;" from P_SetupLevel(), because the P_FreeLevelData()
  call it makes next does the exact same thing, but also freeing it if needed.
- Fixed: Unneeded memcpy in UnpackUserCmd() when ucmd and basis are the same


SVN r75 (trunk)
2006-05-04 03:49:46 +00:00

103 lines
3.6 KiB
C++

#ifndef NAME_H
#define NAME_H
#include "zstring.h"
#include "tarray.h"
enum ENamedName
{
#define xx(n) NAME_##n,
#include "namedef.h"
#undef xx
};
class FName
{
public:
FName () : Index(0) {}
FName (const char *text) { Index = FindName (text, false); }
FName (const FString &text) { Index = FindName (text.GetChars(), false); }
FName (const char *text, bool noCreate) { Index = FindName (text, noCreate); }
FName (const FString &text, bool noCreate) { Index = FindName (text.GetChars(), noCreate); }
FName (const FName &other) { Index = other.Index; }
FName (ENamedName index) { Index = index; }
// ~FName () {} // Names can be added but never removed.
int GetIndex() const { return Index; }
operator int() const { return Index; }
const FString &GetText() const { return NameArray[Index].Text; }
const char *GetChars() const { return NameArray[Index].Text.GetChars(); }
FName &operator = (const char *text) { Index = FindName (text, false); return *this; }
FName &operator = (const FString &text) { Index = FindName (text.GetChars(), false); return *this; }
FName &operator = (const FName &other) { Index = other.Index; return *this; }
FName &operator = (ENamedName index) { Index = index; return *this; }
int SetName (const char *text, bool noCreate) { return Index = FindName (text, false); }
int SetName (const FString &text, bool noCreate) { return Index = FindName (text.GetChars(), false); }
bool IsValidName() const { return (unsigned int)Index < NameArray.Size(); }
// Note that the comparison operators compare the names' indices, not
// their text, so they cannot be used to do a lexicographical sort.
bool operator == (const FName &other) const { return Index == other.Index; }
bool operator != (const FName &other) const { return Index != other.Index; }
bool operator < (const FName &other) const { return Index < other.Index; }
bool operator <= (const FName &other) const { return Index <= other.Index; }
bool operator > (const FName &other) const { return Index > other.Index; }
bool operator >= (const FName &other) const { return Index >= other.Index; }
bool operator == (ENamedName index) const { return Index == index; }
bool operator != (ENamedName index) const { return Index != index; }
bool operator < (ENamedName index) const { return Index < index; }
bool operator <= (ENamedName index) const { return Index <= index; }
bool operator > (ENamedName index) const { return Index > index; }
bool operator >= (ENamedName index) const { return Index >= index; }
private:
int Index;
enum { HASH_SIZE = 256 };
struct MainName
{
MainName (int next);
MainName (const MainName &other) : Text(other.Text), NextHash(other.NextHash) {}
MainName () {}
FString Text;
int NextHash;
void *operator new (size_t size, MainName *addr)
{
return addr;
}
void operator delete (void *, MainName *)
{
}
};
static TArray<MainName> NameArray;
static int Buckets[HASH_SIZE];
static int FindName (const char *text, bool noCreate);
static void InitBuckets ();
static bool Inited;
#ifndef __GNUC__
template<> friend void CopyForTArray<MainName> (MainName &dst, MainName &src)
{
dst.NextHash = src.NextHash;
CopyForTArray (dst.Text, src.Text);
}
#else
template<class MainName> friend inline void CopyForTArray (MainName &dst, MainName &src);
#endif
};
#ifdef __GNUC__
template<> inline void CopyForTArray<FName::MainName> (FName::MainName &dst, FName::MainName &src)
{
dst.NextHash = src.NextHash;
CopyForTArray (dst.Text, src.Text);
}
#endif
#endif