2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 2002, 2005 Peter Wortmann
|
|
|
|
* Copyright (c) 2006, 2009 Günther Brammer
|
2009-05-08 13:28:41 +00:00
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
|
|
|
|
*
|
|
|
|
* Portions might be copyrighted by other authors who have contributed
|
|
|
|
* to OpenClonk.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
* See isc_license.txt for full license and disclaimer.
|
|
|
|
*
|
|
|
|
* "Clonk" is a registered trademark of Matthes Bender.
|
|
|
|
* See clonk_trademark_license.txt for full license.
|
|
|
|
*/
|
|
|
|
/* string table: holds all strings used by script engine */
|
|
|
|
|
|
|
|
#include <C4Include.h>
|
|
|
|
#include <C4StringTable.h>
|
|
|
|
|
|
|
|
#include <C4Group.h>
|
|
|
|
#include <C4Components.h>
|
2009-04-03 21:53:48 +00:00
|
|
|
//#include <C4Aul.h>
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-01 21:36:58 +00:00
|
|
|
// *** C4Set
|
|
|
|
template<> template<>
|
|
|
|
unsigned int C4Set<C4String *>::Hash<const char *>(const char * s)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-01 21:36:58 +00:00
|
|
|
// Fowler/Noll/Vo hash
|
|
|
|
unsigned int h = 2166136261u;
|
|
|
|
while (*s)
|
|
|
|
h = (h ^ *(s++)) * 16777619;
|
|
|
|
return h;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-01 21:36:58 +00:00
|
|
|
template<> template<>
|
|
|
|
bool C4Set<C4String *>::Equals<const char *>(C4String * a, const char * b)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-01 21:36:58 +00:00
|
|
|
return a->GetData() == b;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-01 21:36:58 +00:00
|
|
|
// *** C4String
|
|
|
|
|
|
|
|
C4String::C4String(StdStrBuf strString)
|
2010-03-28 18:58:01 +00:00
|
|
|
: iRefCnt(0)
|
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// take string
|
2009-11-25 18:38:54 +00:00
|
|
|
Data.Take(std::move(strString));
|
2009-04-01 21:36:58 +00:00
|
|
|
Hash = C4Set<C4String*>::Hash(Data.getData());
|
2009-05-08 13:28:41 +00:00
|
|
|
// reg
|
2009-04-03 21:53:48 +00:00
|
|
|
Strings.Set.Add(this);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4String::~C4String()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
// unreg
|
|
|
|
iRefCnt = 1;
|
2009-04-03 21:53:48 +00:00
|
|
|
Strings.Set.Remove(this);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4String::IncRef()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
++iRefCnt;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
void C4String::DecRef()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
--iRefCnt;
|
2010-03-28 18:58:01 +00:00
|
|
|
if (iRefCnt <= 0)
|
2009-05-08 13:28:41 +00:00
|
|
|
delete this;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
// *** C4StringTable
|
|
|
|
|
|
|
|
C4StringTable::C4StringTable()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-03 19:06:29 +00:00
|
|
|
P[P_Prototype] = RegString("Prototype");
|
|
|
|
P[P_Name] = RegString("Name");
|
2009-04-11 14:38:31 +00:00
|
|
|
P[P_Collectible] = RegString("Collectible");
|
2009-04-12 12:03:14 +00:00
|
|
|
P[P_ActMap] = RegString("ActMap");
|
|
|
|
P[P_Procedure] = RegString("Procedure");
|
|
|
|
P[P_Attach] = RegString("Attach");
|
|
|
|
P[P_Directions] = RegString("Directions");
|
|
|
|
P[P_FlipDir] = RegString("FlipDir");
|
|
|
|
P[P_Length] = RegString("Length");
|
|
|
|
P[P_Delay] = RegString("Delay");
|
|
|
|
P[P_X] = RegString("X");
|
|
|
|
P[P_Y] = RegString("Y");
|
|
|
|
P[P_Wdt] = RegString("Wdt");
|
|
|
|
P[P_Hgt] = RegString("Hgt");
|
|
|
|
P[P_OffX] = RegString("OffX");
|
|
|
|
P[P_OffY] = RegString("OffY");
|
|
|
|
P[P_FacetBase] = RegString("FacetBase");
|
|
|
|
P[P_FacetTopFace] = RegString("FacetTopFace");
|
|
|
|
P[P_FacetTargetStretch] = RegString("FacetTargetStretch");
|
|
|
|
P[P_NextAction] = RegString("NextAction");
|
|
|
|
P[P_Hold] = RegString("Hold");
|
|
|
|
P[P_Idle] = RegString("Idle");
|
|
|
|
P[P_NoOtherAction] = RegString("NoOtherAction");
|
|
|
|
P[P_StartCall] = RegString("StartCall");
|
|
|
|
P[P_EndCall] = RegString("EndCall");
|
|
|
|
P[P_AbortCall] = RegString("AbortCall");
|
|
|
|
P[P_PhaseCall] = RegString("PhaseCall");
|
|
|
|
P[P_Sound] = RegString("Sound");
|
|
|
|
P[P_ObjectDisabled] = RegString("ObjectDisabled");
|
|
|
|
P[P_DigFree] = RegString("DigFree");
|
|
|
|
P[P_EnergyUsage] = RegString("EnergyUsage");
|
|
|
|
P[P_InLiquidAction] = RegString("InLiquidAction");
|
|
|
|
P[P_TurnAction] = RegString("TurnAction");
|
|
|
|
P[P_Reverse] = RegString("Reverse");
|
|
|
|
P[P_Step] = RegString("Step");
|
2009-07-28 01:49:33 +00:00
|
|
|
P[P_Animation] = RegString("Animation");
|
2010-03-18 23:04:29 +00:00
|
|
|
P[P_Action] = RegString("Action");
|
2009-07-22 14:31:09 +00:00
|
|
|
P[P_Visibility] = RegString("Visibility");
|
2009-07-22 16:03:33 +00:00
|
|
|
P[P_Parallaxity] = RegString("Parallaxity");
|
2009-07-22 16:24:07 +00:00
|
|
|
P[P_LineColors] = RegString("LineColors");
|
|
|
|
P[P_LineAttach] = RegString("LineAttach");
|
2009-12-30 19:16:32 +00:00
|
|
|
P[P_MouseDragImage] = RegString("MouseDragImage");
|
2010-03-15 21:50:11 +00:00
|
|
|
P[P_PictureTransformation] = RegString("PictureTransformation");
|
2010-03-17 12:43:17 +00:00
|
|
|
P[P_MeshTransformation] = RegString("MeshTransformation");
|
2009-05-19 22:12:11 +00:00
|
|
|
for (unsigned int i = 0; i < P_LAST; ++i) P[i]->IncRef();
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4StringTable::~C4StringTable()
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-19 22:12:11 +00:00
|
|
|
for (unsigned int i = 0; i < P_LAST; ++i) P[i]->DecRef();
|
2009-04-01 21:36:58 +00:00
|
|
|
assert(!Set.GetSize());
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4String *C4StringTable::RegString(StdStrBuf String)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-05-08 13:28:41 +00:00
|
|
|
C4String * s = FindString(String.getData());
|
|
|
|
if (s)
|
|
|
|
return s;
|
|
|
|
else
|
2009-04-01 21:36:58 +00:00
|
|
|
return new C4String(String);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4String *C4StringTable::FindString(const char *strString)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-01 21:36:58 +00:00
|
|
|
return Set.Get(strString);
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
C4String *C4StringTable::FindString(C4String *pString)
|
2010-03-28 18:58:01 +00:00
|
|
|
{
|
2009-04-01 21:36:58 +00:00
|
|
|
for (C4String * const * i = Set.First(); i; i = Set.Next(i))
|
|
|
|
if (*i == pString)
|
|
|
|
return pString;
|
2009-07-22 14:31:09 +00:00
|
|
|
return NULL;
|
2010-03-28 18:58:01 +00:00
|
|
|
}
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-04-03 21:53:48 +00:00
|
|
|
C4StringTable Strings;
|