Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
sharebuf.h
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 : G *
24 * *
25 * $Archive:: /Commando/Code/wwlib/sharebuf.h $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 3/20/01 1:24p $*
30 * *
31 * $Revision:: 8 $*
32 * *
33 *-------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36#if _MSC_VER >= 1000
37#pragma once
38#endif // _MSC_VER >= 1000
39
40#ifndef SHAREBUF_H
41#define SHAREBUF_H
42#include "refcount.h"
43
44
45/*
46** SharedBufferClass - a templatized class for buffers which are shared
47** between different objects. This is essentially just a C array with a
48** refcounted wrapper (also a count).
49*/
50template <class T>
52{
54 public:
55 ShareBufferClass(int count, const char* msg);
58
59 // Get the internal pointer to the array
60 // CAUTION! This pointer is not refcounted so only use it in a context
61 // where you are keeping a reference to the enclosing ShareBufferClass
62 // to avoid the possibility of a dangling pointer.
63 T * Get_Array(void) { return Array; }
64 int Get_Count(void) { return Count; }
65
66 // Access to the elements in the array
67 void Set_Element(int index, const T & thing);
68 const T & Get_Element(int index) const;
69 T & Get_Element(int index);
70
71 // Clear the memory in this array.
72 // CAUTION! Be careful calling this if 'T' is a class. You could be wiping out
73 // virtual function table pointers. Not a good idea to memset 0 over the top of
74 // an array of objects but useful if you are creating an array of some basic type
75 // like pointers or ints...
76 void Clear(void);
77
78 protected:
79
80#if (defined(_DEBUG) || defined(_INTERNAL))
81 const char* Msg;
82#endif
83 T * Array;
84 int Count;
85
86 // not implemented!
88};
89
90template <class T>
92 Count(count)
93#if (defined(_DEBUG) || defined(_INTERNAL))
94 , Msg(msg)
95#endif
96{
97 assert(Count > 0);
99}
100
101template <class T>
103 Count(that.Count)
104{
105 assert(Count > 0);
106#if (defined(_DEBUG) || defined(_INTERNAL))
107 Msg = that.Msg;
108#endif
110 for (int i=0; i<Count; i++) {
111 Array[i] = that.Array[i];
112 }
113}
114
115template <class T>
117{
118 if (Array) {
119 delete[] Array;
120 Array = NULL;
121 }
122}
123
124template<class T>
125void ShareBufferClass<T>::Set_Element(int index,const T & thing)
126{
127 assert(index >= 0);
128 assert(index < Count);
129 Array[index] = thing;
130}
131
132template<class T>
133const T& ShareBufferClass<T>::Get_Element(int index) const
134{
135 return Array[index];
136}
137
138template<class T>
140{
141 return Array[index];
142}
143
144template<class T>
146{
147 memset(Array,0,Count * sizeof(T));
148}
149
150
151#endif // SHAREBUF_H
#define NULL
Definition BaseType.h:92
if(pDbg)
#define _DEBUG
Definition FTP.CPP:45
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
#define MSGW3DNEWARRAY(MSG)
Definition always.h:108
#define Msg
Definition Wnd_File.h:102
RefCountClass(void)
Definition refcount.h:108
ShareBufferClass & operator=(const ShareBufferClass &)
int Get_Count(void)
Definition sharebuf.h:64
T & Get_Element(int index)
Definition sharebuf.h:139
const T & Get_Element(int index) const
Definition sharebuf.h:133
ShareBufferClass(int count, const char *msg)
Definition sharebuf.h:91
void Clear(void)
Definition sharebuf.h:145
ShareBufferClass(const ShareBufferClass &that)
Definition sharebuf.h:102
~ShareBufferClass(void)
Definition sharebuf.h:116
void Set_Element(int index, const T &thing)
Definition sharebuf.h:125
T * Get_Array(void)
Definition sharebuf.h:63
MSG msg
Definition patch.cpp:409