OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4StringTable.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 /* string table: holds all strings used by script engine */
17 
18 #include "C4Include.h"
19 #include "script/C4StringTable.h"
20 
21 
22 // *** C4Set
23 template<> template<>
24 unsigned int C4Set<C4String *>::Hash<const char *>(const char * const & s)
25 {
26  // Fowler/Noll/Vo hash
27  unsigned int h = 2166136261u;
28  const char * p = s;
29  while (*p)
30  h = (h ^ *(p++)) * 16777619;
31  return h;
32 }
33 
34 template<> template<>
35 bool C4Set<C4String *>::Equals<const char *>(C4String * const & a, const char * const & b)
36 {
37  return a->GetData() == b;
38 }
39 
40 // *** C4String
41 
42 C4String::C4String(StdStrBuf strString)
43 {
44  // take string
45  Data.Take(std::move(strString));
46  Hash = Strings.Set.Hash(Data.getData());
47  // reg
48  Strings.Set.Add(this);
49 }
50 
51 C4String::C4String()
52 {
53 }
54 
56 {
57  // unreg
58 #ifdef _DEBUG
59  static bool remove = false;
60  assert(!remove); (void)remove;
61  remove = true;
62 #endif
63  Strings.Set.Remove(this);
64 #ifdef _DEBUG
65  remove = false;
66 #endif
67 }
68 
69 void C4String::operator=(const char * s)
70 {
71  assert(!RefCnt);
72  assert(!Data);
73  // ref string
74  Data.Ref(s);
75  Hash = Strings.Set.Hash(Data.getData());
76  // reg
77  Strings.Set.Add(this);
78 }
79 
80 // *** C4StringTable
81 
83 {
84  P[P_Prototype] = "Prototype";
85  P[P_Name] = "Name";
86  P[P_Priority] = "Priority";
87  P[P_Interval] = "Interval";
88  P[P_CommandTarget] = "CommandTarget";
89  P[P_Time] = "Time";
90  P[P_Construction] = "Construction";
91  P[P_Destruction] = "Destruction";
92  P[P_Start] = "Start";
93  P[P_Stop] = "Stop";
94  P[P_Timer] = "Timer";
95  P[P_Effect] = "Effect";
96  P[P_Damage] = "Damage";
97  P[P_Collectible] = "Collectible";
98  P[P_Touchable] = "Touchable";
99  P[P_ActMap] = "ActMap";
100  P[P_Procedure] = "Procedure";
101  P[P_Speed] = "Speed";
102  P[P_Accel] = "Accel";
103  P[P_Decel] = "Decel";
104  P[P_Attach] = "Attach";
105  P[P_Directions] = "Directions";
106  P[P_FlipDir] = "FlipDir";
107  P[P_Length] = "Length";
108  P[P_Delay] = "Delay";
109  P[P_X] = "X";
110  P[P_Y] = "Y";
111  P[P_x] = "x";
112  P[P_y] = "y";
113  P[P_Wdt] = "Wdt";
114  P[P_Hgt] = "Hgt";
115  P[P_wdt] = "wdt";
116  P[P_hgt] = "hgt";
117  P[P_Vertices] = "Vertices";
118  P[P_Edges] = "Edges";
119  P[P_LineWidth] = "LineWidth";
120  P[P_OffX] = "OffX";
121  P[P_OffY] = "OffY";
122  P[P_Proplist] = "Proplist";
123  P[P_proplist] = "proplist";
124  P[P_FacetBase] = "FacetBase";
125  P[P_FacetTopFace] = "FacetTopFace";
126  P[P_FacetTargetStretch] = "FacetTargetStretch";
127  P[P_NextAction] = "NextAction";
128  P[P_Hold] = "Hold";
129  P[P_Idle] = "Idle";
130  P[P_NoOtherAction] = "NoOtherAction";
131  P[P_StartCall] = "StartCall";
132  P[P_EndCall] = "EndCall";
133  P[P_AbortCall] = "AbortCall";
134  P[P_PhaseCall] = "PhaseCall";
135  P[P_Sound] = "Sound";
136  P[P_ObjectDisabled] = "ObjectDisabled";
137  P[P_DigFree] = "DigFree";
138  P[P_InLiquidAction] = "InLiquidAction";
139  P[P_TurnAction] = "TurnAction";
140  P[P_Reverse] = "Reverse";
141  P[P_Step] = "Step";
142  P[P_Animation] = "Animation";
143  P[P_Action] = "Action";
144  P[P_Visibility] = "Visibility";
145  P[P_Parallaxity] = "Parallaxity";
146  P[P_LineColors] = "LineColors";
147  P[P_LineAttach] = "LineAttach";
148  P[P_MouseDrag] = "MouseDrag";
149  P[P_MouseDragImage] = "MouseDragImage";
150  P[P_PictureTransformation] = "PictureTransformation";
151  P[P_MeshTransformation] = "MeshTransformation";
152  P[P_BreatheWater] = "BreatheWater";
153  P[P_CorrosionResist] = "CorrosionResist";
154  P[P_MaxEnergy] = "MaxEnergy";
155  P[P_MaxBreath] = "MaxBreath";
156  P[P_ThrowSpeed] = "ThrowSpeed";
157  P[P_Mode] = "Mode";
158  P[P_CausedBy] = "CausedBy";
159  P[P_Blasted] = "Blasted";
160  P[P_IncineratingObj] = "IncineratingObj";
161  P[P_Plane] = "Plane";
162  P[P_BorderBound] = "BorderBound";
163  P[P_ContactCalls] = "ContactCalls";
164  P[P_SolidMaskPlane] = "SolidMaskPlane";
165  P[P_Tooltip] = "Tooltip";
166  P[P_Placement] = "Placement";
167  P[P_ContainBlast] = "ContainBlast";
168  P[P_BlastIncinerate] = "BlastIncinerate";
169  P[P_ContactIncinerate] = "ContactIncinerate";
170  P[P_Global] = "Global";
171  P[P_Scenario] = "Scenario";
172  P[P_JumpSpeed] = "JumpSpeed";
173  P[P_BackgroundColor] = "BackgroundColor";
174  P[P_Decoration] = "Decoration";
175  P[P_Symbol] = "Symbol";
176  P[P_Target] = "Target";
177  P[P_Std] = "Std";
178  P[P_Text] = "Text";
179  P[P_GraphicsName] = "GraphicsName";
180  P[P_OnClick] = "OnClick";
181  P[P_OnMouseIn] = "OnMouseIn";
182  P[P_OnMouseOut] = "OnMouseOut";
183  P[P_OnClose] = "OnClose";
184  P[P_ID] = "ID";
185  P[P_Style] = "Style";
186  P[P_Player] = "Player";
187  P[P_Margin] = "Margin";
188  P[P_Algo] = "Algo";
189  P[P_Layer] = "Layer";
190  P[P_Seed] = "Seed";
191  P[P_Ratio] = "Ratio";
192  P[P_FixedOffset] = "FixedOffset";
193  P[P_Op] = "Op";
194  P[P_R] = "R";
195  P[P_Scale] = "Scale";
196  P[P_Amplitude] = "Amplitude";
197  P[P_Iterations] = "Iterations";
198  P[P_Empty] = "Empty";
199  P[P_Open] = "Open";
200  P[P_Left] = "Left";
201  P[P_Top] = "Top";
202  P[P_Right] = "Right";
203  P[P_Bottom] = "Bottom";
204  P[P_Filter] = "Filter";
205  P[P_ForceX] = "ForceX";
206  P[P_ForceY] = "ForceY";
207  P[P_G] = "G";
208  P[P_B] = "B";
209  P[P_Alpha] = "Alpha";
210  P[P_DampingX] = "DampingX";
211  P[P_DampingY] = "DampingY";
212  P[P_Size] = "Size";
213  P[P_Rotation] = "Rotation";
214  P[P_BlitMode] = "BlitMode";
215  P[P_Phase] = "Phase";
216  P[P_Stretch] = "Stretch";
217  P[P_CollisionVertex] = "CollisionVertex";
218  P[P_CollisionDensity] = "CollisionDensity";
219  P[P_OnCollision] = "OnCollision";
220  P[P_Distance] = "Distance";
221  P[P_Smoke] = "Smoke";
222  P[P_Source] = "Source";
223  P[P_Color] = "Color";
224  P[P_EditCursorCommands] = "EditCursorCommands";
225  P[P_IsPointContained] = "IsPointContained";
226  P[P_GetRandomPoint] = "GetRandomPoint";
227  P[P_Type] = "Type";
228  P[P_Reverb_Density] = "Reverb_Density";
229  P[P_Reverb_Diffusion] = "Reverb_Diffusion";
230  P[P_Reverb_Gain] = "Reverb_Gain";
231  P[P_Reverb_GainHF] = "Reverb_GainHF";
232  P[P_Reverb_Decay_Time] = "Reverb_Decay_Time";
233  P[P_Reverb_Decay_HFRatio] = "Reverb_Decay_HFRatio";
234  P[P_Reverb_Reflections_Gain] = "Reverb_Reflections_Gain";
235  P[P_Reverb_Reflections_Delay] = "Reverb_Reflections_Delay";
236  P[P_Reverb_Late_Reverb_Gain] = "Reverb_Late_Reverb_Gain";
237  P[P_Reverb_Late_Reverb_Delay] = "Reverb_Late_Reverb_Delay";
238  P[P_Reverb_Air_Absorption_GainHF] = "Reverb_Air_Absorption_GainHF";
239  P[P_Reverb_Room_Rolloff_Factor] = "Reverb_Room_Rolloff_Factor";
240  P[P_Reverb_Decay_HFLimit] = "Reverb_Decay_HFLimit";
241  P[P_Echo_Delay] = "Echo_Delay";
242  P[P_Echo_LRDelay] = "Echo_LRDelay";
243  P[P_Echo_Damping] = "Echo_Damping";
244  P[P_Echo_Feedback] = "Echo_Feedback";
245  P[P_Echo_Spread] = "Echo_Spread";
246  P[P_Equalizer_Low_Gain] = "Equalizer_Low_Gain";
247  P[P_Equalizer_Low_Cutoff] = "Equalizer_Low_Cutoff";
248  P[P_Equalizer_Mid1_Gain] = "Equalizer_Mid1_Gain";
249  P[P_Equalizer_Mid1_Center] = "Equalizer_Mid1_Center";
250  P[P_Equalizer_Mid1_Width] = "Equalizer_Mid1_Width";
251  P[P_Equalizer_Mid2_Gain] = "Equalizer_Mid2_Gain";
252  P[P_Equalizer_Mid2_Center] = "Equalizer_Mid2_Center";
253  P[P_Equalizer_Mid2_Width] = "Equalizer_Mid2_Width";
254  P[P_Equalizer_High_Gain] = "Equalizer_High_Gain";
255  P[P_Equalizer_High_Cutoff] = "Equalizer_High_Cutoff";
256  P[P_LightOffset] = "LightOffset";
257  P[P_PlayList] = "PlayList";
258  P[P_MusicBreakMin] = "MusicBreakMin";
259  P[P_MusicBreakMax] = "MusicBreakMax";
260  P[P_MusicBreakChance] = "MusicBreakChance";
261  P[P_MusicMaxPositionMemory] = "MusicMaxPositionMemory";
262  P[P_InflameLandscape] = "InflameLandscape";
263  P[P_OptionKey] = "OptionKey";
264  P[P_ValueKey] = "ValueKey";
265  P[P_Value] = "Value";
266  P[P_DefaultValueFunction] = "DefaultValueFunction";
267  P[P_Delegate] = "Delegate";
268  P[P_VertexDelegate] = "VertexDelegate";
269  P[P_EdgeDelegate] = "EdgeDelegate";
270  P[P_HorizontalFix] = "HorizontalFix";
271  P[P_VerticalFix] = "VerticalFix";
272  P[P_StructureFix] = "StructureFix";
273  P[P_OnUpdate] = "OnUpdate";
274  P[P_EditorPropertyChanged] = "EditorPropertyChanged";
275  P[P_Min] = "Min";
276  P[P_Max] = "Max";
277  P[P_Set] = "Set";
278  P[P_SetGlobal] = "SetGlobal";
279  P[P_SetRoot] = "SetRoot";
280  P[P_Options] = "Options";
281  P[P_Key] = "Key";
282  P[P_AsyncGet] = "AsyncGet";
283  P[P_Get] = "Get";
284  P[P_Relative] = "Relative";
285  P[P_CanMoveCenter] = "CanMoveCenter";
286  P[P_StartFromObject] = "StartFromObject";
287  P[P_Storage] = "Storage";
288  P[P_Elements] = "Elements";
289  P[P_EditOnSelection] = "EditOnSelection";
290  P[P_EditorProps] = "EditorProps";
291  P[P_DefaultEditorProp] = "DefaultEditorProp";
292  P[P_EditorActions] = "EditorActions";
293  P[P_CopyDefault] = "CopyDefault";
294  P[P_Display] = "Display";
295  P[P_DefaultValue] = "DefaultValue";
296  P[P_DefinitionPriority] = "DefinitionPriority";
297  P[P_Group] = "Group";
298  P[P_Command] = "Command";
299  P[P_Select] = "Select";
300  P[P_DescendPath] = "DescendPath";
301  P[P_EmptyName] = "EmptyName";
302  P[P_ShortName] = "ShortName";
303  P[P_EditorHelp] = "EditorHelp";
304  P[P_Description] = "Description";
305  P[P_AllowEditing] = "AllowEditing";
306  P[P_EditorInitialize] = "EditorInitialize";
307  P[P_EditorPlacementLimit] = "EditorPlacementLimit";
308  P[P_EditorCollection] = "EditorCollection";
309  P[P_Sorted] = "Sorted";
310  P[P_Uniforms] = "Uniforms";
311  P[P_ForceSerialization] = "ForceSerialization";
312  P[P_DrawArrows] = "DrawArrows";
313  P[P_SCENPAR] = "SCENPAR";
314  P[DFA_WALK] = "WALK";
315  P[DFA_FLIGHT] = "FLIGHT";
316  P[DFA_KNEEL] = "KNEEL";
317  P[DFA_SCALE] = "SCALE";
318  P[DFA_HANGLE] = "HANGLE";
319  P[DFA_DIG] = "DIG";
320  P[DFA_SWIM] = "SWIM";
321  P[DFA_THROW] = "THROW";
322  P[DFA_BRIDGE] = "BRIDGE";
323  P[DFA_PUSH] = "PUSH";
324  P[DFA_LIFT] = "LIFT";
325  P[DFA_FLOAT] = "FLOAT";
326  P[DFA_ATTACH] = "ATTACH";
327  P[DFA_CONNECT] = "CONNECT";
328  P[DFA_PULL] = "PULL";
329  // Prevent the individual strings from being deleted, they are not created with new
330  for (unsigned int i = 0; i < P_LAST; ++i)
331  {
332  assert(P[i].GetCStr()); // all strings should be assigned
333  P[i].IncRef();
334  }
335 }
336 
338 {
339 #ifdef _DEBUG
340  if(Set.GetSize() != P_LAST)
341  {
342  for (C4String * const * s = Set.First(); s; s = Set.Next(s))
343  {
344  if (*s >= &Strings.P[0] && *s < &Strings.P[P_LAST])
345  {
346  if ((*s)->RefCnt != 1)
347 #ifdef _WIN32
348  OutputDebugString(FormatString(" \"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt).GetWideChar());
349 #else
350  fprintf(stderr, " \"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt);
351 #endif
352  }
353  else
354 #ifdef _WIN32
355  OutputDebugString(FormatString("\"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt).GetWideChar());
356 #else
357  fprintf(stderr, "\"%s\" %d\n", (*s)->GetCStr(), (*s)->RefCnt);
358 #endif
359  }
360  }
361 #endif
362  assert(Set.GetSize() == P_LAST);
363 }
364 
366 {
367  C4String * s = FindString(String.getData());
368  if (s)
369  return s;
370  else
371  return new C4String(String);
372 }
373 
374 C4String *C4StringTable::FindString(const char *strString) const
375 {
376  return Set.Get(strString);
377 }
const char * getData() const
Definition: StdBuf.h:450
C4String P[P_LAST]
void IncRef()
Definition: C4StringTable.h:27
T * Add(T const &e)
C4String * String(const char *str)
Definition: C4AulDefFunc.h:31
#define b
C4String * FindString(const char *strString) const
StdStrBuf::wchar_t_holder GetWideChar(const char *utf8, bool double_null_terminate=false)
static unsigned int Hash(const H &)
friend class C4String
C4String * RegString(StdStrBuf String)
#define a
virtual ~C4StringTable()
T & Get(H e) const
T const * Next(T const *p) const
unsigned int GetSize() const
C4StringTable Strings
Definition: C4Globals.cpp:42
unsigned int RefCnt
Definition: C4StringTable.h:31
void Take(char *pnData)
Definition: StdBuf.h:465
unsigned int Hash
Definition: C4StringTable.h:37
void Remove(H e)
void Ref(const char *pnData)
Definition: StdBuf.h:463
T const * First() const
#define s
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277