pointer.cpp

Sat, 16 Mar 2013 14:21:31 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 16 Mar 2013 14:21:31 +0200
changeset 19
6c5977e43e73
child 21
9aebaaafa5da
permissions
-rw-r--r--

Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.

19
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 #include "pointer.h"
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 vector<objPointer*> g_pObjectPointers;
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 // #define POINTER_DEBUG
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 #ifdef POINTER_DEBUG
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 #include <stdio.h>
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 #define DEBUGMESSAGE printf
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 #else
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 #define DEBUGMESSAGE
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 #endif
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 void objPointer::replacePointers (LDObject* old, LDObject* repl) {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 DEBUGMESSAGE ("replacing %p with %p\n", old, repl);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 DEBUGMESSAGE ("%u objects in pointers\n", g_pObjectPointers.size());
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 for (ulong i = 0; i < g_pObjectPointers.size(); ++i) {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 objPointer* ptrptr = g_pObjectPointers[i];
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 DEBUGMESSAGE ("%lu. (%p <-> %p)\n", i, (*ptrptr).ptr, old);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 if ((*ptrptr).ptr == old) {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 DEBUGMESSAGE ("\treplacing... %p -> %p\n", (*ptrptr).ptr, repl);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 (*ptrptr).ptr = repl;
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 DEBUGMESSAGE ("%lu. (%p <-> %p)\n", i, (*ptrptr).ptr, old);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 }
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 }
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 }
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 objPointer::~objPointer () {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 }
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 objPointer::objPointer () {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 ptr = nullptr;
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 }
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 objPointer::objPointer (LDObject* _ptr) {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 ptr = _ptr;
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 }
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 void objPointer::serialize () {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 DEBUGMESSAGE ("Adding %p to pointers (ptr = %p)... ", this, ptr);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 g_pObjectPointers.push_back (this);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 DEBUGMESSAGE ("%u objects in pointers\n", g_pObjectPointers.size());
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 }
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 void objPointer::unSerialize () {
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 DEBUGMESSAGE ("Removing %p from pointers... ", this);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 for (ulong i = 0; i < g_pObjectPointers.size(); ++i)
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 if (g_pObjectPointers[i] == this)
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 g_pObjectPointers.erase (g_pObjectPointers.begin() + i);
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 DEBUGMESSAGE ("%u objects in pointers\n", g_pObjectPointers.size());
6c5977e43e73 Added pointer serializing so I can keep track of all LDObject* members. This way I can replace them all properly when needed.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 }

mercurial