⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basictypes.cpp

📁 Symbian console application
💻 CPP
字号:
/*
 ============================================================================
 Name		: basictypes.cpp
 Author	  : Nguyen Viet Quang 
 Using Carbided C/C++ to generate the project
 Description : Testing basic data types
 Remarks: - Standard Stack Size in Symbian OS is 8 KB.
 Created: 17-Feb-2008
 Last Modified: 23-Feb-2008
 ============================================================================
 */

//  Include Files  

#include <e32base.h>
#include <e32std.h>
#include <e32cons.h>			// Console

// Unicode converion
#include <charconv.h>
#include <utf.h>

#include "basictypes.h"
#include "utils.h"
//  Constants

_LIT(KTextConsoleTitle, "Console application");
_LIT(KTextFailed, " failed, leave code = %d");
_LIT(KTextPressAnyKey, " [press any key to exit]\n");

//  Global Variables

LOCAL_D CConsoleBase* console; // write all messages to this


//  Local Functions

LOCAL_C void MainL()
{
	//
	// add your program code here, example code below
	//
	console->Write(_L("Numbers: 00,11,22,33,44,55,66,77,88,99\n"));
	
	//
	// Start testing data type ...
	// All descritors have derived from TDesC, the Unicode implementation will be TDesC16
	// TDesC16:iLenght=32 bits format: First bit 0..3 - Descriptor type ( Stack, Heap, ROM ) of total maximum 16 types
	// Bit 4..31 - string lengtht. Thus maximum string length is 2^28 = 256 Mb  
	//
	TInt    iVal = 130;
	// TPtrC
	// TLitC16
	// 1) Create a TLitC16 instance in the stack using _LIT
	// TLitC16 object can be casted into TDesC16 object (see e32des16.h)  
	_LIT(KIntSize, " Sizeof TInt = %d bytes, value: %d, Sizeof TInt64 8888 = %d bytes\n");
	console->Printf(KIntSize, sizeof(iVal), iVal, sizeof(TInt64));
	
	// 2) Using buffer descriptors
	// _L Macro will create a temporary TPtrC variable on the stack
	TBuf<64>  buf;
	buf.Copy(_L("Size of float: %d, double aa: %d, boolean: %d\n"));  
	console->Printf(buf, sizeof(TReal32), sizeof(TReal), sizeof(TBool));
	
	// Test again the buffer descriptor	to ensure that it's Unicode string, the TBuf16
	console->Printf(_L("Buffer Length: %d chars, maxLength: %d chars\n"), 
			buf.Length(), buf.MaxLength());
	console->Printf(_L("Buffer size: %d bytes, maxSize: %d bytes\n"), 
			buf.Size(), buf.MaxSize());
	
	TBufC<64>  bufc(buf);
	// Using "printf" with %s will make the program crashed so use
	// "Write" method instead.
	console->Printf(_L("Const Buffer Length: %d chars\n"), bufc.Length()); 
	console->Write(bufc);

	console->Printf(_L("Size of TBufC: %d, TBuf: %d bytes\n"), sizeof(TBufC<5>), sizeof(TBuf<5>));	 

	// 3) Using heap buffer
	// Heap descriptor: Size of HBufC = 8 bytes  - Aligment of (HBufC16:iText=2 bytes + TDesC16:iLength=4 bytes)
	// Size of TPtrC = 8 bytes - Aligment of (TPrtC16:iPtr=4 bytes + TDesC16:iLength=4 bytes)
	// Size of TPtr = 12 bytes - Aligment of (TPrt16:iPtr=4 bytes + TDes16:iMaxLength=4 bytes + TDesC16:iLength=4 bytes)
	// Size of RBuf = 12 bytes - Aligment of (RBuf16:TUint16* or HBufC16*=4 bytes + TDes16:iMaxLength=4 bytes + TDesC16:iLength=4 bytes)
	
	console->Printf(_L("Size of HBufC: %d, TPtrC: %d, TPtr: %d, RBuf: %d  bytes\n"), 
			sizeof(HBufC), sizeof(TPtrC), sizeof(TPtr), sizeof(RBuf));	
	
	HBufC*  hBufc = CreateHBufCDescriptorLC();	
	// Copy data from  KHeapBufStr to hBufc
	console->Write(*hBufc);
	console->Printf(_L("Heap buffer length: %d\n"), hBufc->Length()); 
	
	// Clean up heap due to NewLC
	CleanupStack::PopAndDestroy(1);
	
	// 4) Modify heap buffer through a pointer descriptor
	_LIT(KFirstName, "Jude");
	_LIT(KLastName, "Law");
	
	// Heap buffer allocation
	HBufC* hbufc2 = HBufC::NewLC(KFirstName().Length());
	*hbufc2 = KFirstName;
	// Increase heap size while still holding first name 
	hbufc2 = hbufc2->ReAllocL(KFirstName().Length() + KLastName().Length());
	
	// New memory area has been reserved 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -