Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
persistfactory.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 : WWSaveLoad *
24 * *
25 * $Archive:: /Commando/Code/wwsaveload/persistfactory.h $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 5/04/01 8:42p $*
30 * *
31 * $Revision:: 11 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42
43
44
45#ifndef PERSISTFACTORY_H
46#define PERSISTFACTORY_H
47
48#include "always.h"
49#include "bittype.h"
50#include "chunkio.h"
51#include "wwdebug.h"
52#include "saveload.h"
53
54class PersistClass;
55
56/*
57** PersistFactoryClass
58** Create a PersistFactoryClass for each concrete derived PersistClass. These
59** factories automatically register with the SaveLoadSystem in their constructors
60** and should be accessible through the virtual Get_Factory method of any
61** derived PersistClass.
62*/
63
65{
66public:
67
69 virtual ~PersistFactoryClass(void);
70
71 virtual uint32 Chunk_ID(void) const = 0;
72 virtual PersistClass * Load(ChunkLoadClass & cload) const = 0;
73 virtual void Save(ChunkSaveClass & csave,PersistClass * obj) const = 0;
74
75private:
76
77 PersistFactoryClass * NextFactory;
78 friend class SaveLoadSystemClass;
79};
80
81
82
83
84/*
85** SimplePersistFactoryClass
86** This template automates the creation of a PersistFactory for any type of Persist
87** object. Simply instantiate a single static instance of this template with the
88** type and chunkid in the .cpp file of your class.
89*/
90template <class T,int CHUNKID> class SimplePersistFactoryClass : public PersistFactoryClass
91{
92public:
93
94 virtual uint32 Chunk_ID(void) const { return CHUNKID; }
95 virtual PersistClass * Load(ChunkLoadClass & cload) const;
96 virtual void Save(ChunkSaveClass & csave,PersistClass * obj) const;
97
98 /*
99 ** Internal chunk id's
100 */
101 enum
102 {
105 };
106};
107
108
109template<class T, int CHUNKID> PersistClass *
111{
112 T * new_obj = W3DNEW T;
113 T * old_obj = NULL;
114
115 cload.Open_Chunk();
117 cload.Read(&old_obj,sizeof(T *));
118 cload.Close_Chunk();
119
120 cload.Open_Chunk();
122 new_obj->Load(cload);
123 cload.Close_Chunk();
124
126 return new_obj;
127}
128
129
130template<class T, int CHUNKID> void
132{
133 uint32 objptr = (uint32)obj;
135 csave.Write(&objptr,sizeof(uint32));
136 csave.End_Chunk();
137
139 obj->Save(csave);
140 csave.End_Chunk();
141}
142
143
144#endif
#define NULL
Definition BaseType.h:92
#define WWASSERT
#define W3DNEW
Definition always.h:109
unsigned long uint32
Definition bittype.h:46
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
uint32 Read(void *buf, uint32 nbytes)
Definition chunkio.cpp:692
bool Open_Chunk()
Definition chunkio.cpp:412
uint32 Write(const void *buf, uint32 nbytes)
Definition chunkio.cpp:264
bool Begin_Chunk(uint32 id)
Definition chunkio.cpp:108
bool End_Chunk()
Definition chunkio.cpp:148
virtual bool Save(ChunkSaveClass &csave)
Definition persist.h:70
virtual uint32 Chunk_ID(void) const =0
friend class SaveLoadSystemClass
virtual PersistClass * Load(ChunkLoadClass &cload) const =0
virtual void Save(ChunkSaveClass &csave, PersistClass *obj) const =0
virtual ~PersistFactoryClass(void)
static void Register_Pointer(void *old_pointer, void *new_pointer)
Definition saveload.cpp:210
virtual void Save(ChunkSaveClass &csave, PersistClass *obj) const
virtual uint32 Chunk_ID(void) const
virtual PersistClass * Load(ChunkLoadClass &cload) const