HoverRace  2.0
FastArray.h
Go to the documentation of this file.
1 
2 // FastArray.h
3 //
4 // Copyright (c) 1995-1998 - Richard Langlois and Grokksoft Inc.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 //
22 
23 #pragma once
24 
25 #include "MR_Types.h"
26 
27 template <class pType>
28 class MR_FastArrayBase
29 {
30 protected:
31  int mNbItem;
33  pType *mArray;
34 
35 public:
36  MR_FastArrayBase(int pSize, pType *pData) :
37  mNbItem(0), mArraySize(pSize), mArray(pData) { }
38 
39  void Add(pType pData)
40  {
41  ASSERT(mNbItem < mArraySize);
42  mArray[mNbItem++] = pData;
43  };
44 
45  void Use(int pCount = 1)
46  {
47  mNbItem += pCount;
48  ASSERT(mNbItem <= mArraySize);
49  };
50 
51  void Clean()
52  {
53  mNbItem = 0;
54  }
55 
56  int Used() const
57  {
58  return mNbItem;
59  }
60 
61  int TotalSize() const
62  {
63  return mArraySize;
64  }
65 
66  int Full() const
67  {
68  return mNbItem == mArraySize;
69  }
70 
71  BOOL CanAdd(int pCount = 1)
72  {
73  return mNbItem + pCount <= mArraySize;
74  }
75 
76  BOOL Contains(pType pData) const
77  {
78  for(int lCounter = 0; lCounter < mNbItem; lCounter++) {
79  if(mArray[lCounter] == pData)
80  return TRUE;
81  } return FALSE;
82  };
83 
84  const pType operator[] (int pIndex) const
85  {
86  return mArray[pIndex];
87  }
88 
89  const pType & operator[] (int pIndex)
90  {
91  return mArray[pIndex];
92  }
93 };
94 
95 template <class pType, int pSize>
96 class MR_FixedFastArray : public MR_FastArrayBase<pType>
97 {
99 
100 protected:
101  pType mData[pSize];
102 
103 public:
104  MR_FixedFastArray() : SUPER(pSize, mData) { };
105 };
int mArraySize
Definition: FastArray.h:32
void Use(int pCount=1)
Definition: FastArray.h:45
BOOL Contains(pType pData) const
Definition: FastArray.h:76
void Add(pType pData)
Definition: FastArray.h:39
void Clean()
Definition: FastArray.h:51
int Full() const
Definition: FastArray.h:66
Definition: FastArray.h:96
int TotalSize() const
Definition: FastArray.h:61
Definition: GameSession.h:49
MR_FixedFastArray()
Definition: FastArray.h:104
const pType operator[](int pIndex) const
Definition: FastArray.h:84
int Used() const
Definition: FastArray.h:56
pType * mArray
Definition: FastArray.h:33
MR_FastArrayBase(int pSize, pType *pData)
Definition: FastArray.h:36
int mNbItem
Definition: FastArray.h:31
BOOL CanAdd(int pCount=1)
Definition: FastArray.h:71