crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianNativeTools/Include/farray.h
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 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 "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 *
       
    16 */
       
    17 
       
    18 #ifndef __FARRAY_H__
       
    19 #define __FARRAY_H__
       
    20 #include <assert.h>
       
    21 #include "h_utl.h"
       
    22 
       
    23 template <class T,TInt S> 
       
    24 class TFixedArray
       
    25 // Range checking wrapper+ class for C++ arrays
       
    26 // Can be embedded in C-objects, or used on the stack: use Reset() to zero it
       
    27 	{
       
    28 	typedef TFixedArray<T,S> ThisClass;
       
    29 public:
       
    30 	inline TFixedArray();
       
    31 	inline TFixedArray(const T* aList, TInt aLength);
       
    32 	//
       
    33 	inline void Copy(const T* aList, TInt aLength);
       
    34 	inline void Reset();		// zero fill
       
    35 	inline void DeleteAll();
       
    36 	//
       
    37 	inline TInt Count() const;
       
    38 	inline TInt Length() const;
       
    39 	// Accessors - debug range checking
       
    40 	inline T& operator[](TInt aIndex);
       
    41 	inline const T& operator[] (TInt aIndex) const;
       
    42 	// Accessors - always range checking
       
    43 	inline T& At(TInt aIndex);
       
    44 	inline const T& At(TInt aIndex) const;
       
    45 	// Provides pointers to the beginning and end of the array
       
    46 	inline T* Begin();
       
    47 	inline T* End();
       
    48 	inline const T* Begin() const;
       
    49 	inline const T* End() const;
       
    50 	//
       
    51 protected:
       
    52 	inline static TBool InRange(TInt aIndex);
       
    53 protected:
       
    54 	T iRep[S];
       
    55 	};
       
    56 
       
    57 
       
    58 template <class T,TInt S>
       
    59 inline TFixedArray<T,S>::TFixedArray()
       
    60 	{}
       
    61 template <class T,TInt S>
       
    62 inline void TFixedArray<T,S>::Copy(const T* aList,TInt aLength)
       
    63 	{assert(TUint(aLength)<=TUint(S));HMem::Copy(iRep,aList,aLength*sizeof(T));}
       
    64 template <class T,TInt S>
       
    65 inline TFixedArray<T,S>::TFixedArray(const T* aList,TInt aLength)
       
    66 	{Copy(aList,aLength);}
       
    67 template <class T,TInt S>
       
    68 inline void TFixedArray<T,S>::Reset()
       
    69 	{HMem::FillZ(iRep,sizeof(iRep));}
       
    70 template <class T,TInt S>
       
    71 inline TInt TFixedArray<T,S>::Count() const
       
    72 	{return S;}
       
    73 template <class T,TInt S>
       
    74 inline TInt TFixedArray<T,S>::Length() const
       
    75 	{return sizeof(T);}
       
    76 template <class T,TInt S>
       
    77 inline TBool TFixedArray<T,S>::InRange(TInt aIndex)
       
    78 	{return TUint(aIndex)<S;}
       
    79 template <class T,TInt S>
       
    80 inline T& TFixedArray<T,S>::operator[](TInt aIndex)
       
    81 	{assert(InRange(aIndex));return iRep[aIndex];}
       
    82 template <class T,TInt S>
       
    83 inline const T& TFixedArray<T,S>::operator[](TInt aIndex) const
       
    84 	{return const_cast<ThisClass&>(*this)[aIndex];}
       
    85 template <class T,TInt S>
       
    86 inline T& TFixedArray<T,S>::At(TInt aIndex)
       
    87 	{verify(InRange(aIndex));return iRep[aIndex];}
       
    88 template <class T,TInt S>
       
    89 inline const T& TFixedArray<T,S>::At(TInt aIndex) const
       
    90 	{return const_cast<ThisClass&>(*this).At(aIndex);}
       
    91 template <class T,TInt S>
       
    92 inline T* TFixedArray<T,S>::Begin()
       
    93 	{return &iRep[0];}
       
    94 template <class T,TInt S>
       
    95 inline T* TFixedArray<T,S>::End()
       
    96 	{return &iRep[S];}
       
    97 template <class T,TInt S>
       
    98 inline const T* TFixedArray<T,S>::Begin() const
       
    99 	{return &iRep[0];}
       
   100 template <class T,TInt S>
       
   101 inline const T* TFixedArray<T,S>::End() const
       
   102 	{return &iRep[S];}
       
   103 #endif