📄 utils.cpp
字号:
/*
======================================================================
Name : utils.cpp
Description : Testing basic data types
Created: 22-Feb-2008
Last Modified: 23-Feb-2008
======================================================================
*/
#include <e32cons.h> // Console
#include <coemain.h>
#include "utils.h"
/*--------------------------+
| Two phases construtors |
+--------------------------*/
CUtils* CUtils::newLC(CConsoleBase & aConsole){
CUtils* self = new (ELeave)CUtils;
CleanupStack::PushL(self);
// Call the 2nd phase constructor
self->ConstructL(aConsole);
// Trailing C: newLC => Indicates that the object is left on the cleanup stack
return (self);
} // eof newLC
CUtils* CUtils::newL(CConsoleBase & aConsole){
CUtils* self = CUtils::newLC(aConsole);
CleanupStack::Pop(self);
return self;
} // eof newL
void CUtils::ConstructL(CConsoleBase & aConsole){
output = &aConsole;
} // ConstructL
CUtils::CUtils(){
// No implementation required
}
CUtils::~CUtils(){
// No implementation required
}
/*---------------------+
| testArrayL |+---------------------*/
void CUtils::testArrayL(){
// output->Printf(_L("Testing utilities object...\n"));
// TRAP/ TRAPD cannot catch panic (access violation in Win32)
// _LIT(KText, "Number->");
// TBuf<5> myText(KText); // => Panic
// 1) Test fixed array. The TInt object list will be created on Stack. See e32std.h::TFixedArray
// declaration for more details.
TFixedArray<TInt, 5> fixedArr;
fixedArr[0] = 1000;
fixedArr[1] = 1001;
fixedArr[3] = 1002;
fixedArr[4] = 1003;
// Dynamic arrays: RArrayX/ CArrayX => Flat/ segmented arrays & pointer/ direct arrays
// CDesCArrayX/ CPtrCArray => Descriptor array
// TSglQue => Single Link list
// TDblQue => Double Link list
// CCirBuf => Circular array
// TBTree/ TBTreeFix => Balanced trees
// No STL => Large footprint for a mobile devices
// 2) Test RArray
// Create an array which can store TAccount-objs.
// RArray<TAccount>accounts(4); // 4 - Granuality number
RArray<TAccount> accounts(4, _FOFF(TAccount, iAccountNumber));
// Make sure cleanup of the array抯 heap memory// is done in case of a leave!
// Constructs and push a TCleanupItem object into the cleanup stack
CleanupClosePushL(accounts); // This requires that destroying stack will be calling Close() method of the object
TAccount a1(_L("Mopius"),16, 58354);
TAccount a2(_L("Ana"),14, 8731);
// Add
accounts.AppendL(a1);
accounts.AppendL(a2);
// Do some stuff with the array
output->Printf(_L("Elm count: RArray=%d, TFixedArray=%d\n"),
accounts.Count(), fixedArr.Count());
// Sizeof accounts = 32 bytes = 4 * 8 bytes
printRArray(accounts);
// 2.1) Current order: elm0(16, 58354), elm1(14, 8731)
// Sort by account number as integer
accounts.SortSigned();
printRArrayPtr(&accounts);
// 2.2) Inserting in order
accounts.InsertInSignedKeyOrderL(TAccount(_L("Tony"),15, 16923));
printRArrayPtr(&accounts);
// 3) Sorting by using a customized function
TLinearOrder<TAccount> order(CompareName);
// Sort the array using the comparison function
accounts.Sort(order);
// Array is now sorted alphabetically by owner name
printRArrayPtr(&accounts);
// Insert in order
// accounts.InsertInOrderL(newEntry, order);
// 4) Compares RArray, CArray*
/***
CArray Disadvantages:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -