Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

XFuSerializable.h

Go to the documentation of this file.
00001 /*!
00002  * \file
00003  * X-Forge Engine <br>
00004  * Copyright 2000-2003 Fathammer Ltd
00005  *
00006  * \brief Base class for classes that need to be able to serialize and deserialize.
00007  *
00008  * $Id: XFuSerializable.h,v 1.1 2003/07/23 10:20:39 lars Exp $
00009  * $Date: 2003/07/23 10:20:39 $
00010  * $Revision: 1.1 $
00011  */
00012 
00013 #ifndef XFUSERIALIZABLE_H_INCLUDED
00014 #define XFUSERIALIZABLE_H_INCLUDED
00015 
00016 
00017 //! Base class for classes that need to be able to serialize and deserialize.
00018 class XFuSerializable
00019 {
00020 
00021 public:
00022 
00023     //! Virtual destructor
00024     virtual ~XFuSerializable() {}
00025 
00026     //! Serializes this object into the buffer. Returns the length of the data.
00027     virtual INT32 serialize(CHAR8 *aBuffer, INT32 aMaxSize) = 0;
00028 
00029     //! Deserializes from the data buffer into this object. Returns length of handled data.
00030     virtual INT32 deserialize(const CHAR8 *aBuffer, INT32 aLen) = 0;
00031 
00032 protected:
00033 
00034     // For reading data from a buffer:
00035 
00036     void readCHAR8(const CHAR8 *aBuffer, CHAR8 *aVal) { memcpy(aVal, aBuffer, sizeof(CHAR8)); }
00037     void readCHAR16(const CHAR8 *aBuffer, CHAR16 *aVal) { memcpy(aVal, aBuffer, sizeof(CHAR16)); }
00038 
00039     void readINT(const CHAR8 *aBuffer, INT *aVal) { readINT32(aBuffer, aVal); }
00040 
00041     void readINT8(const CHAR8 *aBuffer, INT8 *aVal) { memcpy(aVal, aBuffer, sizeof(INT8)); }
00042     void readUINT8(const CHAR8 *aBuffer, UINT8 *aVal) { memcpy(aVal, aBuffer, sizeof(UINT8)); }
00043 
00044     void readINT16(const CHAR8 *aBuffer, INT16 *aVal) { memcpy(aVal, aBuffer, sizeof(INT16)); }
00045     void readUINT16(const CHAR8 *aBuffer, UINT16 *aVal) { memcpy(aVal, aBuffer, sizeof(UINT16)); }
00046 
00047     void readINT32(const CHAR8 *aBuffer, INT32 *aVal) { memcpy(aVal, aBuffer, sizeof(INT32)); }
00048     void readUINT32(const CHAR8 *aBuffer, UINT32 *aVal) { memcpy(aVal, aBuffer, sizeof(UINT32)); }
00049 
00050     void readREAL(const CHAR8 *aBuffer, REAL *aVal) { memcpy(aVal, aBuffer, sizeof(REAL)); }
00051 
00052     void readFLOAT32(const CHAR8 *aBuffer, FLOAT32 *aVal) { memcpy(aVal, aBuffer, sizeof(FLOAT32)); }
00053 
00054     // For writing data to a buffer:
00055 
00056     void writeCHAR8(CHAR8 *aBuffer, CHAR8 aVal) { memcpy(aBuffer, &aVal, sizeof(CHAR8)); }
00057     void writeCHAR16(CHAR8 *aBuffer, CHAR16 aVal) { memcpy(aBuffer, &aVal, sizeof(CHAR16)); }
00058 
00059     void writeINT(CHAR8 *aBuffer, INT aVal) { writeINT32(aBuffer, aVal); }
00060 
00061     void writeINT8(CHAR8 *aBuffer, INT8 aVal) { memcpy(aBuffer, &aVal, sizeof(INT8)); }
00062     void writeUINT8(CHAR8 *aBuffer, UINT8 aVal) { memcpy(aBuffer, &aVal, sizeof(UINT8)); }
00063 
00064     void writeINT16(CHAR8 *aBuffer, INT16 aVal) { memcpy(aBuffer, &aVal, sizeof(INT16)); }
00065     void writeUINT16(CHAR8 *aBuffer, UINT16 aVal) { memcpy(aBuffer, &aVal, sizeof(UINT16)); }
00066 
00067     void writeINT32(CHAR8 *aBuffer, INT32 aVal) { memcpy(aBuffer, &aVal, sizeof(INT32)); }
00068     void writeUINT32(CHAR8 *aBuffer, UINT32 aVal) { memcpy(aBuffer, &aVal, sizeof(UINT32)); }
00069 
00070     void writeREAL(CHAR8 *aBuffer, REAL aVal) { memcpy(aBuffer, &aVal, sizeof(REAL)); }
00071 
00072     void writeFLOAT32(CHAR8 *aBuffer, FLOAT32 aVal) { memcpy(aBuffer, &aVal, sizeof(FLOAT32)); }
00073 
00074 };
00075 
00076 
00077 #endif // !XFUSERIALIZABLE_H_INCLUDED

   
X-Forge Documentation
Confidential
Copyright © 2002-2003 Fathammer
   
Documentation generated
with doxygen
by Dimitri van Heesch