Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
refcount.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Westwood Library *
24 * *
25 * $Archive:: /Commando/Code/wwlib/refcount.cpp $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 8/28/01 9:24a $*
30 * *
31 * $Revision:: 17 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * RefCountClass::Add_Active_Ref -- add a new referenced object to the list *
36 * RefCountClass::Set_Ref_Owner -- update the owner file/line for the given object *
37 * RefCountClass::Remove_Active_Ref -- remove an object from the active refs list *
38 * RefCountClass::Validate_Active_Ref -- Confirm a pointer has a node in the active ref list *
39 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
40
41
42#include "refcount.h"
43#include <windows.h>
44
45
46#ifndef NDEBUG
47
48// #define PARANOID_REFCOUNTS
49
50/*
51** Static variables for the reference counting system
52*/
53int RefCountClass::TotalRefs = 0;
55
56
57
58/***********************************************************************************************
59 * RefCountClass::Add_Active_Ref -- add a new referenced object to the list *
60 * *
61 * INPUT: *
62 * *
63 * OUTPUT: *
64 * *
65 * WARNINGS: *
66 * *
67 * HISTORY: *
68 * 3/16/98 GTH : Created. *
69 *=============================================================================================*/
71{
72 ActiveRefList.Add_Head(&(obj->ActiveRefNode));
73 obj->ActiveRefInfo.File = NULL; // default to no debug information added.
74 obj->ActiveRefInfo.Line = 0;
75 return obj;
76}
77
78/***********************************************************************************************
79 * RefCountClass::Set_Ref_Owner -- update the owner file/line for the given object *
80 * *
81 * INPUT: *
82 * *
83 * OUTPUT: *
84 * *
85 * WARNINGS: *
86 * *
87 * HISTORY: *
88 * 3/16/98 GTH : Created. *
89 *=============================================================================================*/
91{
92// static RefCountClass *hunt = (RefCountClass *)0x06558890;
93 static RefCountClass *hunt = (RefCountClass *)0x0;
94 if (obj == hunt) {
95 assert(0);
96 }
97 obj->ActiveRefInfo.File = file;
98 obj->ActiveRefInfo.Line = line;
99 return obj;
100}
101
102
103/***********************************************************************************************
104 * RefCountClass::Remove_Active_Ref -- remove an object from the active refs list *
105 * *
106 * INPUT: *
107 * *
108 * OUTPUT: *
109 * *
110 * WARNINGS: *
111 * *
112 * HISTORY: *
113 * 3/16/98 GTH : Created. *
114 *=============================================================================================*/
116{
117#ifdef PARANOID_REFCOUNTS
118 assert(Validate_Active_Ref(obj));
119#endif
120 obj->ActiveRefNode.Unlink();
121}
122
123/***********************************************************************************************
124 * RefCountClass::Validate_Active_Ref -- Confirm a pointer has a node in the active ref list *
125 * *
126 * INPUT: *
127 * *
128 * OUTPUT: *
129 * *
130 * WARNINGS: *
131 * *
132 * HISTORY: *
133 * 2/06/99 EHC: Created. *
134 *=============================================================================================*/
136{
137 RefCountNodeClass *node = ActiveRefList.First();
138 while (node) {
139 if (node->Get() == obj) return true;
140 node = node->Next();
141 }
142 return false;
143}
144
145/***********************************************************************************************
146 * RefCountClass::Inc_Total_Refs -- increments the total reference count *
147 * *
148 * INPUT: *
149 * *
150 * OUTPUT: *
151 * *
152 * WARNINGS: *
153 * *
154 * HISTORY: *
155 * 2/06/99 EHC: Created. *
156 *=============================================================================================*/
157void RefCountClass::Inc_Total_Refs(const RefCountClass * obj)
158{
159#ifdef PARANOID_REFCOUNTS
160 assert(Validate_Active_Ref(obj));
161#endif
162 TotalRefs++;
163
164}
165
166// SKB 7/21/99 Set BreakOnRefernce to a pointer and it will break when called.
167// This is used for debugging, please do not deleted.
169
170#ifndef NDEBUG
171void RefCountClass::Add_Ref(void) const
172{
173 NumRefs++;
174
175 // See if programmer set break on for a specific address.
176 if (this == BreakOnReference) {
177 DebugBreak(); // trigger the debugger
178 }
179 Inc_Total_Refs(this);
180}
181#endif
182
183/***********************************************************************************************
184 * RefCountClass::Validate_Active_Ref -- decrements the total reference count *
185 * *
186 * INPUT: *
187 * *
188 * OUTPUT: *
189 * *
190 * WARNINGS: *
191 * *
192 * HISTORY: *
193 * 2/06/99 EHC: Created. *
194 *=============================================================================================*/
195void RefCountClass::Dec_Total_Refs(const RefCountClass * obj)
196{
197#ifdef PARANOID_REFCOUNTS
198 assert(Validate_Active_Ref(obj));
199#endif
200 TotalRefs--;
201
202 // See if programmer set break on for a specific address.
203 if (obj == BreakOnReference) {
204 DebugBreak(); // trigger the debugger
205 }
206}
207
208
209
210#endif
211
212
#define NULL
Definition BaseType.h:92
T Get() const
Definition LISTNODE.H:232
DataNode< T > * Next(void) const
Definition LISTNODE.H:234
void Unlink(void)
Definition LISTNODE.H:73
ActiveRefStruct ActiveRefInfo
Definition refcount.h:223
static RefCountClass * Add_Active_Ref(RefCountClass *obj)
Definition refcount.cpp:70
static RefCountClass * Set_Ref_Owner(RefCountClass *obj, char *file, int line)
Definition refcount.cpp:90
RefCountNodeClass ActiveRefNode
Definition refcount.h:218
static RefCountListClass ActiveRefList
Definition refcount.h:228
void Add_Ref(void) const
Definition refcount.cpp:171
RefCountClass(void)
Definition refcount.h:108
static void Remove_Active_Ref(RefCountClass *obj)
Definition refcount.cpp:115
static bool Validate_Active_Ref(RefCountClass *obj)
Definition refcount.cpp:135
RefCountClass * BreakOnReference
Definition refcount.cpp:168
List< RefCountNodeClass * > RefCountListClass
Definition refcount.h:102
DataNode< RefCountClass * > RefCountNodeClass
Definition refcount.h:101