00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef TA_BUFFERITERATOR_H
00013 #define TA_BUFFERITERATOR_H
00014
00015 #ifndef TA_TYPES_H
00016 #include "Types.h"
00017 #endif // TA_TYPES_H
00018
00019 #ifndef TA_COMMON_H
00020 #include "Common.h"
00021 #endif // TA_COMMON_H
00022
00023 namespace TA
00024 {
00025
00026 class BufferIterator
00027 {
00028 public:
00029 BufferIterator()
00030 {
00031 m_pBufferPtr = 0;
00032 m_pBufferEnd = 0;
00033 }
00034 ~BufferIterator() { Finalise(); }
00035
00036 void Initialise(void *pBuffer, int nSize)
00037 {
00038 TA_ASSERT(nSize >= 0);
00039 m_pBufferPtr = (u8*)pBuffer;
00040 m_pBufferEnd = m_pBufferPtr + nSize;
00041 }
00042 void Finalise() {}
00043
00044 template <class Type> void Add(const Type& type)
00045 {
00046 TA_ASSERT((u32)m_pBufferPtr + sizeof (type) <= (u32)m_pBufferEnd);
00047 *(Type*)m_pBufferPtr = type;
00048 ((Type*&)m_pBufferPtr)++;
00049 }
00050 int GetInt() { return *((int*&)m_pBufferPtr)++; }
00051 int GetIntAt(int nIndex)
00052 {
00053 TA_ASSERT((u8*)&((int*)m_pBufferPtr)[nIndex] < m_pBufferEnd);
00054 return ((int*)m_pBufferPtr)[nIndex];
00055 }
00056 void IncrementBy(int nAmount)
00057 {
00058 m_pBufferPtr += nAmount;
00059 TA_ASSERT(m_pBufferPtr <= m_pBufferEnd);
00060 }
00061
00062 void* GetPointer() { return m_pBufferPtr; }
00063
00064 bool AtEnd() { return (m_pBufferPtr >= m_pBufferEnd); }
00065
00066 private:
00067 u8* m_pBufferPtr;
00068 u8* m_pBufferEnd;
00069 };
00070
00071 };
00072
00073 #endif // TA_BUFFERITERATOR_H
© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.