OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 // TODO: Remove these eventually, since they are deprecated.
34 const C4ID C4ID::Flag(std::string("FLAG"));
35 const C4ID C4ID::Conkit(std::string("CNKT"));
36 const C4ID C4ID::Melee(std::string("MELE"));
37 
38 C4ID::C4ID(const std::string &s) { assign(s); }
39 
40 void C4ID::assign(const std::string &s)
41 {
42  LookupTable::const_iterator it = lookup.find(s);
43  if (it != lookup.end())
44  v = it->second;
45  else
46  {
47  v = names.size();
48  names.push_back(s);
49  lookup.insert(std::make_pair(s, v));
50  }
51 }
52 
54 {
55  if (pComp->isSerializer())
56  {
57  assert(v < names.size());
58  pComp->String(&names[v][0], names[v].size(), StdCompiler::RCT_ID);
59  }
60  else
61  {
62  char *data;
63  pComp->String(&data, StdCompiler::RCT_ID);
64  v = C4ID(data).v;
66  }
67 }
static void DeletePointer(void *data)
Definition: StdBuf.h:196
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
bool isSerializer()
Definition: StdCompiler.h:54
static DEPRECATED const C4ID Flag
Definition: C4Id.h:40
C4ID()
Definition: C4Id.h:47
static const C4ID None
Definition: C4Id.h:39
static DEPRECATED const C4ID Conkit
Definition: C4Id.h:41
static const C4ID Melee
Definition: C4Id.h:43
Definition: C4Id.h:25
void CompileFunc(StdCompiler *pComp)
Definition: C4Id.cpp:53
static const C4ID Clonk
Definition: C4Id.h:42
static const C4ID EditorBase
Definition: C4Id.h:45
static const C4ID Bubble
Definition: C4Id.h:44
#define s