00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef TA_SERIALISER_H
00013 #define TA_SERIALISER_H
00014
00015 #ifndef TA_TYPES_H
00016 #include "Types.h"
00017 #endif // TA_TYPES_H
00018
00019 #ifndef TA_STRING_H
00020 #include "String.h"
00021 #endif // TA_STRING_H
00022
00023 #ifndef TA_DEBUG_H
00024 #include "Debug.h"
00025 #endif // TA_DEBUG_H
00026
00027 #ifndef TA_IOSTREAM_H
00028 #include "IOStream.h"
00029 #endif // TA_IOSTREAM_H
00030
00031 namespace TA
00032 {
00033
00034
00035 #define SERIALISER_PROFILE_BEGIN(name)
00036 #define SERIALISER_PROFILE_END(name)
00037
00038 class TACOMMON_CLASS Serialiser
00039 {
00040 public:
00041 Serialiser() { m_pStream = 0; }
00042 Serialiser(IOStream& ioStream) { m_pStream = 0; Initialise(ioStream); }
00043 ~Serialiser() { Finalise(); }
00044
00045 void Initialise(IOStream& ioStream) { TA_ASSERT(m_pStream == 0); m_pStream = &ioStream; }
00046 void Finalise() { m_pStream = 0; }
00047
00048 template <class Type> void Serialise(Type& type) { TA_ASSERT(m_pStream); m_pStream->StreamData(&type, sizeof(Type)); }
00049 void SerialiseData(void* pData, int nSize) { TA_ASSERT(m_pStream); m_pStream->StreamData(pData, nSize); }
00050 template <class Type>
00051 void SerialiseArrayData(Type& array)
00052 {
00053 int nSize = array.GetSize();
00054 Serialise(nSize);
00055 if (IsInput())
00056 array.Initialise(nSize, nSize);
00057 SerialiseData(&array[0], nSize * array.GetElementSize());
00058 }
00059 template <class Type>
00060 void SerialiseArray(Type& array)
00061 {
00062 int nSize = array.GetSize();
00063 Serialise(nSize);
00064 if (IsInput())
00065 array.Initialise(nSize, nSize);
00066 for (int i = 0; i < nSize; i++)
00067 array[i].Serialise(*this);
00068 }
00069 template <class Type>
00070 void SerialiseList(Type& list)
00071 {
00072 int nSize = list.GetSize();
00073 Serialise(nSize);
00074 if (IsOutput())
00075 {
00076 class Type::Iterator it;
00077 it = list.GetIterator();
00078 for (; !it.AtEnd(); ++it)
00079 (*it).Serialise(*this);
00080 }
00081 else
00082 {
00083 for (int i = 0; i < nSize; i++)
00084 list.Append().Serialise(*this);
00085 }
00086 }
00087
00088 bool IsInput() { TA_ASSERT(m_pStream); return m_pStream->IsInput(); }
00089 bool IsOutput() { TA_ASSERT(m_pStream); return m_pStream->IsOutput(); }
00090
00091 private:
00092 IOStream* m_pStream;
00093 };
00094
00095 };
00096
00097 #endif // TA_SERIALISER_H
00098
00099
© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.