True Axis Physics SDK 1.2.0.1 Beta Documentation
www.trueaxis.com

Array.h

00001 //---------------------------------------------------------------------------------
00002 // File Name: Array.h
00003 // Description: Don't make pointers to the items in this array because
00004 //              there place in memory may change.
00005 //
00006 // Copyright (C) 2004 - 2006 True Axis Pty Ltd, Australia. 
00007 // All Rights Reserved.
00008 //
00009 // History:
00010 //      Created File.
00011 //---------------------------------------------------------------------------------
00012 
00013 #ifndef TA_ARRAY_H
00014 #define TA_ARRAY_H
00015 
00016 #ifndef TA_COMMON_H
00017 #include "Common.h"
00018 #endif // TA_COMMON_H
00019 
00020 namespace TA
00021 {
00022 
00023 template <class Type, bool bDynamic = true>
00024 class TACOMMON_CLASS Array
00025 {
00026 public:
00027     class Iterator
00028     {
00029     public:
00030         Iterator() { m_pCurrentPtr = 0; m_nCountLeft = 0; }
00031         ~Iterator() { Finalise(); }
00032         void operator ++() 
00033         {
00034             if (m_nCountLeft > 0)
00035             {
00036                 m_pCurrentPtr++;
00037                 m_nCountLeft--;
00038             }
00039         }
00040         Type& operator *() { return *m_pCurrentPtr; }
00041         bool AtEnd() { return m_nCountLeft <= 0; }
00042     private:
00043         friend class Array<Type, bDynamic>;
00044         void Initialise(Type* pCurrentPtr, int nSize) { m_pCurrentPtr = pCurrentPtr; m_nCountLeft = nSize; }
00045         void Finalise() { m_pCurrentPtr = 0; m_nCountLeft = 0; }
00046         Type* m_pCurrentPtr;
00047         int m_nCountLeft;
00048     };
00049     Array();
00050     ~Array();
00051 
00052     void Initialise(int nInitialSize, int nInitialMaxSize, int nBlockSize = -1);
00053     void Finalise();
00054     void Clear();
00055     void ZeroData();
00056 
00057     Type& operator [] (int nIndex);
00058     const Type& operator [] (int nIndex) const;
00059 
00060     int GetSize() const;
00061     int GetMaxSize() const;
00062     Type& Append();
00063     void Append(const Type& type);
00064     void IncrementSize(int nAmount);
00065     void Remove(int nIndex);
00066     Type& Insert(int nIndex);
00067     void ReallocateIfNecessary(int nNewMaxSize);
00068     int GetElementSize();
00069     Iterator GetIterator();
00070     void MinimiseMemoryUsage();
00071     bool ContainsPointer(Type* pPointer);
00072 
00073 private:
00074     int m_nSize;
00075     int m_nMaxSize;
00076     int m_nBlockSize;
00077     Type* m_pArray;
00078 };
00079 
00080 }
00081 
00082 #include "Array.inl"
00083 
00084 #endif // TA_ARRAY_H


© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.