D:/Zythum/DinoKod/Common/Bank.h

00001 //---------------------------------------------------------------------------------------------
00002 //      This file is a part of "DinoKod".
00003 //      Copyright © 2003 Dino Productions. All Rights Reserved.
00004 //      
00005 //      File                    : Bank.h
00006 //      Author                  : Sebastien LEIX        sebastien.leix@wanadoo.fr
00007 //      Date                    : 07/09/2002
00008 //      Modification    :
00009 //
00010 //---------------------------------------------------------------------------------------------
00011 #ifndef __BANK_H__
00012 #define __BANK_H__
00013 
00014 #include "Common/CommonDll.h"
00015 #include "Common/Types.h"
00016 #include "Common/Table.h"
00017 #include "Common/Assert.h"
00018 
00019 //---------------------------------------------------------------------------------------------------------------------
00020 template <class TData, class THANDLE>
00021 class KBank
00022 {
00023 protected:
00024         KTable<TData*>          m_DataTable;
00025         u32                                     m_nMaxDatas;
00026         u32                                     m_nDatas;
00027 
00028 public:
00029         KBank()
00030         {
00031                 m_nMaxDatas     = 0;
00032                 m_nDatas        = 0;
00033         }
00034 
00035         virtual ~KBank()
00036         {
00037                 m_DataTable.Clear();
00038         }
00039 
00040         TData*                          GetpData( THANDLE Handle )
00041         {
00042                 if( Handle == KHANDLE_INVALID )
00043                         return NULL;
00044 
00045                 KASSERT( Handle >= 0 );
00046                 KASSERT( Handle < m_nMaxDatas );
00047 
00048                 return m_DataTable[Handle];
00049         }
00050 
00051         THANDLE                         AddData( TData* pData )
00052         {
00053                 KASSERT( pData );
00054 
00055                 // Recherche un emplacement libre dans la table
00056                 for( u32 i = 0; i < m_nMaxDatas; i ++ )
00057                 {
00058                         if( m_DataTable[i] == NULL )
00059                         {
00060                                 // Emplacement libre trouvé
00061                                 m_DataTable[i] = pData;
00062                                 m_nDatas ++;
00063                                 return (THANDLE)i;
00064                         }
00065                 }
00066 
00067                 // La table est pleine, on ajoute
00068                 THANDLE Handle;
00069                 Handle = m_DataTable.Add( pData );
00070                 m_nDatas ++;
00071                 m_nMaxDatas ++;
00072                 return (THANDLE)Handle;
00073         }
00074 
00075         void                            RemoveData( THANDLE Handle )
00076         {
00077                 if( GetpData( Handle ) )
00078                 {
00079                         m_DataTable[Handle] = NULL;
00080                         m_nDatas --;
00081                 }
00082         }
00083 
00084         THANDLE                         GethFirst()
00085         {
00086                 for( u32 i = 0; i < m_nMaxDatas; i ++ )
00087                         if( m_DataTable[i] )
00088                                 return (THANDLE)i;
00089                 return KHANDLE_INVALID;
00090         }
00091 
00092         THANDLE                         GethNext( THANDLE Handle )
00093         {
00094                 for( u32 i = (u32)Handle + 1; i < m_nMaxDatas; i ++ )
00095                         if( m_DataTable[i] )
00096                                 return (THANDLE)i;
00097                 return KHANDLE_INVALID;
00098         }
00099 
00100         u32                                     GetnDatas()             { return m_nDatas;              }
00101 };
00102 
00103 #endif //       __BANK_H__

Generated on Sun Mar 25 20:02:10 2007 for Zythum Project by  doxygen 1.5.1-p1