Go to the documentation of this file.00001
00002
00003 #ifndef _SERIALIZER_H_
00004 #define _SERIALIZER_H_
00005
00006 #include <EngineConfig.h>
00007 #include <core/Types.h>
00008
00009 #include <string>
00010
00011 namespace core
00012 {
00013 class vector3d;
00014 class quaternion;
00015 }
00016
00017 namespace render
00018 {
00019 class Color;
00020 }
00021
00022 namespace platform
00023 {
00024 class File;
00025 }
00026
00027 namespace resource
00028 {
00029
00030 class DataStream;
00031 class Resource;
00032 enum ResourceType;
00033
00035 const u32 CHUNK_OVERHEAD_SIZE = sizeof(u16) + sizeof(u32);
00036 const u16 HEADER_CHUNK_ID = 0x1000;
00037
00042 class ENGINE_PUBLIC_EXPORT Serializer
00043 {
00044 public:
00045
00046 Serializer();
00047 virtual ~Serializer();
00048
00050 virtual bool importResource(DataStream* stream, Resource* dest);
00051
00053 virtual bool exportResource(Resource* source, const std::string& filename);
00054
00055 protected:
00056
00057 ResourceType mResourceType;
00058
00059 u32 mCurrentChunkLen;
00060 platform::File* mFile;
00061 std::string mVersion;
00062
00063
00064 virtual void writeFileHeader();
00065 virtual void writeChunkHeader(u16 id, u32 size);
00066
00067 void writebools(const bool* src, u32 count);
00068 void writeShorts(const u16* src, u32 count);
00069 void writeLongs(const u32* src, u32 count);
00070 void writeFloats(const f32* src, u32 count);
00071 void writeObject(const core::vector3d& vec);
00072 void writeObject(const core::quaternion& q);
00073
00074 void writeString(const std::string& string);
00075 void writeData(const void* buf, u32 size, u32 count);
00076
00077 virtual void readFileHeader(DataStream* stream);
00078 virtual u16 readChunk(DataStream* stream);
00079
00080 void readBools(DataStream* stream, bool* dest, u32 count);
00081 void readShorts(DataStream* stream, u16* dest, u32 count);
00082 void readLongs(DataStream* stream, u32* dest, u32 count);
00083 void readFloats(DataStream* stream, f32* dest, u32 count);
00084 void readObject(DataStream* stream, core::vector3d* dest);
00085 void readObject(DataStream* stream, core::quaternion* dest);
00086
00087 std::string readString(DataStream* stream);
00088 };
00089
00090 inline core::vector3d ENGINE_PUBLIC_EXPORT parseVector3d(std::string& params);
00091 inline core::quaternion ENGINE_PUBLIC_EXPORT parseQuaternion(std::string& params);
00092 inline render::Color ENGINE_PUBLIC_EXPORT parseColor(std::string& params);
00093
00094 }
00095
00096 #endif