tdbcategory.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. ** Command & Conquer Renegade(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. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : wwtranslatedb *
  23. * *
  24. * $Archive:: /Commando/Code/wwtranslatedb/tdbcategory.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/22/00 10:53a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "tdbcategory.h"
  36. #include "chunkio.h"
  37. #include "persistfactory.h"
  38. #include "translatedbids.h"
  39. #include "tdbcategories.h"
  40. //////////////////////////////////////////////////////////////////////////////
  41. // Persist factory
  42. //////////////////////////////////////////////////////////////////////////////
  43. SimplePersistFactoryClass<TDBCategoryClass, CHUNKID_TDBCATEGORY> _TDBCategoryPersistFactory;
  44. //////////////////////////////////////////////////////////////////////////////
  45. // Constants
  46. //////////////////////////////////////////////////////////////////////////////
  47. enum
  48. {
  49. CHUNKID_VARIABLES = 0x11221022,
  50. CHUNKID_BASE_CLASS,
  51. };
  52. enum
  53. {
  54. VARID_ID = 0x01,
  55. VARID_NAME,
  56. };
  57. ///////////////////////////////////////////////////////////////////////
  58. //
  59. // TDBCategoryClass
  60. //
  61. ///////////////////////////////////////////////////////////////////////
  62. TDBCategoryClass::TDBCategoryClass (void) :
  63. ID (CATEGORY_DEFAULT)
  64. {
  65. return ;
  66. }
  67. ///////////////////////////////////////////////////////////////////////
  68. //
  69. // TDBCategoryClass
  70. //
  71. ///////////////////////////////////////////////////////////////////////
  72. TDBCategoryClass::TDBCategoryClass (const TDBCategoryClass &src) :
  73. ID (CATEGORY_DEFAULT)
  74. {
  75. (*this) = src;
  76. return ;
  77. }
  78. ///////////////////////////////////////////////////////////////////////
  79. //
  80. // ~TDBCategoryClass
  81. //
  82. ///////////////////////////////////////////////////////////////////////
  83. TDBCategoryClass::~TDBCategoryClass (void)
  84. {
  85. return ;
  86. }
  87. /////////////////////////////////////////////////////////////////
  88. //
  89. // operator=
  90. //
  91. /////////////////////////////////////////////////////////////////
  92. const TDBCategoryClass &
  93. TDBCategoryClass::operator= (const TDBCategoryClass &src)
  94. {
  95. ID = src.ID;
  96. Name = src.Name;
  97. return *this;
  98. }
  99. ///////////////////////////////////////////////////////////////////////
  100. //
  101. // Get_Factory
  102. //
  103. ///////////////////////////////////////////////////////////////////////
  104. const PersistFactoryClass &
  105. TDBCategoryClass::Get_Factory (void) const
  106. {
  107. return _TDBCategoryPersistFactory;
  108. }
  109. /////////////////////////////////////////////////////////////////
  110. //
  111. // Save
  112. //
  113. /////////////////////////////////////////////////////////////////
  114. bool
  115. TDBCategoryClass::Save (ChunkSaveClass &csave)
  116. {
  117. csave.Begin_Chunk (CHUNKID_BASE_CLASS);
  118. PersistClass::Save (csave);
  119. csave.End_Chunk ();
  120. csave.Begin_Chunk (CHUNKID_VARIABLES);
  121. Save_Variables (csave);
  122. csave.End_Chunk ();
  123. return true;
  124. }
  125. /////////////////////////////////////////////////////////////////
  126. //
  127. // Load
  128. //
  129. /////////////////////////////////////////////////////////////////
  130. bool
  131. TDBCategoryClass::Load (ChunkLoadClass &cload)
  132. {
  133. while (cload.Open_Chunk ()) {
  134. switch (cload.Cur_Chunk_ID ()) {
  135. case CHUNKID_BASE_CLASS:
  136. PersistClass::Load (cload);
  137. break;
  138. case CHUNKID_VARIABLES:
  139. Load_Variables (cload);
  140. break;
  141. }
  142. cload.Close_Chunk ();
  143. }
  144. return true;
  145. }
  146. /////////////////////////////////////////////////////////////////
  147. //
  148. // Save_Variables
  149. //
  150. /////////////////////////////////////////////////////////////////
  151. void
  152. TDBCategoryClass::Save_Variables (ChunkSaveClass &csave)
  153. {
  154. //
  155. // Save each variable to its own micro chunk
  156. //
  157. WRITE_MICRO_CHUNK (csave, VARID_ID, ID);
  158. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_NAME, Name);
  159. return ;
  160. }
  161. /////////////////////////////////////////////////////////////////
  162. //
  163. // Load_Variables
  164. //
  165. /////////////////////////////////////////////////////////////////
  166. void
  167. TDBCategoryClass::Load_Variables (ChunkLoadClass &cload)
  168. {
  169. while (cload.Open_Micro_Chunk ()) {
  170. switch (cload.Cur_Micro_Chunk_ID ()) {
  171. READ_MICRO_CHUNK (cload, VARID_ID, ID);
  172. READ_MICRO_CHUNK_WWSTRING (cload, VARID_NAME, Name);
  173. }
  174. cload.Close_Micro_Chunk ();
  175. }
  176. return ;
  177. }