00001 // $Id: archive.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // The Archive class used to save the Camelot native file format 00099 00100 /* 00101 */ 00102 00103 #include "camtypes.h" 00104 #include "archive.h" 00105 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "ccfile.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 #include "intelmac.h" 00108 00109 // An implement to match the Declare in the .h file. 00110 CC_IMPLEMENT_MEMDUMP(CCArchive, CC_CLASS_MEMDUMP) 00111 #define new CAM_DEBUG_NEW 00112 00113 00114 00115 00116 /******************************************************************************************** 00117 00118 > CCArchive::CCArchive(CCLexFile* pNewFile, UINT32 Mode) 00119 00120 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00121 Created: 7/12/94 00122 Inputs: pNewFile - A CCDiskFile that is ready to be saved into or loaded out of 00123 Mode - The mode of the Archive. Can be one of CCArchive::Load or 00124 CCArchive::Save. 00125 Purpose: Constructs a new CCArchive object. The Archive class assumes the following 00126 things about the size of objects. 00127 00128 00129 ********************************************************************************************/ 00130 00131 CCArchive::CCArchive(CCLexFile* pNewFile, UINT32 Mode) 00132 : pFile(pNewFile), 00133 IsLoadArchive(FALSE), 00134 IsArchiveOK(TRUE) 00135 { 00136 // Find out what sort of Archive we are going to be 00137 if (Mode & CCArchive::Load) 00138 { 00139 // We are loading 00140 IsLoadArchive = TRUE; 00141 } 00142 else if (Mode & CCArchive::Save) 00143 { 00144 // We are saving 00145 IsLoadArchive = FALSE; 00146 } 00147 else 00148 { 00149 // Something is wrong. Mode should be Save or Load 00150 IsArchiveOK = FALSE; 00151 } 00152 } 00153 00154 00155 /******************************************************************************************** 00156 00157 > CCArchive::~CCArchive() 00158 00159 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00160 Created: 7/12/94 00161 Purpose: Destructor 00162 00163 ********************************************************************************************/ 00164 00165 CCArchive::~CCArchive() 00166 { 00167 // Empty. 00168 } 00169 00170 00171 00172 /******************************************************************************************** 00173 00174 > void CCArchive::Close() 00175 00176 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00177 Created: 7/12/94 00178 Purpose: Flushes and closes the CCArchive. After this has been done, you can not write 00179 any more data to it. 00180 00181 ********************************************************************************************/ 00182 00183 void CCArchive::Close() 00184 { 00185 // Close the file associated with the Archive. This should flush the file as well... 00186 pFile->close(); 00187 } 00188 00189 00190 00191 00192 /******************************************************************************************** 00193 00194 > CCArchive& CCArchive::operator>>(BYTE& Var) 00195 CCArchive& CCArchive::operator>>(WORD& Var) 00196 CCArchive& CCArchive::operator>>(INT32& Var) 00197 CCArchive& CCArchive::operator>>(DWORD& Var) 00198 CCArchive& CCArchive::operator>>(float& Var) 00199 CCArchive& CCArchive::operator>>(double& Var) 00200 00201 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00202 Created: 7/12/94 00203 Inputs: Various - The item to be loaded from the archive 00204 Outputs: Various - The data from the file will be in the variable supplied 00205 Returns: A reference to a CCArchive to allow chaining of loading commands 00206 Purpose: Loads a primitive item out of the archive into the variable. This function 00207 will throw an ArchiveExeption if there is an error 00208 SeeAlso: CCArchive::operator<< 00209 00210 ********************************************************************************************/ 00211 00212 CCArchive& CCArchive::operator>>(BYTE& Var) 00213 { 00214 // Read an INT32 out of the file 00215 pFile->read(&Var, sizeof(BYTE)); 00216 return *this; 00217 } 00218 00219 // The INT32 verion of the Loading operator 00220 CCArchive& CCArchive::operator>>(INT32& Var) 00221 { 00222 ERROR3IF(sizeof(INT32)!=4, "INT32 is no longer 4 bytes!\n"); 00223 00224 // Get a Word out the Archive 00225 INT32 LoadMe; 00226 pFile->read(&LoadMe, sizeof(INT32)); 00227 00228 // Fix the word up from Intel format 00229 INT_FROM_INTEL(LoadMe, Var); 00230 return *this; 00231 } 00232 00233 // The WORD verion of the Loading operator 00234 CCArchive& CCArchive::operator>>(WORD& Var) 00235 { 00236 ERROR3IF(sizeof(WORD)!=2, "WORD is no longer 2 bytes!\n"); 00237 00238 // Get a Word out the Archive 00239 WORD LoadMe; 00240 pFile->read(&LoadMe, sizeof(WORD)); 00241 00242 // Fix the word up from Intel format 00243 WORD_FROM_INTEL(LoadMe, Var); 00244 return *this; 00245 } 00246 00247 // The INT32 verion of the Loading operator 00248 CCArchive& CCArchive::operator>>(INT32& Var) 00249 { 00250 ERROR3IF(sizeof(INT32)!=4, "INT32 is no longer 4 bytes!\n"); 00251 00252 // Get a INT32 out the Archive 00253 INT32 LoadMe; 00254 pFile->read(&LoadMe, sizeof(INT32)); 00255 00256 // Fix the INT32 up from Intel format 00257 LONG_FROM_INTEL(LoadMe, Var); 00258 return *this; 00259 } 00260 00261 // The DWORD verion of the Loading operator 00262 CCArchive& CCArchive::operator>>(DWORD& Var) 00263 { 00264 ERROR3IF(sizeof(DWORD)!=4, "DWORD is no longer 4 bytes!\n"); 00265 00266 // Get a DWORD out the Archive 00267 DWORD LoadMe; 00268 pFile->read(&LoadMe, sizeof(DWORD)); 00269 00270 // Fix the DWORD up from Intel format 00271 DWORD_FROM_INTEL(LoadMe, Var); 00272 return *this; 00273 } 00274 00275 // The float verion of the Loading operator 00276 CCArchive& CCArchive::operator>>(float& Var) 00277 { 00278 ERROR3IF(sizeof(float)!=4, "float is no longer 4 bytes!\n"); 00279 00280 // Get a float out the Archive 00281 float LoadMe; 00282 pFile->read(&LoadMe, sizeof(float)); 00283 00284 // Fix the float up from Intel format 00285 FLOAT_FROM_INTEL(LoadMe, Var); 00286 return *this; 00287 } 00288 00289 // The double verion of the Loading operator 00290 CCArchive& CCArchive::operator>>(double& Var) 00291 { 00292 ERROR3IF(sizeof(double)!=8, "double is no longer 8 bytes!\n"); 00293 00294 // Get a float out the Archive 00295 double LoadMe; 00296 pFile->read(&LoadMe, sizeof(double)); 00297 00298 // Fix the float up from Intel format 00299 DOUBLE_FROM_INTEL(LoadMe, Var); 00300 return *this; 00301 } 00302 00303 00304 00305 /******************************************************************************************** 00306 00307 > CCArchive& CCArchive::operator<<(BYTE Var) 00308 CCArchive& CCArchive::operator<<(WORD Var) 00309 CCArchive& CCArchive::operator<<(INT32 Var) 00310 CCArchive& CCArchive::operator<<(DWORD Var) 00311 CCArchive& CCArchive::operator<<(float Var) 00312 CCArchive& CCArchive::operator<<(double Var) 00313 00314 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00315 Created: 7/12/94 00316 Inputs: Various - The item to be Saved to the archive 00317 Returns: A reference to a CCArchive to allow chaining of saving commands 00318 Purpose: saves a primitive item out of the archive from the variable. This function 00319 will throw an ArchiveExeption if there is an error 00320 SeeAlso: CCArchive::operator>> 00321 00322 ********************************************************************************************/ 00323 00324 CCArchive& CCArchive::operator<<(BYTE Var) 00325 { 00326 pFile->write(&Var, sizeof(BYTE)); 00327 return *this; 00328 } 00329 00330 00331 // The INT32 verion of the Saving operator 00332 CCArchive& CCArchive::operator<<(INT32 Var) 00333 { 00334 ERROR3IF(sizeof(INT32)!=4, "INT32 is no longer 4 bytes!\n"); 00335 00336 // Get the Word into Intel form 00337 INT32 SaveMe; 00338 INT_TO_INTEL(Var, SaveMe); 00339 00340 // Save out the Fixed up word 00341 pFile->write(&SaveMe, sizeof(INT32)); 00342 return *this; 00343 } 00344 00345 00346 // The WORD verion of the Saving operator 00347 CCArchive& CCArchive::operator<<(WORD Var) 00348 { 00349 ERROR3IF(sizeof(WORD)!=2, "WORD is no longer 2 bytes!\n"); 00350 00351 // Get the Word into Intel form 00352 WORD SaveMe; 00353 WORD_TO_INTEL(Var, SaveMe); 00354 00355 // Save out the Fixed up word 00356 pFile->write(&SaveMe, sizeof(WORD)); 00357 return *this; 00358 } 00359 00360 // The INT32 verion of the Saving operator 00361 CCArchive& CCArchive::operator<<(INT32 Var) 00362 { 00363 ERROR3IF(sizeof(INT32)!=4, "INT32 is no longer 4 bytes!\n"); 00364 00365 // Get the INT32 into Intel form 00366 INT32 SaveMe; 00367 LONG_TO_INTEL(Var, SaveMe); 00368 00369 // Save out the Fixed up word 00370 pFile->write(&SaveMe, sizeof(INT32)); 00371 return *this; 00372 } 00373 00374 00375 // The DWORD verion of the Saving operator 00376 CCArchive& CCArchive::operator<<(DWORD Var) 00377 { 00378 ERROR3IF(sizeof(DWORD)!=4, "DWORD is no longer 4 bytes!\n"); 00379 00380 // Get the DWORD into Intel form 00381 DWORD SaveMe; 00382 DWORD_TO_INTEL(Var, SaveMe); 00383 00384 // Save out the Fixed up word 00385 pFile->write(&SaveMe, sizeof(DWORD)); 00386 return *this; 00387 } 00388 00389 // The float verion of the Saving operator 00390 CCArchive& CCArchive::operator<<(float Var) 00391 { 00392 ERROR3IF(sizeof(float)!=4, "float is no longer 4 bytes!\n"); 00393 00394 // Get the float into Intel form 00395 float SaveMe; 00396 FLOAT_TO_INTEL(Var, SaveMe); 00397 00398 // Save out the Fixed up word 00399 pFile->write(&SaveMe, sizeof(float)); 00400 return *this; 00401 } 00402 00403 // The double verion of the Saving operator 00404 CCArchive& CCArchive::operator<<(double Var) 00405 { 00406 ERROR3IF(sizeof(double)!=8, "double is no longer 8 bytes!\n"); 00407 00408 // Get the double into Intel form 00409 double SaveMe; 00410 DOUBLE_TO_INTEL(Var, SaveMe); 00411 00412 // Save out the Fixed up word 00413 pFile->write(&SaveMe, sizeof(double)); 00414 return *this; 00415 } 00416 00417 00418 00419 00420 /******************************************************************************************** 00421 00422 > BOOL CCArchive::IsReady() 00423 00424 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00425 Created: 7/12/94 00426 Returns: TRUE if the Archive is Ready, FALSE if not 00427 Purpose: Tests to see if the Archive is ready to save or load data items. This tests 00428 that all the files are OK and everything is set up as it should be. 00429 You should call this function before starting to use the Loading and Saving 00430 operators of this class, though it does only need to be called once at the 00431 begining. Individual objects should NOT need to call this function before 00432 saving/loading their components as it should have been done before all the 00433 Serialise functions are called. 00434 00435 ********************************************************************************************/ 00436 00437 BOOL CCArchive::IsReady() 00438 { 00439 // Make sure that we have a pointer to a file 00440 if (pFile==NULL) 00441 return FALSE; 00442 00443 // make sure that it is open 00444 if (!pFile->isOpen()) 00445 return FALSE; 00446 00447 // all seemed to be ok. 00448 return TRUE; 00449 } 00450 00451 00452 00453 /******************************************************************************************** 00454 00455 > BOOL CCArchive::IsLoading() const 00456 00457 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00458 Created: 7/12/94 00459 Returns: TRUE if this archive is Loading data. 00460 Purpose: Determines if this Archive is a loading or saving archive and responds 00461 appropriatly 00462 00463 ********************************************************************************************/ 00464 00465 BOOL CCArchive::IsLoading() const 00466 { 00467 return IsLoadArchive; 00468 } 00469 00470 00471 /******************************************************************************************** 00472 00473 > BOOL CCArchive::IsSaving() const 00474 00475 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00476 Created: 7/12/94 00477 Returns: TRUE if this archive is Saving data. 00478 Purpose: Determines if this Archive is a loading or saving archive and responds 00479 appropriatly 00480 00481 ********************************************************************************************/ 00482 00483 BOOL CCArchive::IsSaving() const 00484 { 00485 return !IsLoadArchive; 00486 } 00487 00488 00489 00490 00491 /******************************************************************************************** 00492 00493 > CCArchive::CCArchive(const CCArchive& Src) 00494 00495 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00496 Created: 7/12/94 00497 Inputs: Src - Reference to an Archive 00498 Purpose: Copy Constuctor. Since the coping of Archives is not permitted, this just 00499 fails with an ERROR3. 00500 Errors: Always fails with an ERROR3. You should never call this function 00501 00502 ********************************************************************************************/ 00503 00504 CCArchive::CCArchive(const CCArchive& Src) 00505 { 00506 ERROR3("CCArchive classes can not be copied\n"); 00507 } 00508 00509 00510 00511 /******************************************************************************************** 00512 00513 > void CCArchive::operator=(const CCArchive& Src) 00514 00515 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00516 Created: 7/12/94 00517 Inputs: Src - An Archive 00518 Purpose: Stops Archives from being copied as this is not permitted. Always fails 00519 with an Error3. DO NOT CALL THIS FUNCTION. 00520 Errors: Always fails with an ERROR3. You are not allowed to copy Archives 00521 00522 ********************************************************************************************/ 00523 00524 void CCArchive::operator=(const CCArchive& Src) 00525 { 00526 ERROR3("CCArchive classes can not be assigned to each other\n"); 00527 } 00528 00529