GizmoBase

serialize.cpp

Example which shows how to use serialization. The source code can also be found in the examples directory of the GizmoBase distribution.

00001 // *****************************************************************************
00002 // File         : serialize.cpp
00003 // Module       : 
00004 // Description  : Test implementation of serialization
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden
00009 //          
00010 // NOTE:    The GIZMO package defines a general purpose API for large model
00011 //          visualisation and advanced graphic behaviours. The package is similar
00012 //          to Cosmo3D, Inventor, Performer etc. but adds automated behaviour
00013 //          patterns to the graphics. 
00014 //
00015 //
00016 // Revision History...                          
00017 //                                  
00018 // Who  Date    Description                     
00019 //                                  
00020 // AMO  990919  Created file    
00021 //
00022 // ******************************************************************************
00023 #include "gzDebug.h"
00024 #include "gzExceptions.h"
00025 #include "gzSerialize.h"
00026 
00027 #include <iostream>
00028 
00029 
00030 class testSerializeData : public gzSerializeData
00031 {
00032 public:
00033 
00034     gzSerializeBinary<long>     longdata;
00035     gzSerializeBinary<float>    floatdata;
00036 
00037 
00038     gzVoid write(gzSerializeAdapter *adapter)
00039     {
00040         longdata.write(adapter);
00041         floatdata.write(adapter);
00042     }
00043 
00044     gzVoid read(gzSerializeAdapter *adapter)
00045     {
00046         longdata.read(adapter);
00047         floatdata.read(adapter);
00048     }
00049 
00050     gzVoid pushBack(gzSerializeAdapter *adapter)
00051     {
00052         floatdata.pushBack(adapter);
00053         longdata.pushBack(adapter);
00054     }
00055 
00056     gzULong getDataSize(gzSerializeAdapter *adapter=NULL) const
00057     {
00058         return longdata.getDataSize()+floatdata.getDataSize();
00059     }
00060 
00061 };
00062 
00063 
00064 int main(int argc , char *argv[] )
00065 {
00066     try     // To catch all Gizmo3D exceptions
00067     {
00068         gzMessage::setMessageLevel(GZ_MESSAGE_DEBUG);
00069 
00070         testSerializeData data1,data2;
00071 
00072         data1.floatdata=1.23f;
00073         data1.longdata=12345678;
00074 
00075         gzSerializeAdapter  *adapter=gzSerializeAdapter::getURLAdapter("test.dat",GZ_SERIALIZE_OUTPUT);
00076 
00077         data1.write(adapter);
00078         delete adapter;
00079 
00080         adapter=gzSerializeAdapter::getURLAdapter("test.dat",GZ_SERIALIZE_INPUT);
00081         data2.read(adapter);
00082         delete adapter;
00083 
00084         GZMESSAGE(GZ_MESSAGE_DEBUG,"Float data %.3lf",(float)data2.floatdata);
00085         GZMESSAGE(GZ_MESSAGE_DEBUG,"Long data %ld",(long)data2.longdata);
00086 
00087     }
00088     catch(gzBaseError &error)   // In case of exceptions thrown we want to print the message
00089     {
00090         error.reportError();
00091     }
00092 
00093     return 0;
00094 }

Documentation for GizmoBase generated at Wed Feb 20 11:57:53 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond