The implementation below shows the creation to two dimensional integer array in symbian. The diagrammatic structure of implementation is given below for clear explanation.
#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
// 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);
}
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
}
( j ) -> ( 0 )( 1 )
[ 0 ] -> [ 0 ][20]
[ 1 ] -> [ 1 ][25]
[ 2 ] -> [ 2 ][35]
[ 3 ] -> [ 3 ][45]
( 0 )( 1 )
[ 0 ][20]
[ 1 ][25]
[ 2 ][35]
[ 3 ][45]
No related wiki articles found