OpenClonk
C4Id.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Value to identify object definitions */
19 
20 #include "C4Include.h"
21 #include "object/C4Id.h"
22 
23 #include "lib/StdCompiler.h"
24 
25 C4ID::NamesList C4ID::names;
26 C4ID::LookupTable C4ID::lookup;
27 
28 const C4ID C4ID::None(std::string("None"));
29 const C4ID C4ID::Clonk(std::string("Clonk"));
30 const C4ID C4ID::Bubble(std::string("Fx_Bubble"));
31 const C4ID C4ID::EditorBase(std::string("EditorBase"));
32 
33 
34 C4ID::C4ID(const std::string &s) { assign(s); }
35 
36 void C4ID::assign(const std::string &s)
37 {
38  LookupTable::const_iterator it = lookup.find(s);
39  if (it != lookup.end())
40  {
41  v = it->second;
42  }
43  else
44  {
45  v = names.size();
46  names.push_back(s);
47  lookup.insert(std::make_pair(s, v));
48  }
49 }
50 
52 {
53  if (comp->isSerializer())
54  {
55  assert(v < names.size());
56  comp->String(&names[v][0], names[v].size(), StdCompiler::RCT_ID);
57  }
58  else
59  {
60  char *data;
61  comp->String(&data, StdCompiler::RCT_ID);
62  v = C4ID(data).v;
64  }
65 }
#define s
Definition: C4Id.h:26
static const C4ID Clonk
Definition: C4Id.h:40
static const C4ID Bubble
Definition: C4Id.h:41
static const C4ID EditorBase
Definition: C4Id.h:42
C4ID()
Definition: C4Id.h:44
void CompileFunc(StdCompiler *pComp)
Definition: C4Id.cpp:51
static const C4ID None
Definition: C4Id.h:39
static void DeletePointer(void *data)
Definition: StdBuf.h:196
bool isSerializer()
Definition: StdCompiler.h:54
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0