OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ObjectPtr.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2010-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 /* A convenient way to (de)serialize object pointers */
17 
18 #include "C4Include.h"
19 #include "object/C4ObjectPtr.h"
20 #include "object/C4Object.h"
21 #include "object/C4GameObjects.h"
22 
23 #include <limits>
24 
26 
28 {
29  // Pointer needs to be denumerated when decompiling
30  assert(fDenumerated);
31 
32  int32_t nptr = 0;
33  if (!pComp->isDeserializer() && data.ptr)
34  nptr = data.ptr->Number;
35  pComp->Value(nptr);
36  if (pComp->isDeserializer())
37  {
38  data.nptr = nptr;
39 #ifndef NDEBUG
40  // After having read a value the pointer is enumerated
41  fDenumerated = false;
42 #endif
43  }
44 }
45 
47 {
48  assert(!fDenumerated || !data.ptr);
49 
50  assert(data.nptr < std::numeric_limits<int32_t>::max());
51  data.ptr = ::Objects.ObjectPointer(static_cast<int32_t>(data.nptr));
52 
53 #ifndef NDEBUG
54  fDenumerated = true;
55 #endif
56 }
57 
bool fDenumerated
Definition: C4ObjectPtr.h:64
void DenumeratePointers()
Definition: C4ObjectPtr.cpp:46
static const C4ObjectPtr Null
Definition: C4ObjectPtr.h:28
union C4ObjectPtr::@78 data
void Value(const T &rStruct)
Definition: StdCompiler.h:170
void CompileFunc(StdCompiler *pComp)
Definition: C4ObjectPtr.cpp:27
virtual bool isDeserializer()
Definition: StdCompiler.h:63
C4Object * ObjectPointer(int32_t iNumber)
C4GameObjects Objects
Definition: C4Globals.cpp:48