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]
Retrieved from "http://wiki.forum.nokia.com/index.php/Two_Dimensional_TInt_Array_in_Symbian"
Symbian二维整型数组
本文介绍了一种在Symbian系统中实现二维整型数组的方法,包括类定义、构造函数、析构函数及成员函数等关键部分,并通过实例展示了如何使用该类创建和操作二维数组。
5027

被折叠的 条评论
为什么被折叠?



