02 Symbian Os Basics Tipos De Dados


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • 02 Symbian Os Basics Tipos De Dados

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