toolsandutils/e32tools/elf2e32/source/farray.h
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 // Copyright (c) 2004-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 // @internalComponent
       
    15 // @released
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 #ifndef __FARRAY_H__
       
    21 #define __FARRAY_H__
       
    22 #include <cassert>
       
    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 
       
    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 	{
       
    65 	// Never used. 
       
    66     assert(TUint(aLength)<=TUint(S));
       
    67     // HMdem::Copy(iRep,aList,aLength*sizeof(T));
       
    68     }
       
    69 template <class T,TInt S>
       
    70 inline TFixedArray<T,S>::TFixedArray(const T* aList,TInt aLength)
       
    71 	{Copy(aList,aLength);}
       
    72 template <class T,TInt S>
       
    73 inline void TFixedArray<T,S>::Reset()
       
    74 	{memset(iRep,0,sizeof(iRep));}
       
    75 template <class T,TInt S>
       
    76 inline TInt TFixedArray<T,S>::Count() const
       
    77 	{return S;}
       
    78 template <class T,TInt S>
       
    79 inline TInt TFixedArray<T,S>::Length() const
       
    80 	{return sizeof(T);}
       
    81 template <class T,TInt S>
       
    82 inline TBool TFixedArray<T,S>::InRange(TInt aIndex)
       
    83 	{return TUint(aIndex)<S;}
       
    84 template <class T,TInt S>
       
    85 inline T& TFixedArray<T,S>::operator[](TInt aIndex)
       
    86 	{assert(InRange(aIndex));return iRep[aIndex];}
       
    87 template <class T,TInt S>
       
    88 inline const T& TFixedArray<T,S>::operator[](TInt aIndex) const
       
    89 	{return const_cast<ThisClass&>(*this)[aIndex];}
       
    90 template <class T,TInt S>
       
    91 inline T& TFixedArray<T,S>::At(TInt aIndex)
       
    92 	{verify(InRange(aIndex));return iRep[aIndex];}
       
    93 template <class T,TInt S>
       
    94 inline const T& TFixedArray<T,S>::At(TInt aIndex) const
       
    95 	{return const_cast<ThisClass&>(*this).At(aIndex);}
       
    96 template <class T,TInt S>
       
    97 inline T* TFixedArray<T,S>::Begin()
       
    98 	{return &iRep[0];}
       
    99 template <class T,TInt S>
       
   100 inline T* TFixedArray<T,S>::End()
       
   101 	{return &iRep[S];}
       
   102 template <class T,TInt S>
       
   103 inline const T* TFixedArray<T,S>::Begin() const
       
   104 	{return &iRep[0];}
       
   105 template <class T,TInt S>
       
   106 inline const T* TFixedArray<T,S>::End() const
       
   107 	{return &iRep[S];}
       
   108 
       
   109 
       
   110 #endif
       
   111