02 Symbian Os Basics Tipos De Dados
Click here to load reader
-
Upload
tiago-romao -
Category
Technology
-
view
753 -
download
2
Transcript of 02 Symbian Os Basics Tipos De Dados
Symbian OS Basics
Módulo 3 - Tipos de dados
Symbian OS Basics
Tipos de dados elementares
Integers Text Boolean Float TAny enums
Symbian OS Basics
Integers Symbian OS defines its own basic types:
TInt is used for general integer arithmetic: typedef signed int TInt;
TUint is used for bitwise flags/handles typedef unsigned int TUint;
The following are used where size is of importance: typedef signed char TInt8; typedef unsigned char TUint8; typedef short int TInt16; typedef unsigned short int TUint16; typedef long int TInt32; typedef unsigned long int TUint32;
Symbian OS Basics
Text
Defaults to 16-bit for Unicode build:TText ch = ‘c’;
Build independent wide character:TText16 ch16 = ‘c’;
Build independent narrow character:TText8 ch8 = ‘c’;
Symbian OS Basics
Boolean
BooleanTBool flag = EFalse;// Note the implicit comparisonif (!flag){
flag = ETrue;// could also do: flag = !flag;
}
Symbian OS Basics
Floating Point Definições:
typedef float TReal32;typedef double TReal64;typedef double TReal;
Exemplo:TReal quotient = 0.234;TReal denominator = 2.431;TReal result = quotient / denominator;
Limitação Floating point support is processor dependant, so
floats should be avoided for speed reasons.
Symbian OS Basics
TAny
TAny é definido como void:typedef void TAny
TAny is used in preference to void* because it is more suggestive of the actual meaning.
e.g. TAny* MyFunction();
TAny usado exclusivamente como um apontador – void is used in preference otherwisee.g. void MyOtherFn();
Symbian OS Basics
Enumerations
Exemplo de definição:enum TState {EOff, EInit, EOn};
Exemplo de utilização:TState state = GetState();if (state == EOn){// Do something}
Symbian OS Basics
Conveções de sintaxe
Classes ’T’ classes ’C’ classes ’R’ classes ’M’ classes
Variables Functions Casting
Symbian OS Basics
T Classes Basic Types:
TInt counter = 0;• Structures:
struct TRectArea{
TInt iWidth;TInt iHeight;
};• Classes that do not own external objects/resources and so can be declared on
the stack:class TMyPoint{public:TMyPoint();TMyPoint(TInt aX, TInt aY);TInt iX;TInt iY;
};
Symbian OS Basics
C Classes If a class needs to allocate memory on the heap it
should derive from CBase and begin with a ‘C’:class CExample : public CBase{...private:CDesCArrayFlat* iArray ; // allocated dynamically...};
‘C’ classes must be declared on the heap:CExample* example = new (ELeave) CExample;...delete example;
Symbian OS Basics
R Classes ‘R’ classes contain handles to a real resource (other
than on the default heap) which is maintained elsewhere
Timer example:RTimer timer; // Handle to a timertimer.CreateLocal();// Tracks the status of requestTRequestStatus status;// Request timeout of 5 secondstimer.After(status, 5000000);// Wait for timer to complete synchronouslyUser::WaitForRequest(status);...timer.Close();
Symbian OS Basics
M Classes Características:
Abstract Pure virtual functions No member data
Propósito: definir um interface Vantagem: reduzir dependências entre
classes Regra: the only use of multiple inheritance
A C class can derive from one other C class and zero or more M classes
Caso de uso: receber notificações de eventos (callback)
Symbian OS Basics
M Class Exampleclass CAknAppUi : public CEikAppUi,public MEikStatusPaneObserver,public MCoeViewDeactivationObserver{
...};class MEikStatusPaneObserver{
public:virtual void HandleStatusPaneSizeChange()=0;
};
Symbian OS Basics
Variáveis
Variáveis membro começam com a letra ‘i’
Argumentos começam com ‘a’ Automatics’ (variavéis locais) começam
com letra minúscula Constantes começam com a letra ‘K’ Variáveis globais devem ser evitadas,
quando necessário, os nomes começam por uma letra maiúscula
Symbian OS Basics
Funções Functions’ names indicate what they do Capital letters are used in the beginning of words.
e.g. AddFileNameL() Data access functions are named as follows:
void SetHeight(TInt aHeight) {iHeight = aHeight;} TInt Height() {return iHeight;} Void GetHeight(TInt& aHeight) {aHeight = iHeight;}
Trailing "D" indicates the deletion of an object Trailing "L" means function may leave Trailing "C" means an item is placed on the cleanup
stack
Symbian OS Basics
Casting Native C++ operators should be used for
casting dynamic_cast
Cannot be used as there is no run time type information with Symbian OS
static_cast Used to cast a base class to derived class and
between base types reinterpret_cast
Used to cast a pointer type to another pointer type, to cast an integer type to pointer type and vice versa
const_cast Used to remove the const attribute from a type
Symbian OS Basics
Assert Catch programming and run-time errors early by using pre- and post-
conditions in functions, that is, assert that those conditions required for correct execution hold true. Two mechanisms (macros) support this programming style: __ASSERT_ALWAYS / __ASSERT_DEBUG class invariants.
Both of these mechanisms must be used. They catch programming errors early and aid in communicating the design and purpose of the class.
Avoid macros in release code. Macros are interpreted using text replacement, which is error-prone and never type-safe.
Assertions __ASSERT_ALWAYS to catch run-time invalid input (avoid usage in released
code) __ASSERT_DEBUG to catch programming errors
// Removes text content, commencing at position aPos, over aLength // number of characters void CComplexTextObject::Delete(TInt aPos,TInt aLength) { __TEST_INVARIANT; __ASSERT_ALWAYS(aPos>0,Panic(EPosOutsideTextObject)); iTextBuffer->Delete(aPos,aLength); TEST_INVARIANT; }