|
1 /* |
|
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * e32tools\petran\Szip\farray.h |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __FARRAY_H__ |
|
21 #define __FARRAY_H__ |
|
22 #include <assert.h> |
|
23 |
|
24 template <class T,TInt S> |
|
25 class TFixedArray |
|
26 // Range checking wrapper+ class for C++ arrays |
|
27 // Can be embedded in C-objects, or used on the stack: use Reset() to zero it |
|
28 { |
|
29 typedef TFixedArray<T,S> ThisClass; |
|
30 public: |
|
31 inline TFixedArray(); |
|
32 inline TFixedArray(const T* aList, TInt aLength); |
|
33 // |
|
34 inline void Copy(const T* aList, TInt aLength); |
|
35 inline void Reset(); // zero fill |
|
36 inline void DeleteAll(); |
|
37 // |
|
38 inline TInt Count() const; |
|
39 inline TInt Length() const; |
|
40 // Accessors - debug range checking |
|
41 inline T& operator[](TInt aIndex); |
|
42 inline const T& operator[] (TInt aIndex) const; |
|
43 // Accessors - always range checking |
|
44 inline T& At(TInt aIndex); |
|
45 inline const T& At(TInt aIndex) const; |
|
46 // Provides pointers to the beginning and end of the array |
|
47 inline T* Begin(); |
|
48 inline T* End(); |
|
49 inline const T* Begin() const; |
|
50 inline const T* End() const; |
|
51 // |
|
52 protected: |
|
53 inline static TBool InRange(TInt aIndex); |
|
54 protected: |
|
55 T iRep[S]; |
|
56 }; |
|
57 |
|
58 // Template class TFixedArray |
|
59 IMPORT_C void PanicTFixedArray(); |
|
60 |
|
61 template <class T,TInt S> |
|
62 inline TFixedArray<T,S>::TFixedArray() |
|
63 {} |
|
64 template <class T,TInt S> |
|
65 inline void TFixedArray<T,S>::Copy(const T* aList,TInt aLength) |
|
66 {assert(TUint(aLength)<=TUint(S));HMem::Copy(iRep,aList,aLength*sizeof(T));} |
|
67 template <class T,TInt S> |
|
68 inline TFixedArray<T,S>::TFixedArray(const T* aList,TInt aLength) |
|
69 {Copy(aList,aLength);} |
|
70 template <class T,TInt S> |
|
71 inline void TFixedArray<T,S>::Reset() |
|
72 {HMem::FillZ(iRep,sizeof(iRep));} |
|
73 template <class T,TInt S> |
|
74 inline TInt TFixedArray<T,S>::Count() const |
|
75 {return S;} |
|
76 template <class T,TInt S> |
|
77 inline TInt TFixedArray<T,S>::Length() const |
|
78 {return sizeof(T);} |
|
79 template <class T,TInt S> |
|
80 inline TBool TFixedArray<T,S>::InRange(TInt aIndex) |
|
81 {return TUint(aIndex)<S;} |
|
82 template <class T,TInt S> |
|
83 inline T& TFixedArray<T,S>::operator[](TInt aIndex) |
|
84 {assert(InRange(aIndex));return iRep[aIndex];} |
|
85 template <class T,TInt S> |
|
86 inline const T& TFixedArray<T,S>::operator[](TInt aIndex) const |
|
87 {return const_cast<ThisClass&>(*this)[aIndex];} |
|
88 template <class T,TInt S> |
|
89 inline T& TFixedArray<T,S>::At(TInt aIndex) |
|
90 {verify(InRange(aIndex));return iRep[aIndex];} |
|
91 template <class T,TInt S> |
|
92 inline const T& TFixedArray<T,S>::At(TInt aIndex) const |
|
93 {return const_cast<ThisClass&>(*this).At(aIndex);} |
|
94 template <class T,TInt S> |
|
95 inline T* TFixedArray<T,S>::Begin() |
|
96 {return &iRep[0];} |
|
97 template <class T,TInt S> |
|
98 inline T* TFixedArray<T,S>::End() |
|
99 {return &iRep[S];} |
|
100 template <class T,TInt S> |
|
101 inline const T* TFixedArray<T,S>::Begin() const |
|
102 {return &iRep[0];} |
|
103 template <class T,TInt S> |
|
104 inline const T* TFixedArray<T,S>::End() const |
|
105 {return &iRep[S];} |
|
106 #endif |