Programming mobile devices Part II Programming Symbian devices with Symbian C++ Strings, Buffers and data collections.

Slides:



Advertisements
Similar presentations
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Advertisements

Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
LECTURE 17 C++ Strings 18. 2Strings Creating String Objects 18 C-string C++ - string \0 Array of chars that is null terminated (‘\0’). Object.
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Strings.
Ch 8. Characters and Strings Timothy Budd 2 Characters and Literals Strings Char in C++ is normally an 8-bit quantity, whereas in Java it is a 16-bit.
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
Current Assignments Homework 5 will be available tomorrow and is due on Sunday. Arrays and Pointers Project 2 due tonight by midnight. Exam 2 on Monday.
Java Programming Strings Chapter 7.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
C++ Sets and Multisets Set containers automatically sort their elements automatically. Multisets allow duplication of elements whereas sets do not. Usually,
 Basically, a sequence of characters  Character? › Like… a letter › Or a number › Or even blank space.
Today’s Class Class string –The basics –Assignment –Concatenation –Compare & swap –Find –Conversion to C-style char * strings –Iterators.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
CSE 333 – SECTION 4. Overview Pointers vs. references Const Classes, constructors, new, delete, etc. More operator overloading.
Data Structures Using C++ 2E
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
Chapter 6 One-Dimensional Arrays ELEC 206 Computer Tools for Electrical Engineering.
TECH Computer Science Dynamic Sets and Searching Analysis Technique  Amortized Analysis // average cost of each operation in the worst case Dynamic Sets.
More C++ Features True object initialisation
Chapter 5 Strings CSC1310 Fall Strings Stringordered storesrepresents String is an ordered collection of characters that stores and represents text-based.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
String Class. C-style and C++ string Classes C-style strings, called C-strings, consist of characters stored in an array ( we’ll look at them later) C++
Symbian Programming Overview Spring 2004: Symbian Larry Rudolph How to program Cellphone? Limited to Series 60 phones Java MidP 2.0 (see wiki,
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
© Oxford University Press All rights reserved. CHAPTER 6 STRINGS.
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
12/23/2015Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 9 An Introduction.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Charles Clute Tom Most Michael Hein. Strings in C  There is no String... But there’s hope! Strings are character arrays char volume[6]; char volume[6]
Java String 1. String String is basically an object that represents sequence of char values. An array of characters works same as java string. For example:
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
1. Iterative Preorder Traversal Rpreorder(T) 1. [process the root node] if T!= NULL then Write Data(T) else Write “empty Tree” 2. [process the left subtree]
Dynamic Programming & Memoization. When to use? Problem has a recursive formulation Solutions are “ordered” –Earlier vs. later recursions.
Const declares immutable value void Test(char* t) { t++;// OK, address is not const t[0] = 'a'; // OK, char is not const } void Test2(const char* t) {
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Assignment #2. Regular Expression (RE) Represent a string pattern – Consists of regular characters and wild cards Assignment #2: implement a subset of.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Strings.
String and Lists Dr. José M. Reyes Álamo.
C++ Memory Management – Homework Exercises
Introduction Programs which manipulate character data don’t usually just deal with single characters, but instead with collections of them (e.g. words,
Do-more Technical Training
Stack and Heap Memory Stack resident variables include:
Sorted Linked List Same objective as a linked list, but it should be sorted Sorting can be custom according to the type of nodes Offers speedups over non-sorted.
String String Builder.
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Object Oriented Programming COP3330 / CGS5409
Pointers, Dynamic Data, and Reference Types
String class and its objects
String and Lists Dr. José M. Reyes Álamo.
String.
Introduction to Computer Science
COP 3330 Object-oriented Programming in C++
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
CS31 Discussion 1H Fall18: week 6
character manipulation
EECE.2160 ECE Application Programming
SPL – PS2 C++ Memory Handling.
Chapter 12: More on C-Strings and the string Class
Presentation transcript:

Programming mobile devices Part II Programming Symbian devices with Symbian C++ Strings, Buffers and data collections

Content Descriptors Dynamic Buffers

Descriptors Data buffer Buffers size Different descriptors for different purposes Methods for –writing the buffer –reading the buffer –accessing different properties of the buffer, like the size

Descriptors Buffer –the buffer is inside the descriptor –TBuf... Pointer –the buffer is outside and the descriptor contains a pointer to the buffer –TPtr... Heap –HBuf...

Descriptors Can be either modifiable or not C for constant e.g. HBufC Either 8 or 16 bit data e.g. TBuf8

Non-modifiable API Length() Size() Ptr() (const TUInt *) Alloc(), AllocL(), AllocLC() Left(), Mid(), Right() Find() 0 based offset or KErrNotFound, ==, !=, [] =

Modifiable API MaxLength() MaxSize() SetLength(),SetMax(),Zero() Append() Insert() Delete() Format() Copy()

Descriptor classes TBuf8 modifiable 8 bit buffer TBuf16 modifiable 16 bit buffer TBuf8C non-modifiable 8 bit buffer TBuf16C non-modifiable 16 bit buffer TPtr8 modifiable 8 bit pointer descriptor TPtr16 modifiable 16 bit pointer descriptor

Descriptor classes TPtrC8 non-modifiable 8 bit pointer descriptor TPtrC16 non-modifiable 16 bit pointer descriptor HBuf8C non-modifiable 8 bit heap descriptor HBuf16C non-modifiable 16 bit heap descriptor

String descriptors 16 bit descriptors (unicode) For binary data 8 bit descriptors For strings we use literals, which behave like descriptors

Literals _LIT _L e.g. _LIT(myString, "Test data...") behaves like a non-modifiable descriptor _LIT creates an instance of TLitC class Can be converted to Descriptors

Literal to Descriptor Three ways –implicit –& –() e.g. _LIT(KMyExampleLiteral, "Test data...") const TDesc *ptr = &KMyExampleLiteral; or KMyExampleLiteral().Length();

Buffer Descriptors TBuf and TBufC –the class contains the data buffer TBuf Buf would be a 16 bit descriptor with a buffer large enough for bit values Type 4b Length 28 b Max length 32 b Buffer

HBufC H for Heap (allocate on the heap, but does not inherit CBase) New() if no leaving needed NewL() if leaving necessary NewLC() if cleanup stack needed Alloc() can be used to create a HBufC from an existing descriptor

Modifying HBufC content HBufC::Des() returns a TPtr pointer e.g. _LIT(testString, "PLO"); HBufC *testBuf = HBufC::NewLC(testString().Length()); TPtr testPtr = testBuf->Des(); testPtr.Copy(testString);

HBufC::ReAlloc Very handy for incrementing the size of a HBufC e.g. HBufC *firstBuf = HBufC::NewLC(10);.... firstBuf=firstBuf->ReAlloc(20);...

HBufC::ReAlloc be careful with cleanup stack (if you use cleanup stack, be sure to pop the old pointer and push the new one) You can also use ReAllocLC

TBuf TBuf buf creates an empty buffer _LIT(KString,"Hello"); TBuf buf(KString); creates the buffer with letters Hello in it _LIT(KString,"Hello"); TBuf buf(); buf.Copy(KString); copies Hello into buf

TBuf _LIT(KString2," world"); buf.Append(KString2); appends world into buf Be careful not to go past the limit of the buffer (a buffer with 10 elements in the previous example would not be enough)

TBufC C for constant not modifiable hence, only one length value you cannot add data you can replace old data replacing is done with = operator

Descriptors as arguments Often base class types used TDes and TDesC e.g. void doSomething(const &TDesC) void doMore(&TDes)

... and return types A function can also return a descriptor e.g. const TDesc& myFunc() { return...; }

Comparison Strings can be compared with the Compare method, for example: _LIT(KStr1, "PLO"); _LIT(KStr2, "plo"); TBuf str1(KStr1); TInt result = str1.Compare(KStr1); 0 for same, negative if KStr1 is less and positive if KStr1 is greater than str1

Search using function Find _LIT(KStr1, "example text for searching"); _LIT(KStr2, "for"); TBuf str1(KStr1); TInt result = str1.Find(KStr1); returns either -1 (KErrNotFound) or the position

Match Like Find, but wildcards, like * are accepted. * any string sequence ? any one character _LIT(KStr1, "PLO"); _LIT(KStr2, "?LO"); TBuf str2(KStr2); TInt result = str2.Match(KStr1);

Substrings Left Right Mid e.g. _LIT(KStr1, "Symbian programming..."); TBuf str1(KStr1); TPtrC result = str1.Left(7); // Symbian TPtrC result = str1.Mid(12,4); // gram

Copying to a descriptor use Copy() –replaces existing data –updates the size CopyCP capital CopyLC lower case CopyUC upper case

Copying to a descriptor TUInt8 binaryData[4] = {0xB0,0xB1,0xB2,0xB3}; TBuf8 binDescr; binDescr.Copy(binaryData, sizeof(binaryData));

Appending to a descriptor _LIT(KStr1, "PLO"); _LIT(KStr2, " course"); TBuf str(KStr1); TInt result = str.Append(KStr2);