This page was last modified 13:39, 31 December 2007.
Two Dimensional TInt Array in Symbian
From Forum Nokia Wiki
The implementation below shows the creation to two dimensional integer array in symbian. The diagrammatic structure of implementation is given below for clear explanation.
Header File
#ifndef __TWODIMENSIONAL_H__ #define __TWODIMENSIONAL_H__ #include <e32std.h> typedef RArray<TInt> RIntegerArray; class R2DIntArray: public RPointerArray <RIntegerArray> { public: ~R2DIntArray(); void ResetAndDestroy(); inline TInt& At(TInt a1, TInt a2) { return (*((*this)[a1]))[a2]; } TInt Find(TInt aInteger); void Add(TInt aInteger); void AppendLast(TInt aPosition, TInt aValue); }; #endif
Functions Implementation
// destructor R2DIntArray::~R2DIntArray() { ResetAndDestroy(); }; void R2DIntArray::ResetAndDestroy() { for (TInt i=0; i<Count(); i++) { (*this)[i]->Reset(); } RPointerArray<RIntegerArray>::ResetAndDestroy(); }; // Finding the particular integer value TInt R2DIntArray::Find(TInt aInteger) { for (TInt i=0; i<Count(); i++) if (aInteger == (*((*this)[i]))[0]) return i; return KErrNotFound; } // adding the entry void R2DIntArray::Add(TInt aInteger) { Append(new RIntegerArray); (*this)[Count() - 1]->Append(aInteger); } // Appending the entry void R2DIntArray::AppendLast(TInt aPosition, TInt aValue) { (*this)[aPosition]->Append(aValue); }
Two Dimensional Array Usage
R2DIntArray 2DArray; 2DArray.Reset(); 2DArray.At(j,0) 2DArray.At(j,1) 2DArray.Count() TInt j= 0 ; // value less than count of array. TInt word = 25 // Any integer value. RPointerArray<R2DIntArray> 2DPtrArray; 2DPtrArray.Append(new R2DIntArray); 2DPtrArray[0]->At(j,1); // refer to diagram above for clear understanting TInt retWord = 2DPtrArray[0]->Find(word); if(retWord != KErrNotFound) { // you got the index of the searched word }
- RPointerArray<R2DIntArray> 2DPtrArray
( j ) -> ( 0 )( 1 )
[ 0 ] -> [ 0 ][20]
[ 1 ] -> [ 1 ][25]
[ 2 ] -> [ 2 ][35]
[ 3 ] -> [ 3 ][45]
- R2DIntArray 2DArray
( 0 )( 1 )
[ 0 ][20]
[ 1 ][25]
[ 2 ][35]
[ 3 ][45]
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do i stream an array? | advocatee | General Symbian C++ | 0 | 2003-08-27 18:28 |
| retrieve values from RArray | remyag | General Symbian C++ | 5 | 2008-07-11 11:25 |
| Can someone check my multi select list code? | advocatee | Symbian User Interface | 14 | 2003-08-18 14:15 |
| (* )[] operator | white.coder | General Symbian C++ | 7 | 2007-08-16 12:54 |
| Using Icons | GENERAL_INFO | Symbian User Interface | 1 | 2001-12-05 17:53 |
