GizmoBase

gzSerialize.h

Go to the documentation of this file.
00001 // *****************************************************************************
00002 // File         : gzSerialize.h
00003 // Module       : gzBase
00004 // Description  : Class definition of serialize classes
00005 // Author       : Anders Modén      
00006 // Product      : GizmoBase 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden       
00009 //          
00010 // NOTE:    GizmoBase is a platform abstraction utility layer for C++. It contains 
00011 //          design patterns and C++ solutions for the advanced programmer.
00012 //
00013 //
00014 // Revision History...                          
00015 //                                  
00016 // Who  Date    Description                     
00017 //                                  
00018 // AMO  981019  Created file    
00019 //
00020 // ******************************************************************************
00021 
00022 #ifndef __GZ_SERIALIZE_H__
00023 #define __GZ_SERIALIZE_H__
00024 
00032 #include "gzBasicTypes.h"
00033 #include "gzMemory.h"
00034 #include "gzBase.h"
00035 #include "gzTemplates.h"
00036 #include "gzMatrix.h"
00037 #include "gzMutex.h"
00038 #include "gzGuid.h"
00039 #include "gzXYZ.h"
00040 #include "gzIO.h"
00041 
00042 //#include <stdio.h>
00043 
00044 enum gzSerializeAction { GZ_SERIALIZE_OUTPUT=1 , GZ_SERIALIZE_INPUT=2 , GZ_SERIALIZE_DUPLEX=GZ_SERIALIZE_OUTPUT|GZ_SERIALIZE_INPUT} ;
00045 
00046 const gzString  GZ_LOG_NAME             ="gizmosdk.log";
00047 
00048 class gzSerializeData;
00049 
00050 const gzString  GZ_URLBASE_FILE             = "file:";  // file name
00051 const gzString  GZ_URLBASE_HTTP             = "http:";  // http url
00052 const gzString  GZ_URLBASE_FTP              = "ftp:";   // ftp url
00053 const gzString  GZ_URLBASE_MEMORY           = "mem:";   // address,length
00054 const gzString  GZ_URLBASE_REGISTRY         = "reg:";   // name of registry key
00055 const gzString  GZ_URLBASE_ZIP              = "zip:";   // name of archive
00056 const gzString  GZ_URLBASE_PIPE             = "pipe:";  // name of pipe
00057 const gzString  GZ_URLBASE_PURL             = "purl:";  // "pipename","url"
00058 const gzString  GZ_URLBASE_CONSOLE          = "con:";   // console
00059 const gzString  GZ_URLBASE_CACHE            = "cache:"; // offset,len,url
00060 const gzString  GZ_URLBASE_ADAPTER          = "adapt:"; // address of adapter
00061 const gzString  GZ_URLBASE_RANDOM_ACCESS    = "rand:";  // add random access
00062 
00063 
00064 //******************************************************************************
00065 // Class    : gzAdapterSharedData
00066 //                                  
00067 // Purpose  : Utility data holder for serializing adapters
00068 //                                  
00069 // Notes    : -
00070 //                                  
00071 // Revision History...                          
00072 //                                  
00073 // Who  Date    Description                     
00074 //                                  
00075 // AMO  010508  Created 
00076 //                                  
00077 //******************************************************************************
00078 class gzAdapterSharedData : public gzReference
00079 {
00080 public:
00081 
00082     gzAdapterSharedData():index(0),size(0),saved(FALSE){};
00083 
00084     gzULong index;
00085     gzULong size;
00086     gzBool  saved;
00087 };
00088 
00089 // !Serialize Adapter loader flags
00091 typedef gzULongLong gzSerializeAdapterFlags;
00092 
00093 const gzSerializeAdapterFlags   GZ_SERIALIZE_ADAPTER_FLAGS_DEFAULT  =   0;
00094 const gzSerializeAdapterFlags   GZ_SERIALIZE_ADAPTER_NO_ERROR_MSG   =   (1<<0);
00095 const gzSerializeAdapterFlags   GZ_SERIALIZE_ADAPTER_WIDECHAR       =   (1<<1);
00096 const gzSerializeAdapterFlags   GZ_SERIALIZE_ADAPTER_BIG_ENDIAN     =   (1<<2);
00097 
00098 
00100 const gzULong GZ_SERIALIZE_ADAPTER_FLAG_MAX_SIZE            =   3;  // Number of flags in image flag set
00101 
00102 //******************************************************************************
00103 // Class    : gzSerializeURLManagerInterface
00104 //                                  
00105 // Purpose  : Base interface fro registered URL managers
00106 //                                  
00107 // Notes    : 
00108 //                                  
00109 // Revision History...                          
00110 //                                  
00111 // Who  Date    Description                     
00112 //                                  
00113 // AMO  060817  Created 
00114 //                                  
00115 //******************************************************************************
00116 class gzSerializeURLManagerInterface : public gzReference
00117 {
00118 public:
00119 
00120     GZ_BASE_EXPORT virtual gzSerializeAdapter *getURLAdapter(const gzString &url,gzSerializeAction action,gzSerializeAdapterFlags flags, const gzString &password)=0;
00121 };
00122 
00123 //******************************************************************************
00124 // Class    : gzSerializeAdapter
00125 //                                  
00126 // Purpose  : Base class for Serialize Adapter
00127 //                                  
00128 // Notes    : the gzUInt size provides for larger token sizes
00129 //                                  
00130 // Revision History...                          
00131 //                                  
00132 // Who  Date    Description                     
00133 //                                  
00134 // AMO  981019  Created 
00135 //                                  
00136 //******************************************************************************
00137 class  gzSerializeAdapter : public gzReference , public gzNameInterface 
00138 {
00139 public:
00140 
00141     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // RTTI
00142         
00143     GZ_BASE_EXPORT gzSerializeAdapter(const gzString & name);
00144     GZ_BASE_EXPORT gzSerializeAdapter();
00145 
00146     GZ_BASE_EXPORT virtual ~gzSerializeAdapter(){};
00147 
00148     GZ_BASE_EXPORT gzVoid   serialize(gzSerializeData *data , gzSerializeAction action);
00149 
00150     GZ_BASE_EXPORT gzVoid   write(gzUByte data);
00151     GZ_BASE_EXPORT gzUByte  read();
00152 
00153     GZ_BASE_EXPORT gzVoid   write(gzUByte *data,gzULong count);
00154     GZ_BASE_EXPORT gzULong  read(gzUByte *data,gzULong maxcount);
00155     
00156     GZ_BASE_EXPORT gzVoid   pushBack(gzUByte value);
00157     GZ_BASE_EXPORT gzVoid   pushBack(gzUByte *data,gzULong maxcount);
00158 
00159     GZ_BASE_EXPORT gzBool   hasData(gzULong mincount=1);
00160 
00162     GZ_BASE_EXPORT virtual  gzBool      canSeek(){ return FALSE; }
00163     GZ_BASE_EXPORT virtual  gzMemSize   seek(gzMemOffset offset, gzOriginPos origin=GZ_ORIGIN_SET){ return -1; }
00164     GZ_BASE_EXPORT virtual  gzVoid      setSeekMode(gzBool on){}
00165 
00167     GZ_BASE_EXPORT virtual gzBool       supportAction(gzSerializeAction action) {return TRUE;}
00168 
00169     GZ_BASE_EXPORT gzULong  length();
00170     
00171     GZ_BASE_EXPORT virtual  gzVoid flush();
00172 
00173     // ------------- Misc ------------------------------------------------------------------------------
00174 
00175     GZ_BASE_EXPORT gzBool   hasError();
00176 
00177     GZ_PROPERTY_EXPORT_I(gzString,                  Error               ,GZ_BASE_EXPORT);
00178     GZ_PROPERTY_EXPORT(gzSerializeAdapterFlags,     AdapterFlags        ,GZ_BASE_EXPORT);
00179     GZ_PROPERTY_EXPORT(gzULong,                     AdapterVersion      ,GZ_BASE_EXPORT);
00180 
00181     //---- Generic utilities for sharing used in serialization ------------------------------------------
00182 
00183     GZ_BASE_EXPORT virtual gzRefInstanceDictionary &getRefInstanceDictionary();
00184 
00185     GZ_BASE_EXPORT virtual gzRefInstanceArray &     getRefInstanceArray();
00186 
00187     GZ_BASE_EXPORT virtual gzULong                  getNewSharedInstanceID();
00188 
00189     GZ_BASE_EXPORT virtual gzVoid                   clearSharedRefs();
00190     
00191     GZ_BASE_EXPORT gzVoid                           copySharedRefData(const gzSerializeAdapter& inst);
00192 
00193     //--- Generic utils for URL management --------------------------------------------------------------
00194 
00195     // URL
00196 
00197     GZ_BASE_EXPORT gzString         getURL();
00198 
00199     GZ_PROPERTY_EXPORT(gzString,                    URLBase             ,GZ_BASE_EXPORT);
00200     GZ_PROPERTY_EXPORT(gzString,                    DefaultPath         ,GZ_BASE_EXPORT);
00201 
00202     // Password management
00203     GZ_PROPERTY_EXPORT(gzString,                    Password            ,GZ_BASE_EXPORT);
00204 
00205     // Controller Interface
00206     GZ_PROPERTY_EXPORT(gzRefPointer<gzReference>,   AssociatedData      ,GZ_BASE_EXPORT);
00207 
00208 
00209     //--- The VERY generic URL based adaptor factory ----------------------------------------------------
00210 
00211     GZ_BASE_EXPORT static gzSerializeAdapter *getURLAdapter(const gzString &url,gzSerializeAction action=GZ_SERIALIZE_INPUT,gzSerializeAdapterFlags flags=GZ_SERIALIZE_ADAPTER_FLAGS_DEFAULT, const gzString &password=GZ_EMPTY_STRING);
00212     GZ_BASE_EXPORT static gzVoid registerURLManager(const gzString &urlBase,gzSerializeURLManagerInterface *manager);
00213     GZ_BASE_EXPORT static gzVoid unregisterURLManager(const gzString &urlBase,gzSerializeURLManagerInterface *manager);
00214 
00216 
00219     GZ_BASE_EXPORT static gzBool    getURLBaseEncoding(const gzString &url, gzString *_urlBase=NULL,gzString *_defaultPath=NULL,gzString *_urlName=NULL,gzString *_urlAttributes=NULL);
00220     GZ_BASE_EXPORT static gzString  getURLAttributeValue(const gzString &attributeName,const gzString &urlAttributes);
00221 
00222 protected:
00223         
00225     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte data)=0;
00226 
00228     GZ_BASE_EXPORT virtual gzUByte  read_imp()=0;
00229 
00231     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte *data,gzULong count);
00232     
00234     GZ_BASE_EXPORT virtual gzULong  read_imp(gzUByte *data,gzULong maxcount);
00235     
00237     GZ_BASE_EXPORT virtual gzULong  length_imp();
00238 
00239     GZ_BASE_EXPORT virtual gzBool   hasData_imp();
00240 
00241     // -----------------------------------------
00242 
00243     gzQueue<gzUByte>            m_pushback;
00244     gzString                    m_propertyError;
00245 
00246     // Generic adapter utilites
00247 
00248     gzLateBindData<gzRefInstanceDictionary> m_refDict;  // Generic dictionary
00249     gzLateBindData<gzRefInstanceArray>      m_refArray; // Generic array
00250     gzULong                                 m_counter;  // Generic counter
00251 
00252     static gzRefDict<gzString,gzSerializeURLManagerInterface>   s_urlManagers;
00253 };
00254 
00255 GZ_DECLARE_REFPTR(gzSerializeAdapter);
00256 
00257 //******************************************************************************
00258 // Class    : gzSerializeAdapterStdIO
00259 //                                  
00260 // Purpose  : Class for Serialize data to STDIO
00261 //                                  
00262 // Notes    : This class is responsible to write/read data to adapter
00263 //                                  
00264 // Revision History...                          
00265 //                                  
00266 // Who  Date    Description                     
00267 //                                  
00268 // AMO  981019  Created 
00269 //                                  
00270 //******************************************************************************
00271 class  gzSerializeAdapterStdIO : public gzSerializeAdapter
00272 {
00273 public:
00274     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // RTTI
00275 
00276     GZ_BASE_EXPORT gzSerializeAdapterStdIO():gzSerializeAdapter("StdIO"){};
00277 
00278     GZ_BASE_EXPORT virtual ~gzSerializeAdapterStdIO(){};
00279 
00280 protected:
00281         
00282     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte data);
00283     GZ_BASE_EXPORT virtual gzUByte  read_imp();
00284     GZ_BASE_EXPORT virtual gzBool   hasData_imp();
00285 };
00286 
00287 //******************************************************************************
00288 // Class    : gzSerializeAdapterMemory
00289 //                                  
00290 // Purpose  : Class for Serialize data to memory
00291 //                                  
00292 // Notes    : This class is responsible to write/read data to adapter
00293 //                                  
00294 // Revision History...                          
00295 //                                  
00296 // Who  Date    Description                     
00297 //                                  
00298 // AMO  981019  Created 
00299 //                                  
00300 //******************************************************************************
00301 class  gzSerializeAdapterMemory : public gzSerializeAdapter
00302 {
00303 public:
00304     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // RTTI
00305 
00306     GZ_BASE_EXPORT gzSerializeAdapterMemory(gzVoid *adress,gzULong maxlen);
00307 
00308     GZ_BASE_EXPORT virtual  ~gzSerializeAdapterMemory(){};
00309 
00310     GZ_BASE_EXPORT gzVoid   reset(gzVoid *adress=NULL,gzULong maxlen=0);
00311 
00312     GZ_BASE_EXPORT virtual gzVoid move(gzInt steps);
00313 
00314     GZ_BASE_EXPORT virtual  gzVoid flush();
00315 
00316 protected:
00317         
00318     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte data);
00319     GZ_BASE_EXPORT virtual gzUByte  read_imp();
00320 
00321     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte *data,gzULong count);
00322     GZ_BASE_EXPORT virtual gzULong  read_imp(gzUByte *data,gzULong maxcount);
00323     GZ_BASE_EXPORT virtual gzULong  length_imp();
00324 
00325     gzUByte *   m_adress;
00326     gzULong     m_len;
00327     gzULong     m_currentPos;
00328 };
00329 
00330 GZ_DECLARE_REFPTR(gzSerializeAdapterMemory);
00331 
00332 //******************************************************************************
00333 // Class    : gzSerializeAdapterFile
00334 //                                  
00335 // Purpose  : Class for Serialize data to File
00336 //                                  
00337 // Notes    : This class is responsible to write/read data to adapter
00338 //                                  
00339 // Revision History...                          
00340 //                                  
00341 // Who  Date    Description                     
00342 //                                  
00343 // AMO  981019  Created 
00344 //                                  
00345 //******************************************************************************
00346 class  gzSerializeAdapterFile : public gzSerializeAdapter
00347 {
00348 public:
00349     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_BASE_EXPORT);   // RTTI
00350 
00351     GZ_BASE_EXPORT gzSerializeAdapterFile(const gzString &filename,gzSerializeAction action=GZ_SERIALIZE_INPUT,gzBool append=FALSE);
00352 
00353     GZ_BASE_EXPORT virtual ~gzSerializeAdapterFile();
00354 
00355     GZ_BASE_EXPORT virtual gzVoid flush();
00356 
00357     GZ_BASE_EXPORT virtual gzBool reset(gzULong position=0);
00358 
00359     GZ_BASE_EXPORT static gzVoid cleanUpLargeFiles();
00360 
00361     GZ_BASE_EXPORT  gzBool  readLargeChunks();
00362     GZ_BASE_EXPORT  gzVoid  readLargeChunks(gzBool on=TRUE);
00363 
00364     GZ_BASE_EXPORT virtual  gzBool canSeek();
00365     GZ_BASE_EXPORT virtual  gzMemSize seek(gzMemOffset offset, gzOriginPos origin=GZ_ORIGIN_SET);
00366     GZ_BASE_EXPORT virtual  gzVoid setSeekMode(gzBool on);
00367 
00368     GZ_BASE_EXPORT virtual gzBool supportAction(gzSerializeAction action);
00369 
00370 protected:
00371         
00372     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte data);
00373     GZ_BASE_EXPORT virtual gzUByte  read_imp();
00374 
00375     GZ_BASE_EXPORT virtual gzVoid   write_imp(gzUByte *data,gzULong count);
00376     GZ_BASE_EXPORT virtual gzULong  read_imp(gzUByte *data,gzULong maxcount);
00377     GZ_BASE_EXPORT virtual gzULong  length_imp();
00378 
00379 private:
00380 
00381     gzVoid readFileData();
00382     
00383     class gzFileQueue : public gzRecycleData<gzQueue<gzUByte> >
00384     {
00385         public:
00386             virtual gzVoid onInitItem(gzQueue<gzUByte> & data) const;
00387     };
00388     
00389 
00390     gzFileQueue             m_data;
00391     gzString                m_file;
00392     gzSerializeAction       m_mode;
00393     gzFileHandle            m_filehandle;
00394     gzULong                 m_leftOnDisc;   
00395     gzBool                  m_readLargeChunks;
00396     
00397 };
00398 
00399 //******************************************************************************
00400 // Class    : gzSerializeData
00401 //                                  
00402 // Purpose  : Base class for Serialize data
00403 //                                  
00404 // Notes    : This class is responsible to write/read data to adapter
00405 //                                  
00406 // Revision History...                          
00407 //                                  
00408 // Who  Date    Description                     
00409 //                                  
00410 // AMO  981019  Created 
00411 //                                  
00412 //******************************************************************************
00413 class  gzSerializeData 
00414 {
00415 public:
00416     GZ_BASE_EXPORT virtual ~gzSerializeData(){};
00417 
00418     GZ_BASE_EXPORT virtual gzVoid write(gzSerializeAdapter *adapter)=0;
00419 
00420     GZ_BASE_EXPORT virtual gzVoid read(gzSerializeAdapter *adapter)=0;
00421 
00422     GZ_BASE_EXPORT virtual gzVoid pushBack(gzSerializeAdapter *adapter)=0;
00423 
00424     GZ_BASE_EXPORT virtual gzULong  getDataSize(gzSerializeAdapter *adapter=NULL) const =0;
00425 };
00426 
00427 //******************************************************************************
00428 // Class    : gzSerializePacketInterface
00429 //                                  
00430 // Purpose  : Interface that can be implemented by some adapters
00431 //                                  
00432 // Notes    : 
00433 //                                  
00434 // Revision History...                          
00435 //                                  
00436 // Who  Date    Description                     
00437 //                                  
00438 // AMO  981019  Created 
00439 //                                  
00440 //******************************************************************************
00441 class gzSerializePacketInterface
00442 {
00443 public:
00444 
00445     virtual gzULong getDroppedPackets(gzBool clearDroppedPackages=TRUE)=0;
00446 
00447     virtual gzDouble getAveragePacketSize()=0;
00448 
00449     virtual gzDouble getAveragePacketsPerSecond()=0;
00450 };
00451 
00452 typedef gzSerializePacketInterface * gzSerializePacketInterfacePtr;
00453 
00454 const gzString GZ_SERIALIZE_PACKET_INTERFACE="gzSerializePacketInterface";
00455 
00456 
00457 //******************************************************************************
00458 // Class    : gzSerializeBinary
00459 //                                  
00460 // Purpose  : Template for binary storage
00461 //                                  
00462 // Notes    : This class is responsible to write/read data to adapter
00463 //                                  
00464 // Revision History...                          
00465 //                                  
00466 // Who  Date    Description                     
00467 //                                  
00468 // AMO  990301  Created 
00469 //                                  
00470 //******************************************************************************
00471 template <class T> class gzSerializeBinary : public gzSerializeData
00472 {
00473 public:
00474 
00475     explicit gzSerializeBinary<T>(  const gzBool useBigEndian=TRUE):m_useBigEnadian(useBigEndian){};
00476 
00477     gzBool operator==(const gzSerializeBinary<T> &right) { return m_data==right.m_data; }
00478 
00479     gzBool operator!=(const gzSerializeBinary<T> &right) { return m_data!=right.m_data; }
00480 
00481     virtual ~gzSerializeBinary<T>(){};
00482 
00483     virtual gzVoid write(gzSerializeAdapter *adapter);
00484 
00485     virtual gzVoid read(gzSerializeAdapter *adapter);
00486 
00487     virtual gzVoid pushBack(gzSerializeAdapter *adapter);
00488 
00489     virtual gzULong getDataSize(gzSerializeAdapter *adapter=NULL) const { return sizeof(m_data); }
00490 
00491     T & getRef()                                                        {return m_data; }
00492 
00493     operator  T () const                                                { return m_data; }
00494 
00495     T & operator = (const T &data)                                      { m_data=data; return m_data; }
00496     
00497     gzVoid setBigEndian(gzBool useBigEndian)                            { m_useBigEnadian = useBigEndian; }
00498 
00499 private:
00500 
00501 
00502     T       m_data;
00503 
00504     gzBool  m_useBigEnadian;
00505 
00506 };  
00507 
00508 // Initialisation
00509 template <> inline gzSerializeBinary<gzUByte>::gzSerializeBinary(  const gzBool useBigEndian):m_useBigEnadian(useBigEndian),m_data(0){}
00510 template <> inline gzSerializeBinary<gzFloat>::gzSerializeBinary(  const gzBool useBigEndian):m_useBigEnadian(useBigEndian),m_data(0){}
00511 template <> inline gzSerializeBinary<gzDouble>::gzSerializeBinary(  const gzBool useBigEndian):m_useBigEnadian(useBigEndian),m_data(0){}
00512 template <> inline gzSerializeBinary<gzULong>::gzSerializeBinary(  const gzBool useBigEndian):m_useBigEnadian(useBigEndian),m_data(0){}
00513 template <> inline gzSerializeBinary<gzLong>::gzSerializeBinary(  const gzBool useBigEndian):m_useBigEnadian(useBigEndian),m_data(0){}
00514 
00515 template <class T> inline gzVoid gzSerializeBinary<T>::write(gzSerializeAdapter *adapter)
00516 {
00517     gzUByte *data=(gzUByte *)&m_data;
00518 
00519     if(gzBigEndian())
00520     {
00521         if(m_useBigEnadian)
00522         {
00523             adapter->write(data,sizeof(m_data));
00524         }
00525         else
00526         {
00527             data+=(sizeof(m_data)-1);
00528 
00529             for(gzULong i=0;i<sizeof(m_data);i++)
00530                 adapter->write(*data--);
00531         }
00532     }
00533     else    // Intel
00534     {
00535         if(!m_useBigEnadian)
00536         {
00537             adapter->write(data,sizeof(m_data));
00538         }
00539         else
00540         {
00541             data+=(sizeof(m_data)-1);
00542 
00543             for(gzULong i=0;i<sizeof(m_data);i++)
00544                 adapter->write(*data--);
00545         }
00546     }
00547 
00548 }
00549 
00550 template <class T> inline gzVoid gzSerializeBinary<T>::pushBack(gzSerializeAdapter *adapter)
00551 {
00552     gzUByte *data=(gzUByte *)&m_data;
00553 
00554     if(gzBigEndian())   // Irix etc..
00555     {
00556 
00557         if(!m_useBigEnadian)
00558         {
00559             for(gzULong i=0;i<sizeof(m_data);++i)
00560             {
00561                 adapter->pushBack(*data);
00562                 ++data;
00563             }
00564         }
00565         else
00566         {
00567             data+=(sizeof(m_data)-1);
00568 
00569             for(gzULong i=0;i<sizeof(m_data);++i)
00570             {
00571                 adapter->pushBack(*data);
00572                 --data;
00573             }
00574         }
00575     }
00576     else    // Intel
00577     {
00578         if(m_useBigEnadian)
00579         {
00580             for(gzULong i=0;i<sizeof(m_data);++i)
00581             {
00582                 adapter->pushBack(*data);
00583                 ++data;
00584             }
00585         }
00586         else
00587         {
00588             data+=(sizeof(m_data)-1);
00589 
00590             for(gzULong i=0;i<sizeof(m_data);++i)
00591             {
00592                 adapter->pushBack(*data);
00593                 --data;
00594             }
00595         }
00596     }
00597 }
00598 
00599 
00600 template <class T> inline gzVoid gzSerializeBinary<T>::read(gzSerializeAdapter *adapter)
00601 {
00602     gzUByte *data=(gzUByte *)&m_data;
00603 
00604     if(gzBigEndian()) // Irix etc..
00605     {
00606 
00607         if(m_useBigEnadian)
00608         {
00609             adapter->read(data,sizeof(m_data));
00610         }
00611         else
00612         {
00613             data+=(sizeof(m_data)-1);
00614 
00615             for(gzULong i=0;i<sizeof(m_data);i++)
00616                 *data--=adapter->read();
00617         }
00618     }
00619     else    // Intel
00620     {
00621         if(!m_useBigEnadian)
00622         {
00623             adapter->read(data,sizeof(m_data));
00624         }
00625         else
00626         {
00627             data+=(sizeof(m_data)-1);
00628 
00629             for(gzULong i=0;i<sizeof(m_data);i++)
00630                 *data--=adapter->read();
00631         }
00632 
00633     }
00634 
00635 }   
00636 
00637 //******************************************************************************
00638 // Class    : gzVarULongLong
00639 //                                  
00640 // Purpose  : -
00641 //                                  
00642 // Notes    : -
00643 //                                  
00644 // Revision History...                          
00645 //                                  
00646 // Who  Date    Description                     
00647 //                                  
00648 // AMO  000531  Created 
00649 //                                  
00650 //******************************************************************************
00651 class gzVarULongLong : public gzSerializeData
00652 {
00653 public:
00654 
00655     GZ_BASE_EXPORT gzVarULongLong(const gzULongLong &value=0);
00656 
00657     GZ_BASE_EXPORT operator gzULongLong ();
00658 
00659     GZ_BASE_EXPORT virtual gzVoid write(gzSerializeAdapter *adapter);
00660 
00661     GZ_BASE_EXPORT virtual gzVoid read(gzSerializeAdapter *adapter);
00662 
00663     GZ_BASE_EXPORT virtual gzVoid pushBack(gzSerializeAdapter *adapter);
00664 
00665     GZ_BASE_EXPORT virtual gzULong  getDataSize(gzSerializeAdapter *adapter=NULL) const ;
00666 
00667 private:
00668 
00669     gzULongLong m_value;
00670 };
00671 
00672 //******************************************************************************
00673 // Class    : gzSerializeArray
00674 //                                  
00675 // Purpose  : Template for storage of arrays of serialize data
00676 //                                  
00677 // Notes    : This class is responsible to write/read data to adapter
00678 //            YOU HAVE TO SET THE SIZE before reading. No storage of size
00679 //            See also gzSerializeBinaryArray
00680 //                                  
00681 // Revision History...                          
00682 //                                  
00683 // Who  Date    Description                     
00684 //                                  
00685 // AMO  000531  Created 
00686 //                                  
00687 //******************************************************************************
00688 template <class T> class gzSerializeArray : public gzSerializeData
00689 {
00690 public:
00691     
00692     gzSerializeArray<T>(gzULong size=0):m_data(size){};
00693 
00694     virtual gzVoid write(gzSerializeAdapter *adapter)
00695     {
00696         gzULong i;
00697         for(i=0;i<m_data.getSize();i++)
00698             m_data[i].write(adapter);
00699     }
00700 
00701     virtual gzVoid read(gzSerializeAdapter *adapter)
00702     {
00703         gzULong i;
00704         for(i=0;i<m_data.getSize();i++)
00705             m_data[i].read(adapter);
00706     }
00707 
00708     virtual gzVoid pushBack(gzSerializeAdapter *adapter)
00709     {
00710         gzULong i;
00711         for(i=0;i<m_data.getSize();i++)
00712             m_data[m_data.getSize()-1-i].pushBack(adapter);
00713     }
00714 
00715 
00716     virtual gzULong getDataSize(gzSerializeAdapter *adapter=NULL) const 
00717     {
00718         gzULong i,size=0;
00719         gzArray<T> &ptr=(gzArray<T> &)m_data;
00720         for(i=0;i<ptr.getSize();i++)
00721             size+=ptr[i].getDataSize(adapter);
00722         return size;
00723     }
00724 
00725     
00726     T & operator [](gzULong index)                                      { return m_data[index]; }
00727 
00728     operator const gzArray<T> & () const                                { return m_data; }
00729 
00730     const gzArray<T> & operator = (const gzArray<T>& data)              { m_data=data; return m_data; }
00731 
00732     operator    gzString ();
00733 
00734     gzVoid      setSize(gzULong size)                                   { m_data.setSize(size); }
00735 
00736     gzULong     getSize()       const                                   { return m_data.getSize(); }
00737 
00738 private:
00739 
00740     gzArray<T>      m_data;
00741 
00742 };
00743 
00744 template <class T> inline gzSerializeArray<T>::operator gzString()
00745 {
00746     gzULong len=getDataSize();
00747 
00748     char *buffer=new char[len+1];
00749 
00750     gzSerializeAdapterMemory adapter(buffer,len);
00751 
00752     write(&adapter);
00753 
00754     buffer[len]='\0';
00755 
00756     gzString result(buffer);
00757 
00758     delete [] buffer;
00759 
00760     return result;  // If string data contains a zero byte data it will be terminated
00761 }
00762 
00763 //******************************************************************************
00764 // Class    : gzSerializeDynamicArray
00765 //                                  
00766 // Purpose  : Template for storage of arrays of serialize data
00767 //                                  
00768 // Notes    : This class is responsible to write/read data to adapter
00769 //            YOU HAVE TO SET THE SIZE before reading. No storage of size
00770 //            See also gzSerializeBinaryArray
00771 //                                  
00772 // Revision History...                          
00773 //                                  
00774 // Who  Date    Description                     
00775 //                                  
00776 // AMO  000531  Created 
00777 //                                  
00778 //******************************************************************************
00779 template <class T> class gzSerializeDynamicArray : public gzSerializeData
00780 {
00781 public:
00782     
00783     gzSerializeDynamicArray<T>(gzULong size=0):m_data(size){};
00784 
00785     virtual gzVoid write(gzSerializeAdapter *adapter)
00786     {
00787         gzULong i;
00788         for(i=0;i<m_data.getSize();i++)
00789             m_data[i].write(adapter);
00790     }
00791 
00792     virtual gzVoid read(gzSerializeAdapter *adapter)
00793     {
00794         gzULong i;
00795         for(i=0;i<m_data.getSize();i++)
00796             m_data[i].read(adapter);
00797     }
00798 
00799     virtual gzVoid pushBack(gzSerializeAdapter *adapter)
00800     {
00801         gzULong i;
00802         for(i=0;i<m_data.getSize();i++)
00803             m_data[m_data.getSize()-1-i].pushBack(adapter);
00804     }
00805 
00806 
00807     virtual gzULong getDataSize(gzSerializeAdapter *adapter=NULL) const 
00808     {
00809         gzULong i,size=0;
00810         gzArray<T> &ptr=(gzArray<T> &)m_data;
00811         for(i=0;i<ptr.getSize();i++)
00812             size+=ptr[i].getDataSize(adapter);
00813         return size;
00814     }
00815 
00816     
00817     T & operator [](gzULong index)                                          { return m_data[index]; }
00818 
00819     operator const gzDynamicArray<T> & () const                             { return m_data; }
00820 
00821     const gzDynamicArray<T> & operator = (const gzDynamicArray<T>& data)    { m_data=data; return m_data; }
00822 
00823     operator    gzString ();
00824     
00825     gzVoid      setSize(gzULong size)                                       { m_data.setSize(size); }
00826 
00827     gzULong     getSize()       const                                       { return m_data.getSize(); }
00828 
00829 private:
00830 
00831     gzDynamicArray<T>       m_data;
00832 
00833 };
00834 
00835 template <class T> inline gzSerializeDynamicArray<T>::operator gzString()
00836 {
00837     gzULong len=getDataSize();
00838 
00839     char *buffer=new char[len+1];
00840 
00841     gzSerializeAdapterMemory adapter(buffer,len);
00842 
00843     write(&adapter);
00844 
00845     buffer[len]='\0';
00846 
00847     gzString result(buffer);
00848 
00849     delete [] buffer;
00850 
00851     return result;  // If string data contains a zero byte data it will be terminated
00852 }
00853 
00854 //******************************************************************************
00855 // Class    : gzSerializeString
00856 //                                  
00857 // Purpose  : Help class for null terminated string storage
00858 //                                  
00859 // Notes    : This class is responsible to write/read data to adapter
00860 //                                  
00861 // Revision History...                          
00862 //                                  
00863 // Who  Date    Description                     
00864 //                                  
00865 // AMO  990401  Created 
00866 //                                  
00867 //******************************************************************************
00868 class  gzSerializeString : public gzSerializeData
00869 {
00870 public:
00871 
00872     GZ_BASE_EXPORT gzSerializeString(gzUByte terminator=0):m_terminator(terminator){};
00873 
00874     GZ_BASE_EXPORT gzSerializeString(const gzString &string,gzUByte terminator=0):m_data(string),m_terminator(terminator){};
00875 
00876     GZ_BASE_EXPORT virtual ~gzSerializeString(){};
00877 
00878     GZ_BASE_EXPORT virtual gzVoid