00001 /** 00002 * \file serializ.h <mi32/serializ.h> 00003 * \brief SERIALIZER class definition 00004 * 00005 * \if NODOC 00006 * $Id: serializ.h_v 1.42 2005/03/31 16:57:20 fileserver!dwilliss Exp $ 00007 * 00008 * $Log: serializ.h_v $ 00009 * Revision 1.42 2005/03/31 16:57:20 fileserver!dwilliss 00010 * Rename one of our types to MIUNICODE because it conflicted with a Microsoft #define 00011 * 00012 * Revision 1.41 2005/01/20 22:22:04 mju 00013 * Add make using parent, objtype, descriptor. 00014 * 00015 * Revision 1.40 2005/01/19 14:50:49 mju 00016 * Add make variant using objitem. 00017 * Deprecate make/open using dparminfo, inode, file handle. 00018 * 00019 * Revision 1.39 2004/10/01 17:21:10 mju 00020 * Add getItemValue as double. 00021 * 00022 * Revision 1.38 2004/06/30 18:46:12 mju 00023 * Remove type_mapprojparm. 00024 * 00025 * Revision 1.37 2004/06/28 17:55:41 mju 00026 * Add spaterf and region2d support. 00027 * 00028 * Revision 1.36 2004/06/25 16:31:15 mju 00029 * Add itemdefs for coordrefsys. 00030 * 00031 * Revision 1.35 2004/03/01 18:38:56 mju 00032 * Disable deprecated declaration warning within header. 00033 * 00034 * Revision 1.34 2003/11/12 20:54:05 mju 00035 * Add logging methods. 00036 * 00037 * Revision 1.33 2003/09/26 19:36:41 scowan 00038 * Removed use of include file. 00039 * 00040 * Revision 1.32 2003/09/15 13:49:56 fileserver!dwilliss 00041 * Doxygen 00042 * 00043 * Revision 1.31 2003/09/09 16:22:57 mju 00044 * Add GetFilePath. 00045 * 00046 * Revision 1.30 2003/03/10 15:43:14 mju 00047 * nc. 00048 * 00049 * Revision 1.29 2002/09/11 18:00:39 mju 00050 * Add ITEM_RVCOBJITEM... 00051 * 00052 * Revision 1.28 2002/08/21 20:40:04 scowan 00053 * Deprecate old object name define. 00054 * 00055 * Revision 1.27 2002/04/04 18:36:24 mju 00056 * Remove vararg method as not used. 00057 * 00058 * Revision 1.26 2002/04/04 18:25:12 mju 00059 * Add TYPE_RVCOBJECTNAME. 00060 * Deprecate varargs method. 00061 * 00062 * Revision 1.25 2002/03/26 21:12:56 mju 00063 * Remove deprecated methods. 00064 * 00065 * Revision 1.24 2002/03/05 14:37:01 mju 00066 * Make PutItem methods public. 00067 * 00068 * Revision 1.23 2002/03/04 18:45:39 mju 00069 * Add Open() using objitem. 00070 * 00071 * Revision 1.22 2001/12/28 21:35:49 mju 00072 * SerialWrite and related methods now const. 00073 * 00074 * Revision 1.21 2001/07/12 17:30:32 dwilliss 00075 * Allow for new TYPE_StringMLRaw -- When writing to text file, don't muck 00076 * with the encoding. It's just a raw one-byte-character string who's encoding 00077 * is only known by the caller. Can't assume it's UTF8 00078 * 00079 * Revision 1.20 2001/07/12 15:55:19 dwilliss 00080 * Made PutStr() methods public (just the Unicode ones). There was a comment 00081 * on the (char*) ones to make them go away, so I left them private. All the 00082 * PutDouble, PutInt, PutUnsigned methods were already public, so why not 00083 * the string ones? 00084 * 00085 * Revision 1.19 2001/06/07 16:09:36 mju 00086 * Add details for SERIALIZABLE. 00087 * Remove unnecessary SERIALIZABLE methods. 00088 * Add TYPE_SERIALIZABLE/PTR. 00089 * 00090 * Revision 1.18 2001/03/05 21:43:59 mju 00091 * Add StatusTextUpdate. 00092 * 00093 * Revision 1.17 2000/11/30 20:36:04 mju 00094 * Add Rewind(). 00095 * 00096 * Revision 1.16 2000/11/13 15:00:31 mju 00097 * Change formula layer to use new geoformula class. 00098 * 00099 * Revision 1.14 2000/09/20 14:05:03 mju 00100 * Add flag to not prompt for missing linked file. 00101 * 00102 * Revision 1.13 2000/08/23 22:19:16 dwilliss 00103 * MISTRING? 00104 * 00105 * Revision 1.12 2000/08/18 20:08:09 dwilliss 00106 * Added LPOINT2D/LRECT2D support 00107 * 00108 * Revision 1.9 2000/03/08 18:28:05 mju 00109 * Add GetIgnoreSkippable() method. 00110 * 00111 * Revision 1.8 2000/03/03 15:03:07 mju 00112 * Add FLAG_AddOffsetCB. 00113 * 00114 * Revision 1.7 2000/02/15 14:21:46 mju 00115 * Make SkipStruct public. 00116 * 00117 * Revision 1.6 2000/01/27 15:33:40 mju 00118 * Add GetObjectName(). 00119 * 00120 * Revision 1.5 2000/01/19 18:50:49 mju 00121 * Allow FILEPATH for Make/Open. 00122 * 00123 * Revision 1.4 2000/01/19 14:22:29 mju 00124 * Make PutDouble/PutInt public. 00125 * Add GetItemValue(). 00126 * 00127 * Revision 1.3 1999/12/10 23:07:25 mju 00128 * Make SERIALIZABLE pure virtual. 00129 * 00130 * Revision 1.1 1999/12/02 23:21:26 mju 00131 * Initial revision 00132 * 00133 * \endif 00134 **/ 00135 00136 #ifndef INC_MI32_SERIALIZ_H 00137 #define INC_MI32_SERIALIZ_H 00138 00139 #ifndef INC_RVC_SERIALIZE_H 00140 #include <rvc/serialze.h> 00141 #endif 00142 00143 #ifndef INC_MI32_MSTATUS_H 00144 #include <mi32/mstatus.h> 00145 #endif 00146 00147 #ifdef WIN32 00148 #pragma warning (disable:4996) // Disable warning about deprecated declaration within header 00149 #endif 00150 00151 //! Forward declarations 00152 00153 class SERIALIZABLE; 00154 struct RVCPARMINFO; 00155 struct OLDPROJPARM; 00156 struct COLOR; 00157 struct DPOINT2D; 00158 struct DPOINT3D; 00159 struct DRECT2D; 00160 struct DRECT3D; 00161 namespace SPATREF { 00162 class COORDREFSYS; 00163 } 00164 00165 //----------------------------------------------------------------------------- 00166 // SERIALIZER class 00167 //----------------------------------------------------------------------------- 00168 00169 //! Class for storing object instances to file. 00170 //! The SERIALIZER class provides methods to write object instances to a text 00171 //! file/object and read those instances back into memory later. The design 00172 //! allows for the object structure to change while maintaining compatibility 00173 //! with previously existing files. 00174 00175 class SERIALIZER { 00176 public: 00177 00178 //! Item definition for single member of structure or class. 00179 class ITEMDEF { 00180 public: 00181 00182 //! Item types. 00183 enum TYPE { 00184 TYPE_End = 0, 00185 00186 //! Scalars 00187 TYPE_UINT8 = 1, 00188 TYPE_INT8 = 2, 00189 TYPE_UINT16 = 3, 00190 TYPE_INT16 = 4, 00191 TYPE_UINT32 = 5, 00192 TYPE_INT32 = 6, 00193 TYPE_BitUINT32 = 7, //!< Bit value in UINT32, bit specified in .extra 00194 TYPE_UInt = 8, //!< unsigned int 00195 TYPE_Int = 9, //!< int 00196 TYPE_Float = 10, //!< float 00197 TYPE_Double = 11, //!< double 00198 TYPE_Bool = 12, //!< bool 00199 TYPE_UINT8_Array = 13, 00200 TYPE_Enum = 14, //!< enum, size specified in .extra 00201 00202 //! Strings 00203 TYPE_StringU = 20, //!< MIUNICODE string (.extra contains size) 00204 TYPE_MISTRING = 21, //!< MISTRING 00205 TYPE_MISTRING_ML = 22, //!< Multi-line MISTRING 00206 TYPE_StringMLU = 23, //!< Multi-line Unicode string 00207 TYPE_StringPtrU = 24, //!< Pointer to Unicode string 00208 TYPE_StringA = 25, //!< ASCII string (.extra contains size) 00209 TYPE_StringMLA = 26, //!< Multi-line ASCII string (pointer) 00210 TYPE_StringPtrA = 27, //!< Multi-line Unicode String (pointer) 00211 TYPE_StringMLRaw = 28, //!< Multi-line raw (char*) string (pointer) 00212 00213 //! Files and objects 00214 TYPE_FileName = 30, //!< MIUNICODE filename 00215 TYPE_FILEPATH = 31, 00216 TYPE_Object = 32, //!< RVC object, type stored in ITEMDEF.extra 00217 TYPE_SubObject = 33, //!< Subobject, use previous TYPE_Object as parent 00218 TYPE_RVCOBJECTNAME = 34, //!< RVC::OBJECTNAME 00219 TYPE_RVCOBJITEMFILE = 35, //!< FilePath portion of RVC::OBJITEM 00220 TYPE_RVCOBJITEMOBJECT = 36, //!< Object portion of RVC::OBJITEM, type stored in ITEMDEF.extra 00221 00222 //! Generic 00223 TYPE_Special = 40, //!< Use cbfunc to do read and write 00224 TYPE_SpecialPtr = 41, //!< Use cbfunc to do read and write 00225 TYPE_Struct = 42, //!< Structure/class 00226 TYPE_StructPtr = 43, //!< Structure/class pointer, will be allocated if 0, .extra contains size 00227 TYPE_StructPtrArray = 44, //!< Array of structure pointers, .extra contain size 00228 00229 //! Built-in structures 00230 TYPE_COLOR = 50, //!< COLOR 00231 TYPE_DRECT2D = 51, //!< DRECT2D 00232 TYPE_DPOINT2D = 52, //!< DPOINT2D 00233 TYPE_DPOINT3D = 53, //!< DPOINT3D 00234 TYPE_POINTSTYLE = 55, //!< POINTSTYLE 00235 TYPE_LINESTYLE = 56, //!< LINESTYLE 00236 TYPE_POLYSTYLE = 57, //!< POLYSTYLE 00237 TYPE_TEXTSTYLE = 58, //!< TEXTSTYLE 00238 TYPE_LPOINT2D = 59, //!< LPOINT2D 00239 TYPE_LRECT2D = 60, //!< LRECT2D 00240 TYPE_OLDPROJPARMTOCRS = 61, //!< Serialized as OLDPROJPARM, in memory as SPATREF::COORDREFSYS 00241 TYPE_COORDREFSYS = 62, //!< SPATREF::COORDREFSYS 00242 TYPE_REGION2D = 63, //!< REGION2D 00243 TYPE_DRECT3D = 64, //!< DRECT3D 00244 00245 TYPE_SERIALIZABLE = 90, //!< SERIALIZABLE object 00246 TYPE_SERIALIZABLEPTR = 91, //!< Pointer to SERIALIZABLE object 00247 00248 TYPE_InternalSer = 998, 00249 TYPE_Start = 999 //!< Used internally to start new structure 00250 }; 00251 00252 enum FLAGS { 00253 FLAG_None = 0x0000, 00254 FLAG_NoWrite0 = 0x0001, //!< Don't write value if not set 00255 FLAG_NoWrite = 0x0002, //!< Don't write this item 00256 FLAG_NoRead = 0x0004, //!< Don't read this item 00257 FLAG_FileNoExist0 = 0x0008, //!< When reading PARMITEM_FileName zero string if file doesn't exist 00258 FLAG_Skippable = 0x0020, //!< Item will be ignored if "IgnoreSkippable" set 00259 FLAG_AddOffsetCB = 0x0040, //!< Add offset to pointer when passing to callback function 00260 FLAG_FindFileImmed = 0x0080, //!< Search for file immediately instead of waiting until looking for object 00261 FLAG_DontAskLinkFile = 0x0100 //!< Don't prompt user if can't find linked file 00262 }; 00263 00264 enum ACTION { 00265 ACTION_None = 0x0000, 00266 ACTION_ReadBegin = 0x0001, 00267 ACTION_ReadEnd = 0x0002, 00268 ACTION_WriteBegin = 0x0004, 00269 ACTION_WriteEnd = 0x0008, 00270 ACTION_Read = 0x0010, 00271 ACTION_Write = 0x0020 00272 }; 00273 00274 typedef ERRVALUE (*CBFUNC)(SERIALIZER&, const ITEMDEF*, void *data, ACTION action); 00275 00276 char *name; //!< Name of the item, 0 to terminate array, not case-sensitive 00277 TYPE type; //!< Item type 00278 int offset; //!< Offset into class/struct 00279 int extra; //!< Extra type-specific data, see below 00280 const ITEMDEF *substruct; //!< Sub-structure definition for TYPE_Struct/StructPtr 00281 FLAGS flags; //!< Flags 00282 CBFUNC cbfunc; //!< Callback function for this item 00283 00284 //! The meaning of the "extra" field is dependent on the "type" field: 00285 //! 00286 //! "type" 00287 //! UINT8_Array Number of array entries 00288 //! StringA, StringU Number of bytes in entry (use membersize in definition) 00289 //! Object, SubObject Object type (0 for OTYPE_ALL) 00290 //! BitUINT32 Bit number to use, 0 = lowest 00291 //! StructPtr, StructPtrArray Size of structure to allocate 00292 //! Enum Size of member 00293 00294 //! When handling TYPE_Special items, the cbfunc will be called with ACTION_Read or 00295 //! ACTION_Write. The cbfunc is responsible for actually reading and writing the data 00296 //! using the SERIALIZER class reference provided. 00297 00298 }; 00299 00300 //! Merge two item definition arrays. 00301 //! This is useful when inheriting from a class which already uses an item definition array. 00302 static ITEMDEF* MergeItemDef ( 00303 const ITEMDEF *def1, //!< First definition array 00304 const ITEMDEF *def2 //!< Second definition array 00305 ); //! Returns new allocated definition array 00306 00307 //! Default constructor. 00308 SERIALIZER ( 00309 ); 00310 00311 //! Destructor. 00312 virtual ~SERIALIZER ( 00313 ); 00314 00315 //! Close the serializer, will be done in destructor. 00316 void Close ( 00317 ); 00318 00319 //! Get path to serialization file. 00320 const FILEPATH& GetFilePath ( 00321 ) const { return (m_filepath); } 00322 00323 //! Determine if ignoring "skippable" items. 00324 bool GetIgnoreSkippable ( 00325 ) const { return (m_IgnoreSkippable); } 00326 00327 //! Get name of current item being read/written. 00328 const char* GetItemName ( 00329 ) const { return (m_itemname); } 00330 00331 //! Get value for current item being read. 00332 const MIUNICODE* GetItemValue ( 00333 ) const { return (m_parmvalue); } 00334 00335 //! Get value for current item as double. 00336 //! @return true if could convert, false if not 00337 bool GetItemValue ( 00338 double& value //!< Value returned 00339 ) const; 00340 00341 // Get log text. 00342 const MISTRING& GetLog ( 00343 ) const { return (m_Log); } 00344 00345 // Get log text (non-const). 00346 MISTRING& GetLog ( 00347 ) { return (m_Log); } 00348 00349 //! Get name of object, will be blank if text file. 00350 const MIUNICODE* GetObjectName ( 00351 ) const { return (m_objname); } 00352 00353 //! Get list of missing files/objects after scan, also clears the list. 00354 FNAMEINODEUC* GetScanListMissing ( 00355 ) { 00356 FNAMEINODEUC *temp = m_ScanFileObjListMissing; 00357 m_ScanFileObjListMissing = NULL; 00358 return (temp); 00359 } 00360 00361 //! Get list of "used" files/objects after scan, also clears the list. 00362 FNAMEINODEUC* GetScanListUsed ( 00363 ) { 00364 FNAMEINODEUC *temp = m_ScanFileObjListUsed; 00365 m_ScanFileObjListUsed = NULL; 00366 return (temp); 00367 } 00368 00369 //! Get current version setting. 00370 UINT16 GetVersion ( 00371 ) const { return (m_Version[m_depth]); } 00372 00373 //! Check if scanning serialization only. 00374 bool IsScanOnly ( 00375 ) const { return (m_ScanOnly); } 00376 00377 //! Clear serialization log. 00378 void LogClear ( 00379 ) { m_Log.Clear(); } 00380 00381 //! Add error message to log. 00382 //! Will insert newline before and after error text. 00383 void LogError ( 00384 ERRVALUE err 00385 ); 00386 00387 //! Add text to log. 00388 void LogText ( 00389 const MISTRING& text 00390 ) { m_Log << text; } 00391 00392 //! Create object to contain serialization using OBJITEM. 00393 ERRVALUE Make ( 00394 RVC::OBJITEM& objitem, //!< Object item reference passed/returned 00395 const RVC::SERIALIZE::MAKEPARMS& makeparms 00396 ); 00397 00398 //! Create object to contain serialization using parent and descriptor. 00399 ERRVALUE Make ( 00400 RVC::OBJECT& parent, //!< Parent object 00401 RVC::OBJTYPE objtype, //!< Object type 00402 RVC::DESCRIPTOR& descriptor, //!< Descriptor for new object 00403 const RVC::SERIALIZE::MAKEPARMS& makeparms 00404 ); 00405 00406 #ifndef DEPRECATE_ALL 00407 //! Create object to contain serialization. 00408 //! \deprecated Use RVC::OBJITEM version. 00409 DEPRECATED ERRVALUE Make ( 00410 const FILEPATH& filepath, //!< RVC file path 00411 RVCPARMINFO& objinfo //!< New or existing object header 00412 ); 00413 #endif 00414 00415 #ifndef DEPRECATE_ALL 00416 //! Create object to contain serialization. 00417 //! \deprecated Use RVC::OBJITEM version. 00418 DEPRECATED ERRVALUE Make ( 00419 int fhandle, //!< RVC file handle 00420 RVCPARMINFO& objinfo //!< New or existing object header 00421 ); 00422 #endif 00423 00424 //! Create text file to contain serialization. 00425 ERRVALUE Make ( 00426 const FILEPATH& filepath, //!< Text file path 00427 int version = 1 //!< Version to write 00428 ); 00429 00430 //! Open object containing serialization to read. 00431 ERRVALUE Open ( 00432 const RVC::OBJITEM& objitem //!< RVC object item reference 00433 ); 00434 00435 #ifndef DEPRECATE_ALL 00436 //! Open object containing serialization to read. 00437 //! \deprecated Use RVC::OBJITEM version. 00438 DEPRECATED ERRVALUE Open ( 00439 const FILEPATH& filepath, //!< RVC file path 00440 INT32 inode, //!< RVC object inode 00441 RVCPARMINFO& objinfo //!< Object header returned 00442 ); 00443 #endif 00444 00445 #ifndef DEPRECATE_ALL 00446 //! Open object containing serialization to read. 00447 //! \deprecated Use RVC::OBJITEM version. 00448 DEPRECATED ERRVALUE Open ( 00449 int fhandle, //!< Open RVC file handle 00450 INT32 inode, //!< RVC object inode 00451 RVCPARMINFO& objinfo //!< Object header returned 00452 ); 00453 #endif 00454 00455 //! Open text file containing serialization to read. 00456 ERRVALUE Open ( 00457 const FILEPATH& filepath //!< Text file path 00458 ); 00459 00460 //! Write beginning tag for starting a component. 00461 ERRVALUE PutBegin ( 00462 const char *tagname, //!< Tag name to write 00463 UINT16 version = 0 //!< Optional version 00464 ); 00465 00466 //! Write floating-point value. 00467 ERRVALUE PutDouble ( 00468 const char *tagname, //!< Tag name 00469 double value //!< Value to write 00470 ); 00471 00472 //! Write ending tag at end of a component. 00473 ERRVALUE PutEnd ( 00474 ); 00475 00476 //! Write integer value. 00477 ERRVALUE PutInt ( 00478 const char *tagname, //!< Tag name to write 00479 int value //!< Value to write 00480 ); 00481 00482 //! Write COLOR item. 00483 ERRVALUE PutItem ( 00484 const char *tagname, //!< Tag name to write 00485 const COLOR& color //!< Item value 00486 ); 00487 00488 //! Write DPOINT2D item. 00489 ERRVALUE PutItem ( 00490 const char *tagname, //!< Tag name to write 00491 const DPOINT2D& point2d //!< Item value 00492 ); 00493 00494 //! Write DPOINT3D item. 00495 ERRVALUE PutItem ( 00496 const char *tagname, //!< Tag name to write 00497 const DPOINT3D& point3d //!< Item value 00498 ); 00499 00500 //! Write DRECT2D item. 00501 ERRVALUE PutItem ( 00502 const char *tagname, //!< Tag name to write 00503 const DRECT2D& rect //!< Item value 00504 ); 00505 00506 //! Write DRECT3D item. 00507 ERRVALUE PutItem ( 00508 const char *tagname, //!< Tag name to write 00509 const DRECT3D& rect //!< Item value 00510 ); 00511 00512 //! Write LPOINT2D item. 00513 ERRVALUE PutItem ( 00514 const char *tagname, //!< Tag name to write 00515 const LPOINT2D& point2d //!< Item value 00516 ); 00517 00518 //! Write LRECT2D item. 00519 ERRVALUE PutItem ( 00520 const char *tagname, //!< Tag name to write 00521 const LRECT2D& rect //!< Item value 00522 ); 00523 00524 //! Write OLDPROJPARM item. 00525 ERRVALUE PutItem ( 00526 const char *tagname, //!< Tag name to write 00527 const OLDPROJPARM& oldprojparm //!< Item value 00528 ); 00529 00530 //! Write SPATREF::COORDREFSYS item. 00531 ERRVALUE PutItem ( 00532 const char *tagname, //!< Tag name to write 00533 const SPATREF::COORDREFSYS& crs //!< Item value 00534 ); 00535 00536 //! Write a single-line Unicode string 00537 ERRVALUE PutStr ( 00538 const char *tagname, //!< Tag name to write 00539 const MIUNICODE *str //!< String 00540 ); 00541 00542 //! Write a Multi-line Unicode String 00543 ERRVALUE PutStrML ( 00544 const char *tagname, //!< Tag name to write 00545 const MIUNICODE *str //!< String 00546 ); 00547 00548 //! Write unsigned integer value. 00549 ERRVALUE PutUnsigned ( 00550 const char *tagname, //!< Tag name to write 00551 unsigned int value //!< Item value 00552 ); 00553 00554 //! Read SERIALIZABLE object. 00555 inline ERRVALUE Read ( 00556 SERIALIZABLE& object //!< Object to read 00557 ); 00558 00559 //! Read SERIALIZABLE object. 00560 ERRVALUE Read ( 00561 const char *tagname, //!< Tag name to match 00562 SERIALIZABLE& object //!< Object to read 00563 ); 00564 00565 //! Read items from serialization. 00566 ERRVALUE Read ( 00567 const ITEMDEF *itemdef, //!< Item definition array 00568 void *data //!< Serialization data 00569 ); 00570 00571 //! Read items from serialization. 00572 ERRVALUE Read ( 00573 const char *tagname, //!< Tag name to match 00574 const ITEMDEF *itemdef, //!< Item definition array 00575 void *data //!< Serialization data 00576 ); 00577 00578 //! Read OLDPROJPARM from serialization. 00579 ERRVALUE Read ( 00580 OLDPROJPARM& oldprojparm 00581 ); 00582 00583 //! Rewind file to beginning. 00584 ERRVALUE Rewind ( 00585 ); 00586 00587 //! Set whether to ignore "skippable" items. 00588 void SetIgnoreSkippable ( 00589 bool IgnoreSkippable = true //!< Ignore skippable mode 00590 ) { m_IgnoreSkippable = IgnoreSkippable; } 00591 00592 //! Set scan-only mode. 00593 void SetScanOnly ( 00594 bool ScanOnly //!< Scan only mode 00595 ) { m_ScanOnly = ScanOnly; } 00596 00597 //! Set version (for overriding). 00598 void SetVersion ( 00599 UINT16 Version //!< Version 00600 ) { m_Version[m_depth] = Version; } 00601 00602 //! Skip remainder of current structure (for use in item callback). 00603 ERRVALUE SkipStruct ( 00604 ); 00605 00606 //! Update status text from Unicode string. 00607 ERRVALUE StatusTextUpdate ( 00608 const MIUNICODE *string 00609 ) { return (MstatusTextUpdateString(m_StatusContext,0,string)); } 00610 00611 //! Write items without begin/end tags. 00612 ERRVALUE Write ( 00613 const ITEMDEF *itemdef, //!< Item definition array 00614 const void *data //!< Data to write 00615 ); 00616 00617 //! Write items to serialized output. 00618 ERRVALUE Write ( 00619 const char *tagname, //!< Name to tag object with 00620 const ITEMDEF *itemdef, //!< Item definition array 00621 const void *data, //!< Data to write 00622 UINT16 version = 0 //!< Version to set if top level object 00623 ); 00624 00625 //! Write SERIALIZABLE object. 00626 inline ERRVALUE Write ( 00627 const SERIALIZABLE& object, //!< Object to write 00628 const char *tagname = 0 //!< Name to tag object with 00629 ); 00630 00631 private: 00632 #ifndef GENERATING_DOXYGEN_OUTPUT 00633 00634 FILEPATH m_filepath; //!< Path to file 00635 RVC::OBJECTNAME m_objname; //!< Name of object if in RVC file 00636 FILE *m_fp; //!< Text file handle if non-RVC 00637 int m_fhandle; //!< RVC file handle if Text object 00638 int m_ohandle; //!< RVC object handle for Text object 00639 int m_depth; //!< Current depth 00640 UINT16 m_Version[128]; //!< Version at current depth 00641 char m_itemname[128]; 00642 MIUNICODE m_parmvalue[2048]; //!< Last parameter value 00643 MSTATUSCONTEXT m_StatusContext; 00644 INT32 m_filesize; //!< Size of file/object being read for status update 00645 INT32 m_filepos; //!< Position in file/object for status update 00646 bool m_IgnoreSkippable; 00647 bool m_ScanOnly; 00648 FNAMEINODEUC *m_ScanFileObjListUsed; 00649 FNAMEINODEUC *m_ScanFileObjListMissing; 00650 MISTRING m_Log; 00651 00652 static const ITEMDEF* GetItemDefREGION2D ( 00653 ); 00654 00655 static const ITEMDEF* GetItemDefSUBREGION2D ( 00656 ); 00657 00658 //! Call callback for item if necessary. 00659 ERRVALUE CallItemCB ( 00660 const ITEMDEF *itemdef, 00661 void *data, //!< Callback data 00662 ITEMDEF::ACTION action //!< Callback action 00663 ); 00664 00665 //! Find link file, add to missing file list if can't find it. 00666 ERRVALUE FindLinkFile ( 00667 const ITEMDEF *parmdp, 00668 const UINT8* data, 00669 FILEPATH& linkfilepath, 00670 UINT32 findflags = 0 00671 ); 00672 00673 //! Find object. 00674 int FindObject ( 00675 const ITEMDEF *parmdp, 00676 const ITEMDEF *startdp, 00677 UINT8 *data 00678 ); 00679 00680 //! Find subobject. 00681 int FindSubObject ( 00682 const ITEMDEF *parmdp, 00683 const ITEMDEF *startdp, 00684 UINT8 *data 00685 ); 00686 00687 //! Get multi-line string (Unicode). 00688 ERRVALUE GetStrML ( 00689 MIUNICODE **str //!< XXX change to MISTRING& 00690 ); 00691 00692 //! Get multi-line string (ASCII or RAW). 00693 ERRVALUE GetStrML ( 00694 char **str, 00695 bool raw = false 00696 ); 00697 00698 //! 00699 ERRVALUE PutObjName ( 00700 const ITEMDEF *parmdp, 00701 const ITEMDEF *startdp, 00702 const UINT8 *data 00703 ); 00704 00705 //! 00706 ERRVALUE PutStr ( 00707 const char *tagname, 00708 const char *str //!< XXX eliminate 00709 ); 00710 00711 00712 //! 00713 ERRVALUE PutStrML ( 00714 const char *tagname, 00715 const char *str 00716 ); 00717 00718 //! 00719 ERRVALUE PutSubObjName ( 00720 const ITEMDEF *parmdp, 00721 const ITEMDEF *startdp, 00722 const UINT8 *data 00723 ); 00724 00725 //! 00726 ERRVALUE ReadLine ( 00727 MIUNICODE *buf, //!< XXX change to MISTRING& 00728 int bufsize, 00729 bool raw = false 00730 ); 00731 00732 //! Write single-line MIUNICODE string. 00733 ERRVALUE WriteText ( 00734 const MIUNICODE *str //!< String to write 00735 ); 00736 00737 //! Write ASCII string. 00738 ERRVALUE WriteText ( 00739 const char *str //!< String to write 00740 ); 00741 00742 SERIALIZER (const SERIALIZER&); 00743 SERIALIZER& operator= (const SERIALIZER&); 00744 #endif // GENERATING_DOXYGEN_OUTPUT 00745 }; 00746 00747 DEFINE_ENUM_OPERATORS(SERIALIZER::ITEMDEF::FLAGS); 00748 DEFINE_ENUM_OPERATORS(SERIALIZER::ITEMDEF::ACTION); 00749 00750 00751 //----------------------------------------------------------------------------- 00752 // SERIALIZABLE interface definition 00753 //----------------------------------------------------------------------------- 00754 00755 //! Interface class for making object serializable. 00756 //! Objects may be serialized without inheriting from this interface provided 00757 //! they are serialized as part of a container object. In general there are two 00758 //! reasons to inherit from SERIALIZABLE. 00759 //! 00760 //! 1. If the object will be a top-level item in the serialization. This 00761 //! makes it easy to read and write the object via the SERIALIZER Read() 00762 //! and Write() methods pertaining to SERIALIZABLE objects. Simple 00763 //! objects which may be represented by an ITEMDEF array do not need to 00764 //! be made serializable as there are Read/Write methods which may use 00765 //! this array. The GRE_LAYOUT and GRE_GROUP classes are examples. 00766 //! 00767 //! 2. If an object is contained within another object and has complicated 00768 //! serialization which must be implemented via functions rather than 00769 //! using and ITEMDEF array. This allows use of TYPE_SERIALIZABLE and 00770 //! TYPE_SERIALIZABLEPTR in the containing object's ITEMDEF array, thus 00771 //! simplifying its definition. The GRE_LAYER::DISPPARM class is an 00772 //! example of this case. 00773 //! 00774 //! By convention, if an object implements SerialRead and/or SerialWrite() the 00775 //! method signatures should match those used in SERIALIZABLE even if the class 00776 //! does not actually implement the SERIALIZABLE interface. This allows easy 00777 //! modification should it become necessary to implement the interface in the 00778 //! future. The GRE_LAYER class is an example of this case in that it defines 00779 //! both SerialRead() and SerialWrite() methods but does not specifically 00780 //! inherit from SERIALIZABLE. 00781 00782 class SERIALIZABLE { 00783 //! This is an "interface" class and must therefore 00784 //! only have virtual methods and no members. 00785 00786 public: 00787 00788 //! Read component from serialization. 00789 //! This method must be called only after the tag name has been read and 00790 //! is responsible for determining how to deserialize the component 00791 //! elements. When beginning a deserialization, usually the 00792 //! SERIALIZER::Read(tagname,object) method should be used to match 00793 //! the desired tag name which was used in writing. 00794 //! A default implementation is not possible due to multiple inheritance 00795 //! resulting in a different "this" pointer being passed than the actual 00796 //! object, which causes the offset values in the ITEMDEF arrays to be wrong. 00797 virtual ERRVALUE SerialRead ( 00798 SERIALIZER& serializer 00799 ) = 0; 00800 00801 //! Write object to serialization. 00802 //! This method must write the tag name provided, using SERIALIZER::PutBegin(). 00803 //! If the tagname is 0 (default) then it must determine the proper tag name to 00804 //! write. After writing the object this method must write the ending tag using 00805 //! SERIALIZER::PutEnd(). 00806 //! When inheriting this interface, the default value of 0 for the tag name 00807 //! must NOT be redefined. (See Meyers, Effective C++, item #38) 00808 //! A default implementation is not possible due to multiple inheritance 00809 //! resulting in a different "this" pointer being passed than the actual 00810 //! object, which causes the offset values in the ITEMDEF arrays to be wrong. 00811 virtual ERRVALUE SerialWrite ( 00812 SERIALIZER& serializer, 00813 const char *tagname = 0 00814 ) const = 0; 00815 }; 00816 00817 00818 //----------------------------------------------------------------------------- 00819 //! Inline methods 00820 //----------------------------------------------------------------------------- 00821 00822 #ifndef GENERATING_DOXYGEN_OUTPUT 00823 00824 inline ERRVALUE SERIALIZER::Read ( 00825 SERIALIZABLE& object 00826 ) { 00827 return (object.SerialRead(*this)); 00828 } 00829 00830 inline ERRVALUE SERIALIZER::Write ( 00831 const SERIALIZABLE& object, 00832 const char *tagname 00833 ) { 00834 return (object.SerialWrite(*this,tagname)); 00835 } 00836 00837 #endif //!< GENERATING_DOXYGEN_OUTPUT 00838 00839 #ifdef WIN32 00840 #pragma warning (default:4996) // Restore warning about deprecated declaration 00841 #endif 00842 00843 #endif //!< INC_MI32_SERIALIZ_H
1.3.8-20040913