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 #include "lib/StdCompiler.h"
23 
24 #include <utility>
25 
26 C4ID::NamesList C4ID::names;
27 C4ID::LookupTable C4ID::lookup;
28 
29 const C4ID C4ID::None(std::string("None"));
30 const C4ID C4ID::Clonk(std::string("Clonk"));
31 const C4ID C4ID::Bubble(std::string("Fx_Bubble"));
32 const C4ID C4ID::EditorBase(std::string("EditorBase"));
33 
34 // TODO: Remove these eventually, since they are deprecated.
35 const C4ID C4ID::Flag(std::string("FLAG"));
36 const C4ID C4ID::Conkit(std::string("CNKT"));
37 const C4ID C4ID::Melee(std::string("MELE"));
38 
39 C4ID::C4ID(const std::string &s) { assign(s); }
40 
41 void C4ID::assign(const std::string &s)
42 {
43  LookupTable::const_iterator it = lookup.find(s);
44  if (it != lookup.end())
45  v = it->second;
46  else
47  {
48  v = names.size();
49  names.push_back(s);
50  lookup.insert(std::make_pair(s, v));
51  }
52 }
53 
55 {
56  if (pComp->isSerializer())
57  {
58  assert(v < names.size());
59  pComp->String(&names[v][0], names[v].size(), StdCompiler::RCT_ID);
60  }
61  else
62  {
63  char *data;
64  pComp->String(&data, StdCompiler::RCT_ID);
65  v = C4ID(data).v;
67  }
68 }
static void DeletePointer(void *data)
Definition: StdBuf.h:204
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
bool isSerializer()
Definition: StdCompiler.h:64
static DEPRECATED const C4ID Flag
Definition: C4Id.h:43
C4ID()
Definition: C4Id.h:50
static const C4ID None
Definition: C4Id.h:42
static DEPRECATED const C4ID Conkit
Definition: C4Id.h:44
static const C4ID Melee
Definition: C4Id.h:46
Definition: C4Id.h:28
void CompileFunc(StdCompiler *pComp)
Definition: C4Id.cpp:54
static const C4ID Clonk
Definition: C4Id.h:45
static const C4ID EditorBase
Definition: C4Id.h:48
static const C4ID Bubble
Definition: C4Id.h:47
#define s