Two Dimensional TInt Array in Symbian(二维数组)

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"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值