Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
buff.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 : Command & Conquer *
24 * *
25 * $Archive:: /G/wwlib/BUFF.CPP $*
26 * *
27 * $Author:: Eric_c $*
28 * *
29 * $Modtime:: 4/15/99 10:14a $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * Buffer::Buffer -- Constructor for buffer object. *
36 * Buffer::Buffer -- Copy constructor for buffer object. *
37 * Buffer::Buffer -- Self-allocating constructor for buffer object. *
38 * Buffer::Reset -- Clears the buffer object to null state. *
39 * Buffer::operator = -- Assignment operator for the buffer object. *
40 * Buffer::~Buffer -- Destructor for buffer object. *
41 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
42
43#include "always.h"
44#include "buff.h"
45//#include <stddef.h>
46
47
48/***********************************************************************************************
49 * Buffer::Buffer -- Constructor for buffer object. *
50 * *
51 * This is the normal constructor for a buffer object. The buffer pointer and size are *
52 * specified as parameters. *
53 * *
54 * INPUT: buffer -- Pointer to the buffer. *
55 * *
56 * size -- The size of the buffer. *
57 * *
58 * OUTPUT: none *
59 * *
60 * WARNINGS: It is possible to construct a Buffer object that has a pointer but a size *
61 * value of zero. The Buffer object can still be used for its pointer, but it *
62 * any function that requires a size will fail. *
63 * *
64 * HISTORY: *
65 * 07/29/1996 JLB : Created. *
66 *=============================================================================================*/
67Buffer::Buffer(void * buffer, long size) :
68 BufferPtr(buffer),
69 Size(size),
71{
72 if (buffer == NULL && size > 0) {
73 BufferPtr = W3DNEWARRAY char[size];
74 IsAllocated = true;
75 }
76}
77
78
79// Alternate constructor for char * pointer.
80Buffer::Buffer(char * buffer, long size) :
81 BufferPtr(buffer),
82 Size(size),
84{
85 if (buffer == NULL && size > 0) {
86 BufferPtr = W3DNEWARRAY char[size];
87 IsAllocated = true;
88 }
89}
90
91
92// Alternate constructor for void const * pointer.
93Buffer::Buffer(void const * buffer, long size) :
94 BufferPtr((void*)buffer),
95 Size(size),
97{
98 if (buffer == NULL && size > 0) {
99 BufferPtr = W3DNEWARRAY char[size];
100 IsAllocated = true;
101 }
102}
103
104
105/***********************************************************************************************
106 * Buffer::Buffer -- Self-allocating constructor for buffer object. *
107 * *
108 * This construtor for a buffer object will automatically allocate the bytes necessary *
109 * to fulfill the size requested. This object is also responsible for deleting the buffer *
110 * it allocated. *
111 * *
112 * INPUT: size -- The size of the buffer to allocated. *
113 * *
114 * OUTPUT: none *
115 * *
116 * WARNINGS: There is no way to tell if the allocation failed. To verify, call Get_Buffer *
117 * and compare with NULL. *
118 * *
119 * HISTORY: *
120 * 07/29/1996 JLB : Created. *
121 *=============================================================================================*/
122Buffer::Buffer(long size) :
124 Size(size),
126{
127 if (size > 0) {
128 BufferPtr = W3DNEWARRAY char[size];
129 IsAllocated = true;
130 }
131}
132
133
134/***********************************************************************************************
135 * Buffer::Buffer -- Copy constructor for buffer object. *
136 * *
137 * This will make a duplicate of the specified buffer object. The ownership of the pointer *
138 * remains with the original object. This prevents multiple deletion of the same pointer. *
139 * *
140 * INPUT: buffer -- Reference to the buffer object to be dupilcated. *
141 * *
142 * OUTPUT: none *
143 * *
144 * WARNINGS: none *
145 * *
146 * HISTORY: *
147 * 08/02/1996 JLB : Created. *
148 *=============================================================================================*/
149Buffer::Buffer(Buffer const & buffer) :
151{
152 BufferPtr = buffer.BufferPtr;
153 Size = buffer.Size;
154}
155
156
157/***********************************************************************************************
158 * Buffer::operator = -- Assignment operator for the buffer object. *
159 * *
160 * This will make a duplicate of the buffer object specified. Any buffer pointed to by the *
161 * left hand buffer will be lost (possibley freed as a result). *
162 * *
163 * INPUT: buffer -- Reference to the right hand buffer object. *
164 * *
165 * OUTPUT: Returns with a reference to the copied buffer object. *
166 * *
167 * WARNINGS: none *
168 * *
169 * HISTORY: *
170 * 08/02/1996 JLB : Created. *
171 *=============================================================================================*/
173{
174 if (&buffer != this) {
175 if (IsAllocated) {
176 delete [] BufferPtr;
177 }
178 IsAllocated = false;
179 BufferPtr = buffer.BufferPtr;
180 Size = buffer.Size;
181 }
182 return(*this);
183}
184
185
186/***********************************************************************************************
187 * Buffer::~Buffer -- Destructor for buffer object. *
188 * *
189 * This destructor will free any buffer it is responsible for. *
190 * *
191 * INPUT: none *
192 * *
193 * OUTPUT: none *
194 * *
195 * WARNINGS: none *
196 * *
197 * HISTORY: *
198 * 07/29/1996 JLB : Created. *
199 *=============================================================================================*/
201{
202 Reset();
203}
204
205
206/***********************************************************************************************
207 * Buffer::Reset -- Clears the buffer object to null state. *
208 * *
209 * This routine will bring the buffer object into a null (newly constructed) state. If *
210 * there was any buffer allocated or referred to by this object, it will be freed or *
211 * dereferenced as necessary. *
212 * *
213 * INPUT: none *
214 * *
215 * OUTPUT: none *
216 * *
217 * WARNINGS: This routine will free the buffer if it is responsible for doing so when *
218 * it is no longer referenced. *
219 * *
220 * HISTORY: *
221 * 09/07/1996 JLB : Created. *
222 *=============================================================================================*/
224{
225 if (IsAllocated) {
226 delete [] BufferPtr;
227 }
228 BufferPtr = NULL;
229 Size = 0;
230 IsAllocated = false;
231}
#define NULL
Definition BaseType.h:92
#define W3DNEWARRAY
Definition always.h:110
@ false
Definition bool.h:59
long Size
Definition BUFF.H:85
void * BufferPtr
Definition BUFF.H:80
bool IsAllocated
Definition BUFF.H:91
~Buffer(void)
Definition buff.cpp:200
Buffer(char *ptr, long size=0)
Definition buff.cpp:80
Buffer & operator=(Buffer const &buffer)
Definition buff.cpp:172
void Reset(void)
Definition buff.cpp:223