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