SlideShare uma empresa Scribd logo
1 de 25
Symbian OS TypesandDeclarations v2.0 – 17 May 2008
Disclaimer These slides are provided free of charge at http://www.symbianresources.com and are used during Symbian OS courses at the University of Applied Sciences in Hagenberg, Austria ( http://www.fh-hagenberg.at/ ) Respecting the copyright laws, you are allowed to use them: for your own, personal, non-commercial use in the academic environment In all other cases (e.g. for commercial training), please contact andreas.jakl@fh-hagenberg.at The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials. Parts of these materials are based on information from Symbian Press-books published by John Wiley & Sons, Ltd. This document contains copyright materials which are proprietary to Symbian, UIQ, Nokia and SonyEricsson. “S60™” is a trademark of Nokia. “UIQ™” is a trademark of UIQ Technology. Pictures of mobile phones or applications are copyright their respective manufacturers / developers. “Symbian ™”, “Symbian OS ™” and all other Symbian-based marks and logos are trademarks of Symbian Software Limited and are used under license. © Symbian Software Limited 2006.  Andreas Jakl, 2007
Contents Motivation Fundamental types Variable namingconventions Class namingconventions (T, C, R, M, static) Andreas Jakl, 2007 3
Motivation Most C++ frameworks define own fundamental types For compiler independence using typedef’s OpenGL: GLint, Symbian OS: TInt, … Symbian OS: Class Types Each has different characteristics Describes properties, behavior, creation on stack and/or heap, cleanup Simplifies correct use TPoint, CFbsBitmap, RFile, MCallbackInterface Andreas Jakl, 2007 4
NamingConventions Some more thoughts... Make code more self-explaining(“... and where's this variable coming from?”) Get rid of references using “this->” for instance variables Important for clean-up(Instance variables stored on the heap have to be deleted in the destructor of your class) Common syntax no matter who developed the code Andreas Jakl, 2007 5
Fundamental Types Symbian OS Andreas Jakl, 2007 6
Fundamental Types Defined in <SDK-path>poc32nclude32def.h Andreas Jakl, 2007 7 also available: TText[8|16], TInt[8|16|32], TUint[8|16|32], TUint64
Examples Andreas Jakl, 2007 8 Example: TInt, TReal TInt x = 5; TReal y = (TReal)x + 0.5; Example: TBool TBool b = ETrue; // Bad style: ETrue = 1, but any non-zero number should be interpreted as true! if (b == ETrue) { ... } // Good style: if (b) { ... } Example: void / TAny* // Symbian OS uses ‘void’ for ‘nothing’ and ‘TAny*’ for ‘pointer to anyting’ voidFoo();	// Returns no result TAny* p;		// Pointer to anything
Naming Conventions Symbian OS Andreas Jakl, 2007 9
General Overview Classes Name should be a noun, represents an object Name uses an initial letter to indicate the basic properties Data Name should be a noun, represents an object Name uses an initial letter to indicate their purpose Functions Name usually a verb, represents an action Initial letter should be uppercase(Draw(), Intersects()) Andreas Jakl, 2007 10 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
Variable Naming Conventions Andreas Jakl, 2007 11 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
Example – Variables Andreas Jakl, 2007 12 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes enumTStuffState// Declares an enumeration, prefix T     { EInitialized = 0,			// Individual elements with prefix E EError     }; constTIntKMaxLength = 50;	// Constant with prefix K classTStuff// T type class     { public: voidDoStuff(TIntaLength);	// Function argument with prefix a private: TIntiLength;				// Member (instance) variable with prefix i TStuffStateiState;     }; voidTStuff::DoStuff(TIntaLength)     { if(aLength > KMaxLength) iState = EError; else iLength = aLength;		// Note: no ambiguities!     }
T Classes Remember the fundamental types (TInt, ...)? T classes  similar behaviour Do not have a destructor Therefore, no member data that has a destructor Contain all data internally No pointers, references or handles (“has-a” relation) Can be created on the stack and the heap Also usually used instead of a traditional C struct Andreas Jakl, 2007 13 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
T Classes – Example  Andreas Jakl, 2007 14 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes TPoint definition from e32cmn.h classTPoint 	{ public: enumTUninitialized { EUninitialized }; /** Constructs default point, initialising its iX and iY members to zero. */ TPoint(TUninitialized) {} inlineTPoint(); inlineTPoint(TIntaX, TIntaY); 	IMPORT_C TBooloperator==(constTPoint& aPoint) const; // [...] 	IMPORT_C TPointoperator-() const; 	IMPORT_C voidSetXY(TIntaX, TIntaY); 	IMPORT_C TSizeAsSize() const; public: /** The x coordinate. */ TIntiX; /** The y coordinate. */ TIntiY; 	}; Note the naming conventions for an enum Usage example voidCMyControl::Draw(constTRect &aRect) const     { CWindowGc& gc = SystemGc (); gc.DrawLine (TPoint (0, 0), iLastPoint);     }
C Classes Properties of C classes (‘C’ for ‘cleanup’) Usually created on the heap(they’re often too large for stack themselves) Usually own pointers to large objects, resources, ... Derive from CBase (directly or indirectly) Safe construction / Destruction Zero initialization Andreas Jakl, 2007 15 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
C Classes – Characteristics Safe construction / destruction CBase defines virtual destructor C++ therefore calls destructor in correct order Also required for the cleanup stack (later module) Declares a private copy constructor and assignment operator Prevents errors If required: derived class has to declare it Zero initialization CBase overloads new-operator Zero-initializes all member data Andreas Jakl, 2007 16 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
C Classes – Example  Andreas Jakl, 2007 17 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes classCSprite : publicCBase     { public:	// Constructors and destructors staticCSprite* NewL( TIntaXVelocity, /* ... */, CFbsBitmap* aImage, CFbsBitmap* aMask); staticCSprite* NewLC( TIntaXVelocity, /* ... */, CFbsBitmap* aImage, CFbsBitmap* aMask); virtual ~CSprite(); public:	// New functions (omitted for clarity) private:	// Constructors CSprite( TIntaXVelocity, /* ... */, CFbsBitmap* aImage, CFbsBitmap* aMask); voidConstructL(); private:	// Data TPointiPosition; constCFbsBitmap * constiImage; constCFbsBitmap * constiMask;     };
R Classes Own an external resource handle, e.g.: Server session (RFs– file server session) Memory (RArray, RBuf) Initialization: Open(), Create() or Initialize() Close() or Reset() instead of destructor No automated Close() through the destructor! Andreas Jakl, 2007 18 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
R Classes – Example  Note: leaves and the cleanup stack will be covered in the following modules Andreas Jakl, 2007 19 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes voidCMyClass::SendCachedDataL()     { RSocketServsocketServer;     // Connect to the SocketServer     User::LeaveIfError( socketServer.Connect() );     // Make sure Close() is called at the end CleanupClosePushL( socketServer );     // … CleanupStack::PopAndDestroy();  // Calls Close() on the socket server object }
M Classes M class M is for “mixin” Used for defining interface classes Declares pure virtual functions Should not contain members or constructors Implementing class Usually derives from CBaseand the interface Only form of multiple inheritance encouraged on Symbian OS Andreas Jakl, 2007 20 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
M Classes – Example  Andreas Jakl, 2007 21 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes // Interface definition classMMdaAudioPlayerCallback         { public: virtualvoidMapcInitComplete(TIntaError, constTTimeIntervalMicroSeconds& aDuration) = 0; virtualvoidMapcPlayComplete(TIntaError) = 0;         }; // Implementing class classCSoundPlayer : publicCBase, publicMMdaAudioPlayerCallback         {         // [...] protected:  // Functions from base classes voidMapcInitComplete( TIntaError, constTTimeIntervalMicroSeconds& aDuration ); voidMapcPlayComplete( TIntaError );         // [...]         } The CBase-derivation always has to be first!
Static Classes Static classes provide utility code Can not be instantiated No prefix letter Andreas Jakl, 2007 22 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes Examples TIntcomputerMoveX = Math::Rand(iSeed) % iGridSize.iWidth;	 User::After(1000);		// Suspends the current thread for 1000 microseconds Mem::FillZ(&targetData, 12);	// Zero-fills 12-byte block starting from &targetData
Summary – Classes  Andreas Jakl, 2007 23 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
When to use which class type? Andreas Jakl, 2007 24 Class contains no member data Usually an interface  M classSometimes C class Class contains only static functions (or factory classes) Static class  no prefix Member data has no destructor / does not need special cleanup Only contains native types (T classes) or “uses-a” data  T class Size of the data contained by the class will be large (> 512 bytes) Stack is limited  avoid T class  typically a C class Class owns data that needs cleanup Usually a C class. Also R-classes, which are seldom implemented yourself
… let’s move to the Challenges! Try it for your own Andreas Jakl, 2007 25

Mais conteúdo relacionado

Semelhante a Symbian OS - Types And Declarations

#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
Hadziq Fabroyir
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
Ganesh Samarthyam
 
C++tutorial
C++tutorialC++tutorial
C++tutorial
dips17
 
Cvpr2010 open source vision software, intro and training part-iii introduct...
Cvpr2010 open source vision software, intro and training   part-iii introduct...Cvpr2010 open source vision software, intro and training   part-iii introduct...
Cvpr2010 open source vision software, intro and training part-iii introduct...
zukun
 

Semelhante a Symbian OS - Types And Declarations (20)

Symbian OS - Dynamic Arrays
Symbian OS - Dynamic ArraysSymbian OS - Dynamic Arrays
Symbian OS - Dynamic Arrays
 
Oops recap
Oops recapOops recap
Oops recap
 
Symbian OS - Memory Management
Symbian OS - Memory ManagementSymbian OS - Memory Management
Symbian OS - Memory Management
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 
Symbian OS - Descriptors
Symbian OS - DescriptorsSymbian OS - Descriptors
Symbian OS - Descriptors
 
P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
Eugene Burmako
Eugene BurmakoEugene Burmako
Eugene Burmako
 
Presentation_1370675757603
Presentation_1370675757603Presentation_1370675757603
Presentation_1370675757603
 
from java to c
from java to cfrom java to c
from java to c
 
Toonz code leaves much to be desired
Toonz code leaves much to be desiredToonz code leaves much to be desired
Toonz code leaves much to be desired
 
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
 
麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)麻省理工C++公开教学课程(二)
麻省理工C++公开教学课程(二)
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
 
C++tutorial
C++tutorialC++tutorial
C++tutorial
 
Cvpr2010 open source vision software, intro and training part-iii introduct...
Cvpr2010 open source vision software, intro and training   part-iii introduct...Cvpr2010 open source vision software, intro and training   part-iii introduct...
Cvpr2010 open source vision software, intro and training part-iii introduct...
 
Why rust?
Why rust?Why rust?
Why rust?
 
JNA - Let's C what it's worth
JNA - Let's C what it's worthJNA - Let's C what it's worth
JNA - Let's C what it's worth
 
Understanding C# in .NET
Understanding C# in .NETUnderstanding C# in .NET
Understanding C# in .NET
 
SimpleArray between Python and C++
SimpleArray between Python and C++SimpleArray between Python and C++
SimpleArray between Python and C++
 

Mais de Andreas Jakl

Mais de Andreas Jakl (20)

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented Reality
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with Unity
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App Management
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSON
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - Introduction
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web Technologies
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test Automation
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer Training
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC Quickstart
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App Scenarios
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt Communication
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Symbian OS - Types And Declarations

  • 1. Symbian OS TypesandDeclarations v2.0 – 17 May 2008
  • 2. Disclaimer These slides are provided free of charge at http://www.symbianresources.com and are used during Symbian OS courses at the University of Applied Sciences in Hagenberg, Austria ( http://www.fh-hagenberg.at/ ) Respecting the copyright laws, you are allowed to use them: for your own, personal, non-commercial use in the academic environment In all other cases (e.g. for commercial training), please contact andreas.jakl@fh-hagenberg.at The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials. Parts of these materials are based on information from Symbian Press-books published by John Wiley & Sons, Ltd. This document contains copyright materials which are proprietary to Symbian, UIQ, Nokia and SonyEricsson. “S60™” is a trademark of Nokia. “UIQ™” is a trademark of UIQ Technology. Pictures of mobile phones or applications are copyright their respective manufacturers / developers. “Symbian ™”, “Symbian OS ™” and all other Symbian-based marks and logos are trademarks of Symbian Software Limited and are used under license. © Symbian Software Limited 2006. Andreas Jakl, 2007
  • 3. Contents Motivation Fundamental types Variable namingconventions Class namingconventions (T, C, R, M, static) Andreas Jakl, 2007 3
  • 4. Motivation Most C++ frameworks define own fundamental types For compiler independence using typedef’s OpenGL: GLint, Symbian OS: TInt, … Symbian OS: Class Types Each has different characteristics Describes properties, behavior, creation on stack and/or heap, cleanup Simplifies correct use TPoint, CFbsBitmap, RFile, MCallbackInterface Andreas Jakl, 2007 4
  • 5. NamingConventions Some more thoughts... Make code more self-explaining(“... and where's this variable coming from?”) Get rid of references using “this->” for instance variables Important for clean-up(Instance variables stored on the heap have to be deleted in the destructor of your class) Common syntax no matter who developed the code Andreas Jakl, 2007 5
  • 6. Fundamental Types Symbian OS Andreas Jakl, 2007 6
  • 7. Fundamental Types Defined in <SDK-path>poc32nclude32def.h Andreas Jakl, 2007 7 also available: TText[8|16], TInt[8|16|32], TUint[8|16|32], TUint64
  • 8. Examples Andreas Jakl, 2007 8 Example: TInt, TReal TInt x = 5; TReal y = (TReal)x + 0.5; Example: TBool TBool b = ETrue; // Bad style: ETrue = 1, but any non-zero number should be interpreted as true! if (b == ETrue) { ... } // Good style: if (b) { ... } Example: void / TAny* // Symbian OS uses ‘void’ for ‘nothing’ and ‘TAny*’ for ‘pointer to anyting’ voidFoo(); // Returns no result TAny* p; // Pointer to anything
  • 9. Naming Conventions Symbian OS Andreas Jakl, 2007 9
  • 10. General Overview Classes Name should be a noun, represents an object Name uses an initial letter to indicate the basic properties Data Name should be a noun, represents an object Name uses an initial letter to indicate their purpose Functions Name usually a verb, represents an action Initial letter should be uppercase(Draw(), Intersects()) Andreas Jakl, 2007 10 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 11. Variable Naming Conventions Andreas Jakl, 2007 11 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 12. Example – Variables Andreas Jakl, 2007 12 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes enumTStuffState// Declares an enumeration, prefix T { EInitialized = 0, // Individual elements with prefix E EError }; constTIntKMaxLength = 50; // Constant with prefix K classTStuff// T type class { public: voidDoStuff(TIntaLength); // Function argument with prefix a private: TIntiLength; // Member (instance) variable with prefix i TStuffStateiState; }; voidTStuff::DoStuff(TIntaLength) { if(aLength > KMaxLength) iState = EError; else iLength = aLength; // Note: no ambiguities! }
  • 13. T Classes Remember the fundamental types (TInt, ...)? T classes  similar behaviour Do not have a destructor Therefore, no member data that has a destructor Contain all data internally No pointers, references or handles (“has-a” relation) Can be created on the stack and the heap Also usually used instead of a traditional C struct Andreas Jakl, 2007 13 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 14. T Classes – Example Andreas Jakl, 2007 14 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes TPoint definition from e32cmn.h classTPoint { public: enumTUninitialized { EUninitialized }; /** Constructs default point, initialising its iX and iY members to zero. */ TPoint(TUninitialized) {} inlineTPoint(); inlineTPoint(TIntaX, TIntaY); IMPORT_C TBooloperator==(constTPoint& aPoint) const; // [...] IMPORT_C TPointoperator-() const; IMPORT_C voidSetXY(TIntaX, TIntaY); IMPORT_C TSizeAsSize() const; public: /** The x coordinate. */ TIntiX; /** The y coordinate. */ TIntiY; }; Note the naming conventions for an enum Usage example voidCMyControl::Draw(constTRect &aRect) const { CWindowGc& gc = SystemGc (); gc.DrawLine (TPoint (0, 0), iLastPoint); }
  • 15. C Classes Properties of C classes (‘C’ for ‘cleanup’) Usually created on the heap(they’re often too large for stack themselves) Usually own pointers to large objects, resources, ... Derive from CBase (directly or indirectly) Safe construction / Destruction Zero initialization Andreas Jakl, 2007 15 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 16. C Classes – Characteristics Safe construction / destruction CBase defines virtual destructor C++ therefore calls destructor in correct order Also required for the cleanup stack (later module) Declares a private copy constructor and assignment operator Prevents errors If required: derived class has to declare it Zero initialization CBase overloads new-operator Zero-initializes all member data Andreas Jakl, 2007 16 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 17. C Classes – Example Andreas Jakl, 2007 17 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes classCSprite : publicCBase { public: // Constructors and destructors staticCSprite* NewL( TIntaXVelocity, /* ... */, CFbsBitmap* aImage, CFbsBitmap* aMask); staticCSprite* NewLC( TIntaXVelocity, /* ... */, CFbsBitmap* aImage, CFbsBitmap* aMask); virtual ~CSprite(); public: // New functions (omitted for clarity) private: // Constructors CSprite( TIntaXVelocity, /* ... */, CFbsBitmap* aImage, CFbsBitmap* aMask); voidConstructL(); private: // Data TPointiPosition; constCFbsBitmap * constiImage; constCFbsBitmap * constiMask; };
  • 18. R Classes Own an external resource handle, e.g.: Server session (RFs– file server session) Memory (RArray, RBuf) Initialization: Open(), Create() or Initialize() Close() or Reset() instead of destructor No automated Close() through the destructor! Andreas Jakl, 2007 18 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 19. R Classes – Example Note: leaves and the cleanup stack will be covered in the following modules Andreas Jakl, 2007 19 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes voidCMyClass::SendCachedDataL() { RSocketServsocketServer; // Connect to the SocketServer User::LeaveIfError( socketServer.Connect() ); // Make sure Close() is called at the end CleanupClosePushL( socketServer ); // … CleanupStack::PopAndDestroy(); // Calls Close() on the socket server object }
  • 20. M Classes M class M is for “mixin” Used for defining interface classes Declares pure virtual functions Should not contain members or constructors Implementing class Usually derives from CBaseand the interface Only form of multiple inheritance encouraged on Symbian OS Andreas Jakl, 2007 20 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 21. M Classes – Example Andreas Jakl, 2007 21 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes // Interface definition classMMdaAudioPlayerCallback { public: virtualvoidMapcInitComplete(TIntaError, constTTimeIntervalMicroSeconds& aDuration) = 0; virtualvoidMapcPlayComplete(TIntaError) = 0; }; // Implementing class classCSoundPlayer : publicCBase, publicMMdaAudioPlayerCallback { // [...] protected: // Functions from base classes voidMapcInitComplete( TIntaError, constTTimeIntervalMicroSeconds& aDuration ); voidMapcPlayComplete( TIntaError ); // [...] } The CBase-derivation always has to be first!
  • 22. Static Classes Static classes provide utility code Can not be instantiated No prefix letter Andreas Jakl, 2007 22 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes Examples TIntcomputerMoveX = Math::Rand(iSeed) % iGridSize.iWidth; User::After(1000); // Suspends the current thread for 1000 microseconds Mem::FillZ(&targetData, 12); // Zero-fills 12-byte block starting from &targetData
  • 23. Summary – Classes Andreas Jakl, 2007 23 Variables | T Classes | C Classes | R Classes | M Classes | Static Classes
  • 24. When to use which class type? Andreas Jakl, 2007 24 Class contains no member data Usually an interface  M classSometimes C class Class contains only static functions (or factory classes) Static class  no prefix Member data has no destructor / does not need special cleanup Only contains native types (T classes) or “uses-a” data  T class Size of the data contained by the class will be large (> 512 bytes) Stack is limited  avoid T class  typically a C class Class owns data that needs cleanup Usually a C class. Also R-classes, which are seldom implemented yourself
  • 25. … let’s move to the Challenges! Try it for your own Andreas Jakl, 2007 25