This document summarizes Symbian OS data types including integers, text, Boolean, floating point values, TAny, and enumerations. It also discusses Symbian OS naming conventions for classes, variables, and functions.
2. Tipos de dados elementares Integers Text Boolean Float TAny enums
3. 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;
4. 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’;
5. Boolean Boolean TBool flag = EFalse; // Note the implicit comparison if (!flag) { flag = ETrue; // could also do: flag = !flag; }
6. 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.
7. 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 otherwise e.g. void MyOtherFn();
8. Enumerations Exemplo de definição: enum TState {EOff, EInit, EOn}; Exemplo de utilização: TState state = GetState(); if (state == EOn) { // Do something }
10. 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; };
11. 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;
12. 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 timer timer.CreateLocal(); // Tracks the status of request TRequestStatus status; // Request timeout of 5 seconds timer.After(status, 5000000); // Wait for timer to complete synchronously User::WaitForRequest(status); ... timer.Close();
13. 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)
14. M Class Example class CAknAppUi : public CEikAppUi, public MEikStatusPaneObserver, public MCoeViewDeactivationObserver { ... }; class MEikStatusPaneObserver { public: virtual void HandleStatusPaneSizeChange()=0; };
15. 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
16. 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
17. 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
18. 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; }