Object oriented

Object oriented operating system

6836879

Abstract

An object oriented operating system handles all objects related to text strings as belonging to one of three classes, in which each class performs a different function and at least one such class is modified to do so in a way that reduces code and cycle overhead. This reduces executable code overhead to minimise the amount of memory required, and allows execution in a minimum number of cycles to minimise power consumption. The operating system is particularly well suited to ROM based mobile computing devices.


Claims

What is claimed is:

1. A computing device programmed to manipulate or access objects of the string class using an object oriented operating system, wherein the objects of the string class are derived from a single base class and the operating system handles all such objects of the string class according to one or more of the following requirements:

(a) objects of the string class for literal text are handled as belonging to a class in which a pointer points to the memory location where the text string is stored;

(b) objects of the string class for length limited text are handled as belonging to a class in which a buffer stores text of a predetermined length requiring a limited subset of available memory management functions; and

(c) objects of the string class using heap memory are handled as belonging to a class requiring the full set of available memory management functions.

2. The computing device of claim 1, further comprising a program which interfaces with the operating system and which also handles objects according to one or more of the requirements.

3. The computing device of claim 1, wherein objects satisfying one or more of the requirements are flat structures.

4. The computing device of claim 1, wherein objects of the string class for length limited text are stored in particular memory locations at run time which are not part of the heap memory.

5. The computing device of claim 1, wherein the objects are polymorphic.

6. The device of claim 5, wherein polymorphism is achieved by providing a data field for each object which identifies its class, with a different action being associated with different data field values.

7. The computing device of claim 6, wherein the data field is a part of the representation of another data item within a machine word.

8. The computing device of claim 7, wherein the same source code is used, irrespective of the character code system and character code width being used, by using aliases for class names that are character code independent.

9. The computing device of claim 8, wherein the source code using text strings is written in a manner independent of the strings' actual ASCII or Unicode implementation by using a system of aliases for class names.

10. The computing device of claim 1, wherein objects have information on the length of the data they contain and hence have no `0` terminator.

11. A method of allowing objects of the string class to be manipulated or accessed by a program using an object oriented operating system, wherein the program handles all such objects according to one or more of the following requirements:

(a) objects of the string class for literal text are handled as belonging to a class in which a pointer points to the memory location where the text string is stored;

(b) objects of the string class for length limited text are handled as belonging to a class in which a buffer stores text of a predetermined length requiring a limited subset of available memory management functions; and

(c) objects of the string class using heap memory are handled as belonging to a class requiring the full set of available memory management functions.

12. The method of claim 11, being performed by an operating system.

13. The method of claim 11, being performed by a program which interfaces with an operating system which itself also performs the method of claim 11.

14. The method of claim 11, wherein objects satisfying one or more of the requirements are flat structures.

15. The method of claim 11, wherein objects of the string class for length limited text are stored in particular memory locations at run time which are not part of the heap memory.

16. The method of claim 11, wherein the objects are polymorphic.

17. The method of claim 16, wherein polymorphism is achieved by providing a data field for each object which identifies its class, with a different action being associated with different data field values.

18. The method of claim 17, wherein the data field is a part of the representation of another data item within a machine word.

19. The method of claim 18, wherein the same source code is used, irrespective of the character code system and character code width being used, by using aliases for class names that are character code independent.

20. The method of claim 19, wherein the source code using text strings is written in a manner independent of the strings' actual ASCII or Unicode implementation by using a system of aliases for class names.

21. The method of claim 11, wherein objects have information on the length of the data they contain and hence have no `0` terminator.

22. Computer software which allows objects of the string class to be manipulated or accessed by a program using an object oriented operating system, wherein the program handles all such objects according to one or more of the following requirements:

(a) objects of the string class for literal text are handled as belonging to a class in which a pointer points to the memory location where the text string is stored;

(b) objects of the string class for length limited text are handled as belonging to a class in which a buffer stores text of a predetermined length requiring a limited subset of available memory management functions; and

(c) objects of the string class using heap memory are handled as belonging to a class requiring the fall set of available memory management functions.

23. The computer software of claim 22, being an object oriented operating system.

24. The computer software of claims 23, further comprising a program which is capable of interfacing with the object oriented operating system.

25. The computer software of claim 22, wherein in which objects satisfying one or more of the requirements are flat structures.

26. The computer software of claim 22, wherein objects of the string class for length limited text are stored in particular memory locations at run time which are not pat of the heap memory.

27. The computer software of claim 22, wherein the objects are polymorphic.

28. The computer software of claim 27, wherein polymorphism is achieved by providing a data field for each object which identifies its class, with a different action being associated with different data field values.

29. The computer software of claim 28, wherein the data field is a part of the representation of another data item within a machine word.

30. The computer software of claim 29, wherein the same source code is used, irrespective of the character code system and character code width being used, by using aliases for class names that are character code independent.

31. The computer software of claim 30, wherein the source code using text strings is written in a manner independent of the strings' actual ASCII or Unicode implementation by using a system of aliases for class names.

32. The computer software of claim 22, wherein objects have information on the length of the data they contain and hence have no `0` terminator.


Description

BACKGROUND

1. Field of the Invention

This invention relates to an improved object oriented operating system for a computer. In particular, it relates to an operating system which is based on C++ programming techniques. The commercially available embodiment of this operating system is the EPOC32 operating system produced by Psion Software Plc of England. EPOC32 is a preferred operating system in the mobile computing environment.

2. Description of the Related Art

The C++ programming language is widely used for writing application programs for computers, such as Personal Computers, although it has only rarely been widely adopted for writing operating systems. When writing for Personal Computers, there is generally no overriding requirement to either minimise the size of the executable code or to minimise the number of cycles required for executing steps within the program. Typically, performance and ease of authorship are the more significant requirements.

But there are other contexts in which the executable code must occupy the minimum amount of space (e.g. to minimise the amount of ROM and/or RAM required to store it), and to execute in the minimum number of cycles (e.g. to minimise power consumption).

The mobile computing (e.g. personal digital assistants), smart phone (e.g. GSM cellular telephones with in-built word processing, facsimile send/receive and Internet browsing capabilities) and network computer ("NC") environments exemplify contexts in which there are advantages to minimising the code size of the operating system: namely, the hardware costs (particularly ROM and/or RAM) can then be reduced. That is particularly significant in the above contexts since widespread consumer adoption is generally dependent on relatively low hardware pricing. Similarly, minimising processor execution cycles of the operating system is very important in the mobile computing and smart phone contexts, since doing so minimises power consumption and minimising power consumption is critical to long battery life. A fully architected operating system written in C++ would generally be substantial in size and be power hungry. Hence, it would it be unsuitable for the mobile computing, smart phone and NC environments.

Further, it is generally regarded as difficult to design a fully functional operating system in C++ that meets stringent requirements for code size and cycle overhead, particularly the stringent requirements associated with the mobile, smart phone and NC computing environments.

Some Terminology

"Objects of the String Class"

In C++, text (e.g. strings of letters that will actually appear on a computer screen) is represented as an "Object". The implementer skilled in C++ or other object oriented languages will be familiar with this categorisation. Such text related Objects are of a particular type, which we shall call "Objects of the String Class": The kind of Class that an Object belongs to (e.g. in the case of text, the String Class) defines the allowable manipulations that can be performed on that Object. Only certain manipulations can be performed on Objects of the String Class (e.g. concatenating 2 text strings together). A particular Object of the String Class therefore represents a particular text string. It can only be manipulated in certain, well defined ways.

The following steps are performed in conventional C++ programming in order to create an Object of the String Class from an item of text, where the text resides in a file in the filing system:

set aside a buffer location in memory

read the text into the buffer using a file reading service

use a string creation service to turn the buffered data into an Object of the String Class

discard the buffer contents

The actual storage location of the text string is difficult to identify in C++, but one does not need to know its location since it is the Object of the String Class that one manipulates directly: that in turn causes the actual text string to be manipulated. Hence the Object of the String Class in effect knows the memory location of the text string and can handle all the necessary memory management tasks associated with text manipulation.

Multiple Classes of Objects of the String Class

In the version of C++ known as the draft ANSL/ISO C++ Standard, all Objects of the String Class (as exemplified by the string class in that part of the draft C++ Standard Library of the above Standard referred to as <string>) are handled in a manner that enables sophisticated memory management tasks to be accomplished (e.g. re-allocating buffer space for text that can grow or shrink or be spliced--fully dynamic text). But this level of memory management uses a great deal of code and may require considerable heap space.

Two examples of conventional C++ memory management illustrate this:

Example 1: C++ Handling of Literal Text

In C++, there are many instances in which source code contains text strings. These strings are known as `Literal Text` and are permanently stored in buffer memory on compilation of the source code into executable object code. When Literal Text is to be manipulated, then an Object of the String Class must be created from it. However, creation of that Object of the String Class itself leads to the creation in memory of the text string which the newly created Object of the String Class in fact manipulates. Hence, the text string is duplicated in memory: once in the original buffer that arises on compilation of the source code and again in the memory location associated with the Object of the String Class that enables the text to be manipulated.

As noted above, in some computing environments, code space and power consumption are at a premium. However, in conventional C++ (i.e. as implemented in the draft ANSI/ISO C++ Standard), there is no mechanism to overcome the inherent duplication in memory of Literal Text. That is problematic, especially for an operating system since, in an operating system, there are many occasions in which Literal Text must be handled.

Example 2: C++ Handling of Length Limited Text

In C++, a programmer handles text using heap memory. Text whose length is limited does not in fact require the fully flexible approach that is needed to handle text whose length is not limited. However, in conventional C++, there is no mechanism for using anything other than fully flexible, fully featured Objects of the String Class, irrespective of the length of text. That leads to a high overhead in memory management code since handling heap memory is code and cycle intensive.

Overall, text memory management in C++ is code and cycle intensive. Since code space and power consumption are at a premium in mobile environments, the conventional C++approach would lead to an operating system that is unacceptably large in terms of code size and is also too power hungry.

SUMMARY

The operating system of the present invention re-defines Objects of the String Class (i.e. as defined in the draft ANSI/ISO C++ Standard), by substituting them with a three fold structure of Objects of the String Class, namely three new Classes of Objects. The conventional, fully featured memory management functionality associated with <string> from the draft ANSI/ISO C++ Standard is not applied to all three of the new classes. Whilst that full functionality is useful in many environments, it is problematic in (inter alia) mobile computing environments in which code space and power consumption are at a premium.

Hence, the generalisation of the inventive concept of the present invention is to minimise code size and cycle overhead by providing, in a computer operating system, a family of three different Classes for handling text strings: each different class is appropriate for a different circumstance. This allows flexibility: for example, the fully featured memory management functionality can now be applied solely to those text strings that actually require it.

We shall refer to this new family of String Class Objects as "Descriptors". In a preferred embodiment, we call the members of this family "Pointer Descriptors", "Buffer Descriptors" and "Heap Descriptors". Care should be taken to note that these concepts are different (although related to) the established concepts of "pointers", "buffers" and "heaps", with which the skilled implementer will be familiar. Care should also be taken to note that the Descriptors envisaged in this specification have no relationship to the VMS facility of the same name, nor the UNIX term for small integer numbers used to identify active operating system files. The skilled implementer may appreciate that it is possible to design an operating system in which the number of Classes for handling text strings exceeds three: such variants are within the scope of the present invention. The three fold structure is the minimum (and in almost all cases, the most effective) proliferation of Classes.

Further, Descriptors are preferably polymorphic: hence, a single service can operate on all Descriptors. That leads to significant savings in code and, to a lesser extent, cycle overhead, since otherwise modified services would be needed for each of different Descriptors.

Hence, in accordance with a first aspect of the present invention, there is provided a computer programmed with an object oriented operating system, in which the operating system is adapted to handle objects related to text strings;

characterised in that the operating system handles all such objects as belonging to one of three classes (namely the Pointer Descriptor Class, the Buffer Descriptor Class and the Heap Descriptor Class), in which each class performs a different function and at least one such class is modified to do so in a way that reduces code and cycle overhead.

The invention is founded upon the insight that in order to deliver significant reductions in code and cycle overhead, one has to redesign the operating system by substituting the conventional, single form of Object of the String Class (for example) with three different forms of that Object: each form is optimised for different circumstances.

In a preferred form of the invention, conventional, memory intensive text handling techniques are applied only to Objects which fall within the new Descriptor Class which defines Objects requiring such techniques (i.e. Heap Descriptors). The Pointer and Buffer Descriptor Classes are however designed in a manner that reduces code and processor cycles compared to conventional String Classes.

Using the two examples mentioned in the Description of the Prior Art above (i.e. Example 1: C++ Handling of literal text and Example 2: C++ Handling of length limited text), the operating system of the present invention (i) handles Literal Text in a manner that eliminates the need for a duplicate copy of Literal Text and (ii) handles text which is determined dynamically at run time in a manner that only requires code intensive utilisation of heap memory in those limited circumstances in which it is actually necessary to do so: in other circumstances (for example, where the programmer knows in advance the maximum length of the text), then static memory is used instead. Fuller details of the specific handling is given below (see section titled Detailed Description).

Preferably, the operating system is adapted to handle not only text but also raw data using the same three fold structure.

In addition to the combined computer/operating system as defined above, one can identify further inventive aspects. For example, any device that has to interface with such an operating system must also use the same three-fold structure for Objects of the String Class. For example, driver software for peripherals such as solid state memory devices will have to use this three fold-structure. Likewise, control panel software for peripherals will also have to.

Hence, in a second aspect of the present invention, there is provided a peripheral device for a computer programmed with an object oriented operating system, in which the operating system is adapted to handle objects related to text strings;

characterised in that the operating system handles all such objects as belonging to one of three classes (namely the Pointer Descriptor Class, the Buffer Descriptor Class and the Heap Descriptor Class), in which each class performs a different function and at least one such class is modified to do so in a way that reduces code and cycle overhead and is further characterised in that the peripheral device is programmed to handle objects which also fall into the above three classes.

In a third aspect of the present invention, there is provided an operating system encoded on computer readable media, in which the operating system handles objects related to text strings;

characterised in that the operating system is adapted to handle all such objects as belonging to one of three classes (namely the Pointer Descriptor Class, the Buffer Descriptor Class and the Heap Descriptor Class), in which each class performs a different function and at least one such class is modified to do so in a way that reduces code and cycle overhead.

In a fourth aspect of the invention, there is provided a method of operating a micro-processor using an operating system, in which the operating system is adapted to handle objects related to text strings;

characterised in that the operating system handles all such objects as belonging to one of three classes (namely the Pointer Descriptor Class, the Buffer Descriptor Class and the Heap Descriptor Class), in which each class performs a different function and at least one such class is modified to do so in a way that reduces code and cycle overhead.

In a fifth aspect, there is provided computer readable media encoded with an operating system adapted to handle objects related to text strings;

characterised in that the operating system handles all such objects as belonging to one of three classes, in which each class performs a different function and at least one such class is modified to do so in a way that reduces code and cycle overhead. Typically, the computer readable media will be a masked ROM. For distribution purposes, the media may also be a conventional CD-ROM or floppy disc.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is an illustration of a constant pointer descriptor;

FIG. 2A is an illustration of a modifiable pointer descriptor pointing to an area in at memory;

FIG. 2B is an illustration of a modifiable pointer descriptor pointing to another descriptor;

FIG. 3 is an illustration of a constant buffer descriptor;

FIG. 4 is an illustration of a modifiable pointer descriptor pointing to a constant buffer descriptor;

FIG. 5 is an illustration of a modifiable buffer descriptor;

FIG. 6 is an illustration of a constant heap descriptor;

FIG. 7 is an illustration of a modifiable pointer descriptor pointing to an allocated constant heap descriptor;

FIG. 8 is an illustration of the member functions available to members of the various descriptor classes;

FIGS. 9, 10 illustrate an example to construct a pointer descriptor for leftmost part of data;

FIGS. 11, 12 illustrate an example to construct a pointer descriptor for rightmost part of data;

FIGS. 13, 14 illustrate an example to create a new heap descriptor;

FIGS. 15, 16 illustrate an example to copy from a descriptor and justify;

FIG. 17 illustrates an example to append a descriptor and justify;

FIG. 18 illustrates an example to append part of a descriptor and justify; and

FIG. 19 illustrates an example to append a zero terminator.

DETAILED DESCRIPTION

The present invention will be described in relation to an embodiment known as EPOC32. EPOC32 is a 32 bit operating system developed by Psion Software plc of England for use in (inter alia) mobile and smart phone environments. Further details of the EPOC32 embodiment are disclosed in the SDK on EPOC32 published by Psion Software Plc, England, to the extent possible without limiting in any way the rights of the inventors and assignees of this invention, the full SDK is incorporated by reference into this specification.

EPOC32 has been ported to run on a number of different micro-processor architectures. The details of porting an operating system per se are beyond the scope of this specification, but will be understood by those skilled in the arts. In particular, EPOC32 has been ported to run on ARM RISC-based micro-processors from Advanced RISC Machines of England. Various models of ARM micro-processors are widely used in digital cellular telephones and will be familiar to those skilled in the art. However, the invention can be realised on many different micro-processors. Hence, the claims of this specification should be read to cover any and every hardware and software implementation in which the operating system performs the functions as limited in the claims.

Returning to the examples of Literal Text and Length Limited Text given in the Prior Art discussion above, EPOC32 applies the above three-fold structure for Objects of the String Class as follows:

Example 1: Literal Text in EPOC32

As explained above, in conventional C++, a text string relating to Literal Text is duplicated in memory: once in the original buffer that arises on compilation of the source code and again in the memory location associated with the Object of the String Class that enables the text to be manipulated. That duplication is wasteful.

EPOC32 however uses a Pointer Descriptor which points to the original memory location of the Literal Text (i.e. as laid down by the compiler). This Pointer Descriptor (called the TPtrC Pointer Descriptor in EPOC32) is the Object of the String Class for Literal Text. (In C++, pointers are not usually regarded as Objects per se). Hence, the hybrid pointer/object in EPOC32 leads to the complete elimination of the need for an additional copy of Literal Text.

Example 2: Length Limited Text in EPOC32

As noted above, in conventional C++, there is no mechanism for using anything other than fully flexible, fully featured Objects of the String Class, irrespective of the length of text. That leads to a high overhead in memory management code since handling heap memory is code and cycle intensive.

In EPOC32, there is a particular class of String Objects, known as Buffer Descriptors, which are size limited. Because they are size limited, complex memory allocation code is not required to manipulate them. Further, Buffer Descriptors can use Static Memory (rather than heap memory). Static memory cannot be re-allocated in the code intensive fashion that heap memory can be, but is more efficient to use in that fewer code cycles are required to achieve the necessary manipulations (hence leading to power saving). Only in the truly dynamic case does EPOC32 require use of the heap memory with its attendant high cycle overhead: Then, the Heap Descriptor Class is used.

EPOC32 lays down the parameters of length limited String Classes using a template class, the `TBuf` class. (Class templates define the properties of numerous Objects of the String Class; e.g. TBuf is the template for all Buffer Descriptors--i.e. all Objects of the String Class of the Buffer variant. TBuf defines certain common properties for all such Objects of the String Class.)

EPOC32 exhibits several other significant features which lead to minimising code size and cycle overhead, namely that:

String and Raw Data Buffer Class Objects act as `flat` structures

Descriptors give polymorphic characteristics

Descriptors allow for UNICODE and ASCII invariant coding

String and Raw Data Buffer Class Objects as Flat Structures

All Descriptors are `flat` structures (i.e. if a Descriptor has to be copied, then only the Descriptor itself is copied. In conventional C++, copying an Object requires copying not only of the Object itself, but also all related pointers and the data pointed to--i.e. the complex, related structure that gives an Object meaning.) In EPOC32, copying a Descriptor is therefore far more economic in memory overhead and cycles than copying an equivalent Object in ordinary C++.

This is achieved in EPOC32 as follows, for Buffers and Pointers:

Buffer Descriptors (TBuf) contain the actual text referenced by the Buffer: hence, copying the Buffer inherently copies the related text. There is no need to copy a pointer and related data as there would be in C++.

Pointer Descriptors (TPtr) contain a C++ type pointer within them, so that copying TPtr alone is all that is required when duplicating: in conventional C++, one would have had to copy not just one entity, but also related and separate pointers and text.

Descriptors as Polymorphic Objects

A group of Objects are said to exhibit polymorphism if all the Objects in the Group behave like a single Object, yet achieve common behaviour through different mechanisms. Polymorphism is provided for in conventional C++ through Virtual Functions: all Objects which are polymorphic to one another include, at a common location, a pointer to a Virtual Function Table (a pointer is therefore required in each Object). This Table identifies the actual code for each polymorphic function. A separate Table is needed for each class that shares polymorphism. But this approach uses a considerable amount of space, since each pointer is 32 bits (i.e. 4 characters) and each Object needs a pointer to a Virtual Function Table. In addition, a 32 bit length field is also used in each Object.

In (inter alia) mobile operating system environments, this overhead is problematic. EPOC32 addresses this as follows for Objects of the String Class: a 32 bit length field is sub-divided so that the first 4 bits code for the type of Descriptor. A function then looks at the 4 bits and points to the correct text location (e.g. within the Descriptor itself if the Descriptor is a Buffer etc.) Hence, polymorphism is provided for in that each of the three different classes of Descriptors for Objects of the String Class (i.e. Pointer Descriptors, Buffer Descriptors and Heap Descriptors) can be coded for using merely the first 4 bits of a single 32 bit field. Hence, considerable memory savings can be achieved. In more general terms, the field shares a machine word with another data item.

UNICODE and ASCII Invariant Code

In C++, coding for 16 bit Unicode leads to doubling in size of all text data that would otherwise be in 8 bit code. Also, conventionally, a programmer has to decide when writing source code whether to code for text using ASCII or Unicode.

In EPOC32, the same source code is used irrespective of the ultimate choice of ASCII or Unicode. This is achieved by building the system using aliases for Class Names, which are ASCII and Unicode invariant, rather than Classes per se (e.g. Pointer Descriptors, Buffer Descriptors and Heap Descriptors). Hence, instead of building using the Pointer TPtr16 to code for Unicode or TPtr8 to code for ASCII, one instead builds using the TPtr Class Name. At build time, the Class Names can be compiled as either 16 bit Unicode or 8 bit ASCII. This approach can be used to encompass all character sets which can be encoded in different bit lengths.

Additional Advantages of EPOC32

In C++. text strings are conventionally terminated with a `0` so that the system can readily know where a text string ends. In EPOC32, that is no longer necessary; Descriptors include a statement defining the length of the data referenced. Hence, there is a yet further saving in code since it no longer needs to use `0` terminators to flag the end of each and every text item.

Summary of Descriptors Features

Descriptors come 3 classes: Pointer Descriptors, Buffer Descriptors and Heap Descriptors

Pointer Descriptors come in two forms: constant Pointer Descriptors: TPtrC and modifiable Pointer Descriptors: TPtr

constant Pointer Descriptors: TPtrC.

Data cannot be modified through this.

All member functions are constant.

Is used to reference constant strings or data (e.g. data that must not be altered).

Is derived from TDesC and hence has a large number of member functions.

modifiable Pointer Descriptors: TPtr.

Data can be modified though this Descriptor, so long as the data does not extend beyond the maximum length set by the constructor.

Points directly to a memory area containing the area to be modified.

Pointer length determines number of data items that are contained.

Inherits all the TDesC member functions, plus TDes member functions for manipulating and changing data.

Pointer Descriptors are separate from the data represented; but are constructed from a pre-existing area in memory.

Buffer Descriptors come in two forms

constant Buffer Descriptor, TBufC<TInt S>

data can be set into the Descriptor at construction time or by the assignment operator (operator=) later on.

length is defined by an integer template: TBufC<40> contains 40 data items.

Inherits all the TDesC member functions

a modifiable Buffer Descriptor:, TBuf<TInt S>

contains data that can be modified, so long as the data is not modified to extend beyond the maximum length.

maximum length defines the max. number of data items

actual length defines actual number of data items

length is defined by an integer template: TBuf<40> contains 40 data items and no more.

the data area is part of the Descriptor object

useful for containing data which needs to be manipulated and changed, but whose length will not exceed a known maximum (e.g. WP text).

Inherits all the TDesC member functions, plus TDes member functions for manipulating and changing data.

Heap Descriptors come in one form only

constant Heap Descriptor HBufC

contains a length followed by data

the data area is part of the Descriptor object; the whole object occupies a cell allocated from the heap.

Data can be set into the Descriptor at construction time or by the assignment operator (operator=) later on.

Inherits all the TDesC member functions

can be re-allocated: data area can expand or contract

TPtrC is a constant Descriptor through which no data can be modified. All of its member functions (except the constructors) are constant. TPtrC is shown schematically at FIG. 1. TPtrC is useful for referencing constant strings or data; for example, accessing text built into ROM resident code, or passing a reference to data in RAM which must not be modified through that reference. TPtrC is derived from TDesC, which provides a large number of member functions for operating on its content; for example, locating characters within text or extracting portions of data.

TPtr is a modifiable pointer Descriptor through which data can be modified, provided that the data is not extended beyond the maximum length. The maximum length is set by the constructor. TPtr points directly to an area in memory containing the data to be modified. TPtr is shown schematically in FIGS. 2A and 2B.

TBufC is a buffer Descriptor containing a length followed by the data area. Data can be set into the Descriptor at construction time or by the assignment operator (operator=) at any other time. Data already held by the Descriptor is constant. TBufC is shown schematically at FIG. 3. The length of a TBufC is defined by an integer template; for example, TBufC<40> defines a TBufC which can contain up to 40 data items.

TBufC is derived from TDesC, which provides a large number of member functions for operating on its content; for example, locating characters- within text or extracting portions of data. TBufC provides the member function, Des( ), which creates a modifiable pointer Descriptor (a TPtr) to reference the TBufC. This allows the TBufC data to be changed through the TPtr, as indicated schematically at FIG. 4. The maximum length of the TPtr is the value of the integer template parameter.

TBuf is a modifiable buffer Descriptor containing data which can be modified, provided that the data is not extended beyond its maximum length. TBuf is shown schematically at FIG. 5. The maximum number of data items that the data area within TBuf can contain, is defined by the maximum length. The length of the Descriptor indicates how many data items are currently contained within the data area. When this value is less than the maximum, a portion of the data area is unused. The maximum length of a TBuf is defined by an integer template; for example, TBuf<40> defines a TBuf which can contain up to data items (and no more!). A TBuf is useful for containing data which needs to be manipulated and changed but whose length will not exceed a known maximum; for example, word processor text. TBuf is derived from TDes which, in turn, is derived from TDesC. Therefore, it inherits all the const member functions defined in TDesC plus the member functions from TDes which can manipulate and change the data; for example, appending a character to the end of existing text.

HBufC is a Descriptor containing a length followed by data. It is allocated on the heap using the New( ), NewL( ) or NewLC( ) static member functions. The length of the Descriptor is passed as a parameter to these static functions. HBufC is shown schematically at FIG. 6. Data can be set into the Descriptor at construction time or by the assignment operator (operator=) at any other time. Data already contained by the Descriptor is constant. HBufC is derived from TDesC, which provides a large number of member functions for operating on its content; for example, locating characters within text or extracting portions of data.

HBufC provides the member function, Des( ), which creates a modifiable pointer Descriptor (a TPtr) to reference the HBufC. This allows the HBufCC data to be changed through the TPtr. The maximum length of the TPtr its the length of the HBufC data area. FIG. 7 illustrates this schematically.

All of the Descriptor classes TPtrC, TPtr., TBufC, TBuf and HBufC are derived from the abstract base classes TDesC and TDes. The class TBufCBase, although marked as an abstract class, is merely an implementation convenience. FIG. 8 schematically illustrates the relationship between the classes.

EXAMPLE FUNCTIONS (See Appendix 1 for details and additional functions)

              The code fragments illustrate the use of Left( ).
              . . .
              TBufC<8>str(_L("abcdefg"));
              . . .           // returns a TPtrC descriptor
              str.Left(4);     / representing the sting
              . . . //        "abcd"


The result of this specific example can be visualized in a before (shown in FIG. 9) and after (shown in FIG. 10) fashion. The underlined text in the "after" diagram (FIG. 10) indicates the data represented by the returned descriptor.
              The code fragments illustrate the use of Right( ).
              . . .
              TBufC<8>str(_L("abcdefg"));
              . . .           // returns a TPtrC descriptor
              str.Right(4);      // representing the string
              . . .           // "defg"


The result of this specific example can be visualized in a before (FIG. 11) and after (FIG. 12) fashion. The underlined text in the "after" diagram (FIG. 12) indicates the data represented by the returned descriptor.

The code fragments illustrate the use of AllocL( ).
        . . .
        TBufC<16>str(_L("abcdefg"));
        HBufC*  ptr;
        . . .
        ptr = str.AllocL( );  // Returns address of new HBufC descriptor
        . . .         // holding the string "abcdefg".
        ptr.Length( );    // Returns the length 7
        . . .


The result of this specific example can be visualised in a before (FIG. 13) and after (FIG. 14) fashion.

The following code fragments illustrate the use of Justify( ).

. . .

TBuf<16> tgt(_L("abc"));

. . .

tgt.JustifyLL("xyz"),8,ECenter,`@`);

The descriptor tgt has a maximum length of 16 and initially holds the string "abc". After the call to Justify( ), the content of tgt changes to "@@xyz@@@" as illustrated at FIG. 15.

In this example, the content of the source descriptor is taken to form an 8 character field which replaces the original content of the descriptor tgt. The characters "xyz" are centred within the new field and padded on both sides with the fill character`@`. Setting the alignment to ELeft would change the content of tgt to "xyz@@@@@" while setting the alignment to ERight would change the content of tgt to "@@@@@xyz" In all three cases, the length of the descriptor tgt changes from 3 to 8.

. . .

TBuf<8> tgtLL("abc")); . . .

. . .

tgt.JustifyLL("xyz"),9,ECenter,`@`);

This call to Justify( ) will panic because the resulting length of data in tgt would exceed the maximum length of tgt.

. . .

TBuf<16> tgt(_L("abc"));

. . .

tgt.Justify(_L("rstuvwxyz"),8,ECenter,`@`);

In this call to Justify( ), the content of tgt changes to "rstuvwxy" as illustrated at FIG. 16. Only eight of the nine characters in the source descriptor's data area are copied.

The following code fragments illustrate the use of AppendJustify( ).

. . .

TBuf<16> tgt(_L("abc"));

tgt.AppendJustify(_L("xyz"),8,ECenter,`@`);

The descriptor tgt has a maximum length of 16 and initially holds the string "abc". After the call to AppendJustify( ), the content of tgt changes to "abc@@xyz@@@" as illustrated at FIG. 17.

The following code fragments illustrate the use of AppendJustify( ).

. . .

TBuf<16> tgt(_L("abc"));

tgt.AppendJustify(_L("xyz01234456`,789"),3,8,ECenter,`@`);

The descriptor tgt has a maximum length of 16 and initially holds the string "abc". After the call to AppendJustify( ), the content of tgt changes to "abc@@xyz@@@" as illustrated at FIG. 18.

The following code fragment depited in FIG. 19 illustrates the use of ZeroTerminate( ).

. . .

TBuf<8> tgt(_L("abcde"));

. . .

tgt.ZeroTerminate( )

. . .

The length of the descriptor tgt is 5 both before and after the call to ZeroTerminate( ).

The following code fragments extracted from the E3232def.h header file (see Appendix 1 for the SDK) show how this is implemented by defining the variant independent class names as appropriate.

#if defined(_UNICODE)

. . .

typedef TPtr16 TPtr;

#else

. . .

typedef Ttr8 TPtr;

. . .

#endif

Application code should avoid using `C` style string literals directly. Instead, one should use the _S macro to create a `C` style string of the appropriate width, returning a pointer of the appropriate type. Also, one should use the _L macro (_L for "literal") to create a Descriptor of the appropriate type. See e32.macro._S and e32.macro._L for the definitions of these macros.

For example,

const TText* str=_S("Hello");

generates a string of single byte characters in an ASCII build but a string of double-byte characters in a UNICODE build.

_L("Hello");

generates an 8 bit Descriptor in an ASCII build and a 16 bit Descriptor in a UNICODE build. Always use _L("abcdef"), for example, rather than plain "abcdef" as it will always construct a Descriptor of the correct variant.

Note that an 8 bit `C` style string and an 8 bit pointer Descriptor can be explicitly constructed, independently of the build variant, by using the _S8 and _L8 macros respectively. The corresponding 16 bit versions, _S16 and _L16 are also available. See e32.macro._S8, e32.macro._L8, e32.macro._S16 and e32.macro._L16 for their definitions.

Length and Size

E3232.descriptors.length-and-size

A Descriptor characterizes the data it represents by the length of that data. The length of a Descriptor is the number of data items. For the 8 bit variants, the length of the Descriptor is the number of single-bytes of data it represents; for the 16 bit variants, the length of the Descriptor is the number of double-bytes of data it represents.

The size of a Descriptor is the number of bytes occupied by the Descriptor's data; this is not necessarily the same as the Descriptor's length. For the 8 bit variants, the size is the same as the length but for the 16 bit variants, the size is twice the length. Those Descriptors which allow their data to be modified are also characterized by their maximum length. For these Descriptors, the length of data represented can vary from zero up to and including this maximum value. The maximum length for any Descriptor is 2.sup.28.

Text and Binary Data

E3232.descriptors.text-and-binary

In `C`, strings are characterized by the need for a zero terminator to flag the end of the string. They suffer from a number of problems. In particular, they cannot include binary data within them (in case that data includes binary zeroes) and operations on them are, in general, inefficient. `C` strings need to be handled in a different way to binary data, as reflected in the memxxx( ) and strxxx( ) function groups in the ANSI `C` library. Descriptors allow strings and binary data to be represented in the same way; this allows the same functions to be used in both cases. For binary data, the 8 bit Descriptors should be used explicitly. The distinction between UNICODE and ASCH has no meaning for binary data. Note that there is no practical use for explicit 16 bit binary data.

Memory Allocation

E3232.descriptors.alloc

The Descriptor classes (except HBufC) behave as built-in types. They allocate no memory and have no destructors. This means that they can be orphaned on the stack in the same way as a built-in type. This is particularly important in situations where code can leave. (See E3232.exception.trap.cleanup.requirements for the implications of orphaning). An HBufC Descriptor object is allocated on the heap and cannot be created on the stack.

Exceptions

E3232.descriptors.exceptions

All parameters to Descriptor member functions are checked to ensure that the operations are correctly specified and that no data is written outside the Descriptor's data area. A particular consequence is that no member function can extend a modifiable Descriptor beyond its maximum allocated length. It is the programmer's responsibility to ensure that all Descriptors are sufficiently large to contain their data, either by making the original allocation large enough or by anticipating the need for a larger Descriptor and dynamically allocating one at run-time. The static approach is simpler to implement but if this were to prove wasteful in a specific case, then the dynamic approach could be more worthwhile. In the event of an exception, it can be safely assumed that no illegal access of memory has taken place and that no data has been moved or damaged.

The Descriptor Types

E3232.descriptors.types

There are three kinds of Descriptor object:

pointer Descriptors.

The Descriptor object is separate from the data it represents but is constructed for a pre-existing area in memory. They come in two forms:

a constant pointer Descriptor, TPtrC

a modifiable pointer Descriptor, TPtr

buffer Descriptors.

The data area is part of the Descriptor object. They come in two forms:

a constant buffer Descriptor, TBufC<TInt S>

a modifiable buffer Descriptor, TBuf<TInt S>

heap Descriptor.

The data area is part of the Descriptor object and the whole object occupies a cell allocated from the heap. This comes in only one form:

a constant heap Descriptor, HBufC

Pointer Descriptor--TPtrC

E3232.descriptors.buffer-descriptor.TPtrC

TPtrC is a constant Descriptor through which no data can be modified. All of its member functions (except the constructors) are constant. TPtrC is shown schematically at FIG. 1. TPtrC is useful for referencing constant strings or data; for example, accessing text built into ROM resident code, or passing a reference to data in RAM which must not be modified through that reference. TPtr is derived from TDesC, which provides a large number of member functions for operating on its content; for example, locating characters within text or extracting portions of data.

Pointer Descriptor--TPtr

E3232.descriptors.buffer-descriptor.TPtr

TPtr is a modifiable pointer Descriptor through which data can be modified, provided that the data is not extended beyond the maximum length. The maximum length is set by the constructor. TPtr points directly to an area in memory containing the data to be modified. TPtr is shown schematically in FIGS. 2A and 2B.

The maximum number of data items that the area can contain is defined by the maximum length. The length of the TPtr indicates how many data items are currently contained within the data. When this value is less than the maximum, a portion of the data area is unused. TPtr is useful for constructing a reference to an area of RAM which contains data intended to be modified through that reference, or even to an area of RAM which contains no data yet but in which data will be constructed using the Descriptor reference and member functions.

TPtr is also useful for constructing a reference to a TBufC or an HBufC Descriptor which contain the data to be modified. A TPtr used in this way points to a TBufC or an HBufC Descriptor. The data contained by the TBufC or HBufC Descriptors can be modified through the TPtr. TPtr is derived from TDes which, in turn, is derived from TDesC. Therefore, it inherits all the const member functions defined in TDesC plus the member functions from TDes which can manipulate and change the data; for example, appending a character to the end of existing text.

Buffer Descriptor--TBufC<TInt S>

E3232.descriptors.buffer-descriptor.TBufC

TBufC is a buffer Descriptor containing a length followed by the data area. Data can be set into the Descriptor at construction time or by the assignment operator (operator=) at any other time. Data already held by the Descriptor is constant. TBufC is shown schematically at FIG. 3. The length of a TBufC is defined by an integer template; for example, TBufC<40> defines a TBufC which can contain up to 40 data items.

TBufC is derived from TDesC, which provides a large number of member functions for operating on its content; for example, locating characters within text or extracting portions of data. TBufC provides the member function, Des( ), which creates a modifiable pointer Descriptor (a TPtr) to reference the TBufC. This allows the TBufC data to be changed through the TPtr, as indicated schematically at FIG. 4. The maximum length of the TPtr is the value of the integer template parameter.

Buffer Descriptor--TBuf<TInt S>

E3232.descriptors.buffer-descriptor.TBuf

TBuf is a modifiable buffer Descriptor containing data which can be modified, provided that the data is not extended beyond its maximum length. TBuf is shown schematically at FIG. 5. The maximum number of data items that the data area within TBuf can contain, is defined by the maximum length. The length of the Descriptor indicates how many data items are currently contained within the data area. When this value is less than the maximum, a portion of the data area is unused. The maximum length of a TBuf is defined by an integer template; for example, TBuf<40> defines a TBuf which can contain up to 40 data items (and no more!). A TBuf is useful for containing data which needs to be manipulated and changed but whose length will not exceed a known maximum; for example, word processor text. TBuf is derived from TDes which, in turn, is derived from TDesC. Therefore, it inherits all the const member functions defined in TDesC plus the member functions from TDes which can manipulate and change the data; for example, appending a character to the end of existing text.

Heap Descriptor--HBufC

E3232.descriptors.buffer-descriptor.HBufC

HBufC is a Descriptor containing a length followed by data It is allocated on the heap using the New( ), NewL( ) or NewLC( ) static member functions. The length of the Descriptor is passed as a parameter to these static functions. HBufC is shown schematically at FIG. 6. Data can be set into the Descriptor at construction time or by the assignment operator (operator=) at any other time. Data already contained by the Descriptor is constant. HBufC is derived from TDesC, which provides a large number of member functions for operating on its content; for example, locating characters within text or extracting portions of data.

HBufC provides the member function, Des( ), which creates a modifiable pointer Descriptor (a TPtr) to reference the HBufC. This allows the HBufC data to be changed through the TPtr. The maximum length of the TPtr is the length of the HBufC data area. FIG. 7 illustrates this schematically. Heap Descriptors can be re-allocated. The ReAlloc( ) or ReAllocL( ) functions allow the heap Descriptor's data area to expand or contract. The length of the data area, however, cannot be made smaller than the length of data currently held. Before contracting the data area, the length of the data held by the Descriptor must be reduced. The length of data which the assignment operator can set into the heap Descriptor is limited by the space allocated to the Descriptor's data area The memory occupied by heap Descriptors must be explicitly freed either by calling User::Free( ) or by using the delete keyword.

The Descriptor Classes' Relationships

E32.descriptors.classes

All of the Descriptor classes TPtrC, TPtr, TBufC, TBuf and HBufC are derived from the abstract base classes TDesC and TDes. The class TBufCBase, although marked as an abstract class, is merely an implementation convenience. FIG. 8 schematically illustrates the relationship between the classes.

The behaviour of the concrete Descriptor classes is very similar, and therefore, most of the functionality of Descriptors is provided by the abstract base classes. Because Descriptors are widely used (especially on the stack), the size of Descriptor objects must be kept to a minimum. To help with this, no virtual functions are defined in order to avoid the overhead of a virtual function table pointer in each Descriptor object. As a consequence, the base classes have implicit knowledge of the classes derived from them. E32 supplies two variants of the Descriptor classes, one for handling 8 bit (ASCII) text and binary data and the other for handling 16 bit (UNICODE) text. The 8 bit variants of the concrete classes are: TPtrC8, TPtr8, TBufC8<TInt S>, TBuf8<TInt S> and HBufC8 while the 8 bit variants of the abstract classes are: TDesC8, TDes8. Similarly, the 16 bit variants are named: TPtrC, TPtr16, TBufC16<TInt S>, TBuf16<TInt S>, HBufC16, TDesC16 and TDes16 respectively. This distinction is transparent for Descriptors intended to represent text. By writing programs which construct and use TPtrC, TPtr, TBufC<TInt S>, TBuf<TInt S> and HBufC classes, compatibility is maintained between both UNICODE and ASCII. The appropriate variant is selected at build time depending on whether the _UNICODE macro has been defined or not. If the _UNICODE macro is defined, the 16 bit variant is used, otherwise the 8 bit variant is used as explained in e32descriptors.char-set

Descriptors for binary data must explicitly use the 8 bit variants; in other words, code must explicitly construct TPtrC8, TPtr8, TBufC8<TInt S>, TBuf8<TInt S> and HBufC8 classes. Explicit use of the 16 bit variants for binary data is possible but not recommended. In general, 8 bit and 16 bit variants are identical in structure and implementation; the description of the classes themselves uses the build independent names throughout.

N.B. Many member functions take arguments which are either of type TUint8* or type TUint16* depending on whether the Descriptor is the 8 bit or 16 bit variant. To simplify explanation, these arguments are written in function prototypes as TUint??*.

Using Descriptors for Function Interfaces

e32.descriptors.using-function-interfaces

Many interfaces which use or manipulate text strings or general binary data use descriptors to specify the interface. In conventional `C` programming, interfaces would be specified using a combination of char*, void* and length values. In E32 descriptors are always used.

There are four main cases:

Passing a constant string

In `C`: StringRead(const char* aString);

The length of the string is implied by the zero terminator; therefore, the function does not require the length to be explicitly specified.

In E32: StringRead(const TDesC& aString);

The descriptor contains both the string and its length.

Passing a string which can be changed.

In `C`: StringWrite(char* aString, int aMaxLength);

The length of the passed string is implied by the zero terminator. aMaxLength indicates the maximum length to which the string may be extended.

In E32: StringWrite(TDes& aString);

The descriptor contains the string, its length and the maximum length to which the string may be extended.

Passing a buffer containing general binary data

In `C`: BufferRead(const void* aBuffer, int aLength);

Both the address and length of the buffer must be specified.

In E32: BufferRead(const TDes8& aBuffer);

The descriptor contains both the address and the length of the data. The 8 bit variant is explicitly specified; the buffer is treated as byte data, regardless of the build variant.

Passing a buffer containing general binary data which can be changed.

In `C`:

BufferWrite(void* aBuffer, int& aLength, int aMaxLength);

The address of the buffer, the current length of the data and the maximum length of the buffer are specified. The aLength parameter is specified as a reference to allow the function to indicate the length of the data on return.

In E32: BufferRead(TDes8& aBuffer);

The descriptor contains the address, the length of the data and the maximum length. The 8 bit variant is explicitly specified; the buffer is treated as byte data, regardless of the build variant.

Folding and Collating

e32.descriptors.folding-collating

There are two techniques that may be used to modify the characters in a descriptor prior to performing some operations on text:

folding

collating

Variants of member functions that fold or collate are provided where appropriate.

Folding

e32.descriptors.folding

Folding means the removal of differences between characters that are deemed unimportant for the purposes of inexact or case-insensitive matching. As well as ignoring differences of case, folding ignores any accent on a character. By convention, folding converts lower case characters into upper case and removes any accent.

Collating

e32.descriptors.collating

Collating means the removal of differences between characters that are deemed unimportant for the purposes of ordering characters into their collating sequence. For example, collate two strings if they are to be arranged in properly sorted order, this may be different from a strict alphabetic order.

Using Descriptors

e32.descriptors.using

The following series of examples show how descriptors can be used. Specifically, the examples illustrate:

the basic concepts of the pointer descriptors, TPtrC and TPtr. See e32.descriptors.using.pointer-descriptors.

the basic concepts of the buffer descriptors, TBufC and TBuf. See e32.descriptors.using.buffer-descriptors.

how descriptors can represent general binary data. See e32.descriptors.using.general-binary-data.

some of the member functions which do not modify the content of a descriptor. See e32.descriptors.using.non-modifying-functions.

some of the member functions which modify the content of a descriptor. See e32.descriptors.using.modifying-functions.

how descriptors can be used in interfaces. See e32.descritpors.using.interface-specifiers.

the basic concepts of the heap descriptor, HBufC. See e32.descritpors.using.heap-descriptors.

Pointer Descriptors

e32.descriptors.using.pointer-descriptors

The code fragments shown here to illustrate the use of pointer descriptors are extracted from the sample source code in the eudesptr project. Run the code in this project to see pointer descriptors in action.

TPtrC

The 8 bit variant

A TPtrC is useful for referencing constant strings or data; for example, accessing text built into ROM resident code, or passing a reference to data in RAM which must not be modified through that reference.

For example, define a constant `C` style ASCII string:

const TText8* cstr8=(TText8*)"Hello World!";

A TPtrC8 descriptor can be constructed to represent this pre-defined area containing the string "Hello World!":

TPtrC8 ptrC8(cstr8);

The descriptor is separate from the data it represents.

While the length of the `C` string is 12, its size is 13 to allow for the zero terminator. From the descriptor's viewpoint, both the length and the size of the data is 12. The descriptor uses the length to determine the amount of data represented. The address of the descriptor's data area, as returned by:

ptrC8.Ptr( );

is the same as same as the address of the original `C` string, cstr8.

The 16 bit variant (UNICODE)

Similarly, define a constant `C` style string of wide (or UNICODE) characters:

const TText16 cstr16=(TText16)L"Hello World!";

A TPtrC descriptor can be constructed to represent this area containing the string of double-byte characters "Hello World!":

TPtrC ptrC(cstr16);

Again, the descriptor is separate from the data it represents. The length of the descriptor, as returned by a call to ptrc16.Length( ), is 12 as it represents 12 text characters but the size, as returned by a call to ptrc16.Size( ), is now 24 as each character occupies 2 bytes. Again, the address of the descriptor's data area, as returned by:

ptrc16.Ptr( );

is the same as the address of the original `C` string, cstr16.

The _S macro and build independent names

Use the _S macro to define a constant `C` style string of the appropriate width. The TText variant is defined at build time (as either TText8 or TText16) depending on whether the _UNICODE macro has been defined. For example:

const TText* cstr=_S("Hello World!");

The TPtrC descriptor:

TPtrC ptrc(cstr);

represents the area containing the text "Hello World!"; the TPtrC variant is defined at build time (as either TPtrC8 or TPtr16) depending on whether the _UNICODE macro has been defined.

The length of the descriptor, as returned by ptrc.Length( ), is 12 for all build variants but the size of the descriptor, as returned by ptrc.Size( ) is 12 for an ASCII build and 24 for a UNICODE build.

See e32.macro._S.

The _L macro

The _L macro constructs a TPtrC of the correct variant and is frequently used as a source descriptor when constructing a buffer descriptor or a heap descriptor.

The macro is also useful for constructing a TPtrC to be passed as a parameter to a function. For example, the Printf( ) member function of the RTest class used in these examples requires a descriptor as its first parameter. Here, the _L macro constructs a TPtrC representing the constant static area generated by the compiler containing the text ".backslash.nThe _L macro constructs a TPtrC".

testConsole.Printf(_L(".backslash.n The _L macro constructs a TPtrC"));

See e32.macro._L.

TPtr

A TPtr is a modifiable pointer descriptor through which data can be modified, provided that the data is not extended beyond the maximum length. The maximum length is set by the constructor.

For example, define a TText area initialised to contain the string "Have a nice day": ##EQU1##

A TPtr descriptor can be constructed to represent the data in this area; further, this data can be changed, contracted and expanded provided that the length of the data does not exceed the maximum.

TPtr ptr(&str[0],15,16);

The descriptor ptr represents the data in str and is constructed to have a current length of 15 (the length of the text, excluding the zero terminator) and a maximum length of 16 (the actual length of str). Once the descriptor has been constructed, it has no farther use for the zero terminator.

The data can be completely replaced using the assignment operator:

ptr=_L("Hi there");

Note the use of the _L macro to construct a TPtrC of the correct build variant as the source of the assignment.

The length of ptr is now 8 but the maximum length remains 16. The size depends on the build variant. In an ASCII build, this is 8 but in a UNICODE build, this becomes 16 (two bytes for every character).

The length of the data represented can be changed. For example, after ptr.SetLength(2), the descriptor represents the text "Hi". The length can even be set to zero so that after ptr.Zero( ), the descriptor represents no data. Nevertheless, the maximum length remains at 16 so that:

ptr=_L("Have a nice day!"); puts the 16 characters "Have a nice day" into the descriptor's data area.

See also e32.macro._L.

Buffer Descriptors

e32.descriptors.using.buffer-descriptors

The code fragments shown here to illustrate the use of buffer descriptors are extracted from the sample source code in the eudesbuf project. Run the code in this project to see buffer descriptors in action.

TBufC

A TBufC is a buffer descriptor where the data area is part of the descriptor itself.

Data can be set into the descriptor at construction time or by the assignment operator at any other time. Data already held by the descriptor cannot be modified but it can be completely replaced (again, using the assignment operator).

For example:

TBufC<16> bufc2(_L("Hello World!"));

constructs a TBufC which can contain up to 16 data items. During construction, the descriptor's data area is set to contain the text "Hello World!" and the length of the descriptor is set to 12.

The data within bufc2 cannot be modified but it can be replaced using the assignment operator:

bufc2=_L("Replacement text");

To prevent any possibility of replacing the data, declare bufc2 as const.

The data within a TBufC can be changed by constructing a TPtr from the TBufC using the Des( ) member function; the data can then be changed through the TPtr. The maximum length of the TPtr is the value of the TBufC template parameter. For example:

bufc2=_L("Hello World!");

TPtr ptr=bufc2.Des( );

ptr.Delete((ptr.Length( )-1),1);

ptr.Append(_L("& Hi"));

This deletes the last character in the TBufC and adds the characters "& Hi" so that the TBufC now contains the text "Hello World & Hi" and its length is 16. Note that the length of both the TBufC and the TPtr reflect the changed data.

TBuf

A TBuf is a modifiable buffer descriptor where the data area is part of the descriptor itself. The data can be modified provided that the data is not extended beyond the maximum length. The maximum length is set by the constructor.

For example:

TBuf<16> buf(_L("Hello World!"));

constructs a TBuf which can contain up to 16 data items. During construction, the descriptor's data area is set to contain the text "Hello World!", the length of the descriptor is set to 12 and its maximum length is set to 16.

The data can be modified directly:

buf.Append(`@`);

changes buf's data to "Hello World!@" and its length to 13 while:

buf.SetLength(3);

changes it length to 3 and its data to "Hel".

The maximum length of the descriptor always remains at 16.

Like a TBufC descriptor, the data contained within a TBuf can be replaced entirely using the assignment operator:

buf=_L("Replacement text");

replaces "Hello World" with "Replacement text" and changes the length of the descriptor to 16.

An attempt to increase the length of the data beyond the maximum generates an exception (a panic). For example:

buf=_L("Text replacement causes panic!");

generates a panic at run time because the length of the replacement text (30) is greater than the maximum (16).

General Binary Data

e32.descriptors.using.general-binary-data

The code fragments shown here, illustrating how descriptors can handle, general binary data, are extracted from the sample source code in the eudesbin project. Run the code in this project to see the sample in action.

The kind of data represented or contained by descriptors is not restricted to text. Descriptors can also handle general binary data.

To deal with general binary data, always explicitly construct an 8 bit variant descriptor. Binary data should always be treated as 8 bit data regardless of the build.

For example set up an area in memory initialised with binary data:

TUint8 data[6]={0x00,0x01,0x02,0xAD,0xAE,0xAF};

Construct a modifiable buffer descriptor using the default constructor:

TBuf8<32> buffer;

The following code extracted from the eudesbin project puts the binary data into the descriptor, appends a number of single byte values and then displays the data at the test console. The length of the buffer is 9, the maximum length is 32 and the size is 9 regardless of the build.
            TInt index;
            TInt counter;
            buffer.Append(&data[0],sizeof(data));
            buffer.Append(0xFD);
            buffer.Append(0xFE);
            buffer.Append(0xFF);
            counter = buffer.Length( );
            for (index = 0; index < counter; index++)
                testConsole.Printf(_L("0x%02x"),buffer[index]);
            testConsole.Printf(_L("; Length( )=%d;.backslash.n"),
                                 buffer.Length( )
                               );
            testConsole.Printf(_L("Size( )=%d; MaxLength( )=%d.backslash.n"),
                                 buffer.Size( ),
                                 buffer.MaxLength( )
                               );
        Text and general binary data can be freely mixed; so that:
            buffer.Append(`A`);
            buffer.Append(`B`);
            buffer.Append(0x11);
        is acceptable.


Non-modifying Functions

e32.descriptors.using.non-modifying-functions

The code fragments shown here, illustrating some of the non-modifying descriptor member functions, are extracted from the sample source code in the eudesc project. Look at the code in this project to see the full set of examples

These examples all use a TBufC descriptor constructed to contain the text "Hello World!". Note also that the descriptor is declared const so that its data cannot be replaced using the assignment operator:

const TBufC<16> bufc(_L("Hello World!"));

Right( ) & Mid( )

These functions construct a TPtrc to represent a portion of bufc's data

TPtrC ptrc1=bufc.Right(5); ptrc1 represents the right hand 5 data items in bufc. ptrc1's data is "orld!", its length is 5 and the address of its data area is the address of bufc's data area plus 7.

The Left( ) member function works in a similar way.

TPtrC ptrc2=bufc.Mid(3,6);

ptrc2 represents the 6 data items offset 3 from the start of bufc's data area ptrc2's data is "lo Wor", its length is 6 and the address of its data area is the address of bufc's data area plus 3.

In practice, it may not be necessary to assign the returned TPtrC to another TPtrC. For example, the following code puts a value of 3 in pos; this is the offset of char `W` within the chars "lo Wor" (see later for an explicit example of Locate( ))

TInt pos;

. . .

pos=(bufc.Mid(3,6)).Locate(`W`);

These functions can panic. For example, requesting the 13 right hand data items in bufc will cause an exception (there are only 12):

TPtrC ptrc3=bufc.Right(13);

Compare( ) & CompareF( )

The compare functions can be used to compare the content of two descriptors. Any kind of data can be compared. For binary data, use Compare( ). For text use Compare( ), CompareF( ) or CompareC( ).

The following example compares the content of bufc with the content of a number of descriptors and displays the results at the test console:
        . . .
        TInt index;
        . . .
        TPtrC   genptr;
        const TBufC<19>lessthan(_L(" is less than  "));
        const TBufC<19>greaterthan(_L(" is greater than "));
        const TBufC<19>equalto(_L(" is equal to  "));
        . . .
        const TBufC<16>compstr[7] = {_L("Hello World!@@"),
                                   _L("Hello"),
                                   _L("Hello Worl"),
                                   _L("Hello World!"),
                                   _L("hello world!"),
                                   _L("Hello World"),
                                   _L("Hello World@"),
                                   };
        for (index = 0; index < 7; index++)
            {
            if( (bufc.Compare(compstr[index])) < 0)
                genptr.Set(lessthan);
            else if( (bufc.Compare(compstr[index])) > 0)
                  genptr.Set(greaterthan);
                else genptr.Set(equalto);
     testConsole.
     Printf(_L(".backslash."%S.backslash."%S.backslash."%S.backslash.".backslas
    h.n"),
                                   &bufc,
                                   &genptr,
                                   &compstr[index]
                                   );
            }


The case of text is important using Compare( ); the fourth comparison is equal but the fifth comparison is not (the `w` characters are a different case).

Using CompareF( ), the case is not important; both the fourth and fifth comparisons return an equal result.

Locate( ), LocateF( ) & LocateReverse( )

The locate functions can be used to find the position (offset) of a character within text or a specific value within general binary data.

The following example attempts to find the positions (i.e. the offsets) of the characters `H`, `!`, `o` and `w` within the text "Hello World!" and displays the result at the test console:
    . . .
    TInt index;
    TInt pos;
    TPtrC genptr;
    const TBufC<9> notfound(_L("NOT FOUND")),
    const TBufC<5> found(_L("found"));
    . . .
    TChar ch[4] = {`H`, `!`, `o`, `w`};
    . . .
    testConsole.Printf(_L("using Locate( ).backslash.n"));
    for (index = 0 ; index < 4; index++)
        {
        pos = bufc.Locate(ch[index]);
        if (pos < 0)
          genptr.Set(notfound);
        else
          genptr.Set(found);
        testConsole.Printf(_L(".backslash."%S.backslash." Char %c is at pos %d
     (%S).backslash.n"),
                             &bufc,
                             ch[index],
                             pos,
                             &genptr
                             );
        }


The character `w` is not found using Locate( ) but is found using LocateF( ). This is because Locate( ) is case sensitive while LocateF( ).

This example uses LocateReverse( ) which is used to find the position of a character starting from the end of the descriptor's data area
    . . .
    testConsole.Printf(_L("using LocateReverse( ).backslash.n"));
    for (index = 0 ; index < 4; index++)
        {
        pos = bufc.LocateReverse(ch[index]);
        if(pos < 0)
          genptr.Set(notfound);
        else
          genptr.Set(found);
        testConsole.Printf(_L(".backslash."%S.backslash." Char %c is at pos %d
     (%S).backslash.n"),
                             &bufc,
                             ch[index],
                             pos,
                             &genptr
                           );
        }


Note that the 2nd char `o` in the string "Hello World!" is found this time.

Match( ) & MatchF( )

The following example shows the use of the Match( ) and MatchF( ) member functions. The result of a matches between the content of buf and a series of descriptors with varying combinations of match strings is displayed at the test console.
            . . .
            TInt index;
            TInt pos;
            TPtrC genptr;
            const TBufC<9> notfound(_L("NOT FOUND"));
            const TBufC<5> found(_L("found"));
            . . .
            TBufC<8>matchstr[7] = {_L("*World*"),
                                 _L("*W?rld*"),
                                 _L("*Wor*"),
                                 _L("Hello"),
                                 _L("*W*"),
                                 _L("hello"),
                                 _L("*"),
                                 };
            for (index = 0 ; index < 7; index++)
              {
              pos = bufc.Match(matchstr[index]);
              if(pos < 0)
                genptr.Set(notfound);
              else
                genptr.Set(found);
              testConsole.Printf(_L("%- 8S pos %2d (%S).backslash.n"),
                                 &matchstr[index],
                                 pos,
                                 &genptr
                               ):
              }


Note that when using MatchF( ), the result is different when matching the 6th string where the case is ignored.

Modifying Functions

e32.descriptors.using.modifying-functions

The code fragments shown here, illustrating some of the modifying descriptor member functions, are extracted from the sample source code in the eudes project. Look at the code in this project to see the full set of examples.

These examples all use a TBuf descriptor constructed to contain the text "Hello World!".

TBuf<32> buf(_L("Hello World!"));

Swap( )

The contents, length and size of altbuf1 and buf are swapped; the maximum lengths of the descriptors do NOT change.

TBuf<16> altbuf1(_L("What a nice day"));

. . .

buf.Swap(altbuf1);

Repeat( )

The current length of buf is set to 16. Repeat copying the characters "Hello" generates the text sequence "HelloHelloHelloH" in buf.

buf.SetLength(16);

buf.Repeat(_L("Hello"));

Setting the length of buf to and re-doing the repeat generates the text sequence "HelloHel".

Justify( )

The example uses src as the source descriptor.

TBufVC<40> src(_"Hello World!"));

. . .

buf.Justify(src,16,ELeft,`@`);

The descriptor src has length 12.

The target field in buf has width 16 (this is greater than the length of the descriptor src). src is copied into the target field, aligned left and padded with `@` characters. The length of buf becomes the same as the specified width, i.e 16.

buf.Justify(src,16,ECenter,`@`);

The target field in buf has width 16 (this is greater than the length of the descriptor src). src is copied into target field, aligned centrally and padded with `@` characters. The length of buf becomes the same as the specified width, i.e 16

buf.Justify(src,10,ECenter,`@`);

The target field in buf has width 10 (this is smaller than the length of the descriptor src). src is copied into the target field but truncated to 10 characters and, therefore, alignment and padding information is not used. The length of buf becomes the same as the width, i.e. 10

buf.Justify(src,KDefaultJustifyWidth,ECenter,`@`);

The target field in buf is set to the length of the descriptor src (whatever it currently is). src is copied into the target field. No padding and no truncation is needed and so the alignment and padding information is not used. The length of buf becomes the same as the length of src, i.e. 12.

Descriptors as Interface Specifiers

e32.descriptors.using.interface-specifiers

See the eudesint project for examples illustrating the use of descriptors in function interfaces.

Heap Descriptors

e32.descriptors.using.heap-descriptors

The code fragments shown here, illustrating the use of heap descriptors, are extracted from the sample source code in the eudeshbc project. Look at the code in this project to see the the sample in action.

An HBufC is always constructed on the heap using the static member functions New( ), NewL( ) or NewLC( ). For example:

HBufC* buf;

. . .

buf=HBufC::NewL(15);

This constructs an HBufC which can hold up to 15 data items. The current length is zero. Although existing data within an HBufC cannot be modified, the assignment operator can be used to replace that data For example:

*buf=_L("Hello World!");

To allow more than 15 characters or data items to be assigned into the HBufC, it must be reallocated first. For example:

buf=buf-> ReAllocL(20);

This permits the following assignment to be done without causing a panic:

*buf=_L("Hello World! Morning");

buf may or may not point to a different location in the heap after relocation. The location of the reallocated descriptor depends on the heap fragmentation and the size of the new cell.

The Des( ) function returns a TPtr to the HBufC. The data in the HBufC can be modified through the TPtr. The maximum length of the TPtr is determined from the size of the cell allocated to the data area of the HBufC. For example:

TPtr ptr=buf-> Des( );

. . .

ptr.Delete((ptr.Length( )-9),9);

ptr.Append(_L("& Hi"));

This changes the data in the HBufC and the length of the HBufC.

TPtrC Class Constant Pointer Descriptor

Overview

Derivation

TDesC Abstract: implements descriptor behaviour which does not modify data.

TPtrC A constant pointer descriptor.

Defined in

e32des8.h for the 8 bit variant (TPtr8).

e32des16.h for the 16bit variant (TPtr16).

Description

Create a TPtrC descriptor to access a pre-existing location in either ROM or RAM where the data at that location is to be accessed but not changed (or where the data cannot be changed).

A common use for a TPtrC is to access a string of text in a code segment. This will normally be constructed using the _L macro which constructs a TPtrC descriptor for either an ASCII or UNICODE build.

Often, a TPtrC will appear as the right hand side of an expression or as an initialisation value for another descriptor, for example:

TBuf<16> str(_L"abcdefghijklmnop"));

. . .

str.Find(_L"abc");

str.Find(_L"bcde");

The _L macro expands to a TPtrC which is defined as either a TPtr8 or TPtrC16 depending on the build variant (TBuf is also defined in a similar way).

The 8 bit variant, TPtrC8 can be constructed to access binary data The 8 bit variant is always explicitly used for binary data.

Five constructors are available to build a TPtr and include a default constructor. A TPtrC can be (re-)initialised after construction by using the set( ) functions.

All the member functions described under the TDesC class are available for use by a TPtrc descriptor. In summary these are:
    Length( )            Fetch length of descriptor data.
    Size( )              Fetch the number of bytes occupied by
                         descriptor data.
    Ptr( )               Return a pointer to the descriptor data.
    Compare( ),          Compare data (normally), (folded), (collated).
    CompareF( ),
    CompareC( )
    Match( ),            Pattern match data (normally), (folded),
    MatchF( ), MatchC( ) (collated).
    Locate( ), LocateF( ) Locate a character in forwards direction
                         (normally), (folded).
    LocateReverse( ),    Locate a character in reverse direction
    LocateReverseF( )    (normally), (folded).
    Find( ), FindF( ), FindC Find data (normally), (folded), (collated).
    Left( )              Construct TPtrC for leftmost part of data.
    Right( )             Construct TPtrC for rightmost part of data.
    Mid( )               Construct TPtrC for portion of data.
    Alloc( ),            Construct an HBufC for this descriptor.
    AllocL( ), AllocLC( )
    HufEncode( )         Huffman encode
    HufDecode( )         Huffman decode
    operators < <= > >= == Comparison operators
    operator [ ]         Indexing operator


Construction

e32.descriptors.TPtrC.construction

TPtrC( ) Default C++ constructor

Description

The default C++ constructor is used to construct a constant pointer descriptor.

The length of the constructed descriptor is set to zero and its pointer is set to NULL.

Notes

Use the Set( ) member function to initialise the pointer descriptor.

TPtrC( ) Copy constructor

TPtrC(const TPtrC& aDes);

Description

The C++ copy constructor constructs a new TPtrC object from the existing one.

The length of the constructed descriptor is set to the length of aDes and is set to point to aDes's. data.

TPtrC( ) C++ constructor [with any descriptor]

TPtrC(const TDesC& aDes);

Description

The C++ constructor is used to construct the TPtrC with any kind of descriptor.

The length of the constructed descriptor is set to the length of aDes, and it is set to point to aDes's data.

Arguments

const TDesC& aDes A reference to any type of descriptor used to construct the TPtrC.

Notes

If aDes is a reference to a heap descriptor (HBufC), then the data also resides on the heap.

TPtrC( ) C++ constructor [with zero terminated string]

TPtrC(const TText* aString);

Description

The C++ constructor is used to construct the TPtrC object with a zero terminated string.

The length of the descriptor is set to the length of the zero terminated string, excluding the zero terminator.

The constructed descriptor is set to point to the location of the string, whether in RAM or ROM.

Arguments

const TText* aString A pointer to the zero terminated used to construct the TPtrC.

TPtrC( )C++ constructor [with address and length]

TPtrC(const TUint??* aBuf,TInt aLength);

Description

The C++ constructor is used to construct the TPtrC with the memory address and length.

The length of the constructed descriptor is set to the value of aLength.

The constructed descriptor is set to point to the memory address supplied in aBuf; the address can refer to RAM or ROM.

Arguments

const TUint??* aBuf The address which is to be the data area of the constant pointer descriptor.

For the 8 bit variant, this is type TUint8*; for the 16 bit variant, this is type TUint16*.

TInt aLength The length of the constructed constant pointer descriptor.

This value must be non-negative otherwise the constructor will panic with ETDes8LengthNegative for the 8 bit variant or ETDes16LengthNegative for the 16 bit variant.

Late Initialisation

e32.descriptors.TPtrC.late-initialisation

Set( ) Initialisation taking any descriptor

void Set(const TDesC& aDes);

Description

Use this function to initialise (or re-initialise) a constant pointer descriptor using the content of any kind of descriptor.

The length of this constant pointer descriptor is set to the length of aDes.

This descriptor is set (or re-set) to point to aDes's data

Arguments

const TDesC& aDes A reference to any descriptor whose content is to be used to initialise this constant pointer descriptor.

Notes

The Set( ) function can be used to initialise a constant pointer descriptor constructed using the default constructor.

If aDes is a reference to a heap descriptor (HBufC), then the data also resides on the heap.

Set( ) Initialisation taking address and length

void Set(const TUint??* aBuf,TInt aLength);

Use this function to initialise (or re-initialise) a constant pointer descriptor using the supplied memory address and length.

The length of this constant pointer descriptor is set to the value of aLength.

The descriptor is set to point to the memory address supplied in aBuf; the address can refer to RAM or ROM.

Arguments

const TUint??* aBuf The address which is to be the data area of the constant pointer descriptor.

For the 8 bit variant, this is type TUint8*; for the 16 bit variant, this is type TUint16*.

TInt aLength The length of the constant pointer descriptor.

This value must be non-negative otherwise the constructor will panic with ETDes8LengthNegative for the 8 bit variant or ETDes16LengthNegative for the 16 bit variant.

Notes

The Set( ) function can be used to initialise a constant pointer descriptor constructed using the default constructor.

TPtr Class Modifiable Pointer Descriptor

Overview

Derivation

TDesC Abstract: implements descriptor behaviour which does not modify data.

TDes Abstract: implements descriptor behaviour which can change data.

TPtr A modifiable pointer descriptor.

Defined in

e32des8.h for the 8 bit variant (TPtr8).

e32des16.h for the 16 bit variant (TPtr16).

Description

Create a TPtr descriptor to access a pre-existing area or buffer in RAM where the contents of that buffer are to be accessed and manipulated.

A common use for a TPtr is to access the buffer of an existing TBufC or an HBufC descriptor using the Des( ) member functions (of TBufC and HBufC). For example:

TBufC<8> str(_L("abc"));

str.Des( ).Append(`x`);

TPtr is defined as either a TPtr8 or TPtr16 depending on the build variant and can be used to access text.

The 8 bit variant, TPtr8 can be constructed to access binary data. The 8 bit variant is always explicitly used for binary data

Two constructors are available to build a TPtr and include a default constructor. A TPtr can be (re-)initialised after construction by using the set( ) functions.

All the member functions described under the TDesC and TDes classes are available for use by a TPtr descriptor. In summary these are:
    Length( )            Fetch length of descriptor data.
    Size( )              Fetch the number of bytes occupied by
                         descriptor data.
    Ptr( )               Fetch address of descriptor data.
    Compare( ),          Compare data (normally), (folded), (collated).
    CompareF( ),
    CompareC( )
    Match( ),            Pattern match data (normally), (folded),
    MatchF( ), MatchC( ) (collated).
    Locate( ), LocateF( ) Locate a character in forwards direction
                         (normally), (folded).
    LocateReverse( ),    Locate a character in reverse direction
    LocateReverseF( )    (normally), (folded).
    Find( ), FindF( ), FindC Find data (normally), (folded), (collated).
    Left( )              Construct TPtrC for leftmost part of data.
    Right( )             Construct TPtrC for rightmost part of data.
    Mid( )               Construct TPtrC for portion of data.
    Alloc( ),            Construct an HBufC for this descriptor.
    AllocL( ), AllocLC( )
    HufEncode( )         Huffman encode
    HufDecode( )         Huffman decode
    MaxLength( )         Fetch maximum length of descriptor.
    MaxSize( )           Fetch maximum size of descriptor
    SetLength( )         Set length of descriptor data
    Zero( )              Set length of descriptor data to zero
    SetMax( )            Set length of descriptor data to the
                         maximum value.
    Swap( )              Swap data between two descriptors.
    Copy( ),             Copy data (normally), (and fold), (and collate).
    CopyF( ), CopyC( )
    CopyLC( )            Copy data and convert to lower case.
    CopyUC( )            Copy data and convert to upper case
    CopyCP( )            Copy data and capitalise
    Repeat( )            Copy and repeat.
    Justify( )           Copy and justify.
    Insert( )            Insert data.
    Delete( )            Delete data.
    Replace( )           Replace data.
    TrimLeft( )          Delete spaces from left side of data area.
    TrimRight( )         Delete spaces from right side of data area.
    Trim( )              Delete spaces from both left and right side of
                         data area.
    Fold( )              Fold characters.
    Collate( )           Collate characters.
    LowerCase( )         Convert to lower case.
    UpperCase( )         Convert to upper case.
    Capitalise( )        Capitalise.
    Fill( )              Fill with specified character.
    FillZ( )             Fill with 0x00.
    Num( )               Convert numerics to character (hex.digits to
                         lower case).
    NumUC( )             Convert numerics to (upper case) character.
    Format( ),           Convert multiple arguments to character
    FormatList( )        according to format specification.
    Append( )            Append data.
    AppendFill( )        Append with fill characters.
    AppendJustify( )     Append data and justify
    AppendNum( )         Append from converted numerics.
    AppendNumUC( )       Append from converted numerics; convert to
                         upper case.
    AppendFormat( ),     Append from converted multiple arguments.
    AppendFormatList( )
    ZeroTerminate( )     Append zero terminator.
    PtrZ( )              Append zero terminator and return a pointer.
    operators < <= > >= == Comparison operators.
    operator +=          Appending operator.
    operator [ ]         Indexing operator.


Construction

e32.descriptors.TPtr.construction

TPtr( ) C++ constructor [with address and maximum length]

TPtr(TUint??* aBuf,TInt aMaxLength);

Description

The C++ constructor is used to construct the TPtr with the address and maximum length.

The length of the constructed descriptor is set to zero and its maximum length is set to aMaxLength.

The constructed descriptor is set to point to the memory address supplied in aBuf which can refer either to RAM or ROM.

Arguments

TUint??* aBuf The address which is to be the data area of the modifiable pointer descriptor.

For the 8 bit variant, this is type TUint8*; for the 16 bit variant, this is type TUint16*.

TInt aMaxLength The maximum length of the new modifiable pointer descriptor.

This value must be non-negative otherwise the constructor will panic with ETDes8MaxLengthNegative for the 8 bit variant or ETDes16MaxLengthNegative for the 16 bit variant.

TPtr( ) C++ constructor [with address, length and maximum length]

TPtr(TUint??* aBuf,TInt aLength,TInt aMaxLength);

Description

The C++ constructor is used to construct the TPtr with the address, length and maximum length.

Use this to construct a modifiable pointer descriptor using the supplied memory address, length and maximum length to initialise it.

The length of the constructed descriptor is set to aLength and its maximum length is set to aMaxLength.

The constructed descriptor is set to point to the memory address supplied in aBuf which can refer either to RAM or ROM.

Arguments

TUint??* aBuf The address which is to be the data area of the modifiable pointer descriptor.

For the 8 bit variant, this is type TUint8*; for the 16 bit variant, this is type TUint16*.

TInt aLength The length of the new modifiable pointer descriptor.

This value must be non-negative and not greater than the value of aMaxLength otherwise the constructor will panic with ETDes8LengthOutOfRange for the 8 bit variant or ETDes8LengthOutOfRange for 16 bit variant.

TInt aMaxLength The maximum length of the new modifiable pointer descriptor.

This value must be non-negative otherwise the constructor will panic with ETDes8MaxLengthNegative for the 8 bit variant or ETDes16MaxLengthNegative for 16 bit variant.

Late Initialisation

e32.descriptors.TPtr.late-initialisation

Set( ) Initialisation by copying a TPtr

void Set(TPtr& apt);

Use this function to initialise (or re-initialise) a modifiable pointer descriptor using the content of another modifiable pointer descriptor. The function behaves as a copy constructor.

The length of the descriptor is set to the length of aPtr and its maximum length is set to the maximum length of aPtr.

The descriptor is set (or re-set) to point to aPtr's data.

Arguments

TPtr& aPtr A reference to a modifiable pointer descriptor whose content is to be used to initialise this modifiable pointer descriptor.

Set( ) Initialisation taking address, length and maximum length

void Set(TUint??* aBuf,TInt aLength,TInt aMaxLength);

Use this function to initialise (or re-initialise) a modifiable pointer descriptor using the supplied memory address, length and maximum length.

The length of the resulting descriptor is set to the value of aLength and its maximum length is set to the value of aMaxLength.

The descriptor is set (or re-set) to point to the memory address supplied in aBuf; the address can refer to RAM or ROM.

Arguments

TUint??* aBuf The address which is to be the data area of the modifiable pointer descriptor.

For the 8 bit variant, this is type TUint8*; for the 16 bit variant, this is type TUint16*.

TInt aLength The length of the modifiable pointer descriptor.

This value must be non-negative and not greater than the value of aMaxLength otherwise the constructor will panic with ETDes8LengthOutOfRange for the 8 bit variant or ETDes16LengthOutOfRange for the 16 bit variant

TInt aMaxLength The maximum length of the modifiable pointer descriptor. This value must be non-negative otherwise the constructor will panic with ETDes8MaxLengthNegative for the 8 bit variant or ETDes16MaxLengthNegative for the 16 bit variant

Assignment Operators

e32.descriptors.TPtr.assignment-operators

See also e32.descriptors.TDes.assignment-operators.

operator= Operator=taking a TPtr

TPtr& operator=(const TPtr& aDes);

Description

This assignment operator copies a modifiable pointer descriptor to this modifiable pointer descriptor.

aDes's data is copied into this descriptor's data area, replacing the existing content. The length of this descriptor is set to the length of aDes.

Arguments

const TPtr& aDes A reference to the modifiable pointer descriptor whose data is to be copied.

Return value

TPtr& A reference to this descriptor.

Notes

The length of aDes must not be greater than the maximum length of this descriptor otherwise the operation will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

operator= Operator=taking any descriptor

TPtr& operator=(const TDesC& aDes);

Description

This assignment operator copies the content of any type of descriptor, aDes, to this modifiable pointer descriptor.

aDes's data is copied into this descriptor's data area, replacing the existing content. The length of this descriptor is set to the length of aDes.

Arguments

const TDesC& aDes A reference to any type of descriptor whose data is to be copied.

Return value

TPtr& A reference to this descriptor.

Notes

The length of aDes must not be greater than the maximum length of this descriptor otherwise the operation will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

operator= Operator=taking a zero terminated string

TPtr& operator=(const TText aString);

Description

This assignment operator copies a zero terminated string, excluding the zero terminator, into this modifiable pointer descriptor.

The copied string replaces the existing content of this descriptor.

The length of this descriptor is set to the length of the string (excluding the zero terminator).

Arguments

const TText* aString The address of the zero terminated string to be copied.

Return value

TPtr& A reference to this descriptor.

Notes

The length of the string, excluding the zero terminator, must not be greater than the maximum length of this descriptor otherwise the operation will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant.

TBufC<TInt S> Class Constant Buffer Descriptor

Overview

Derivation

TDesC Abstract: implements descriptor behaviour which does not modify data.

TBufCBase Abstract: implementation convenience.

TBufC<TInt S> A constant buffer descriptor.

Defined in

e32des8.h for the 8 bit variant (TBufC8<TInt S>).

e32des16.h for the 16 bit variant (TBufC16<TInt S>)

Description

Create a TBufC descriptor to provide a buffer of fixed length for containing and accessing constant data.

The data held in a TBufC descriptor cannot be modified, although it can be replaced.

Four constructors are available to build a TBufC descriptor and include a default constructor. The content of TBufC descriptor can be replaced after construction using the assignment operators.

For example, to create a buffer of length 16 set to contain the characters "ABC"

TBufC<16> str(_L("ABC"));

The content cannot be modified but may be replaced, for example:

str=_L("xyz"),

To create a buffer which is intended to contain general binary data, explicitly construct the 8 bit variant of TBufC; for example, to create a 256 byte buffer:

TBufC8<256> buf;

. . .

buf= . . . ;

All the member functions described under the TDesC class are available for use by a TBufC descriptor. In summary these are:
    Length( )            Fetch length of descriptor data.
    Size( )              Fetch the number of bytes occupied by
                         descriptor data.
    Ptr( )               Fetch address of descriptor data.
    Compare( ),          Compare data (normally), (folded), (collated).
    CompareF( ),
    CompareC( )
    Match( ),            Pattern match data (normally), (folded),
    MatchF( ), MatchC( ) (collated).
    Locate( ), LocateF( ) Locate a character in forwards direction
                         (normally), (folded).
    LocateReverse( ),    Locate a character in reverse direction
    LocateReverseF( )    (normally), (folded).
    Find( ),             Find data (normally), (folded), (collated).
    FindF( ), FindC
    Left( )              Construct TPtrC for leftmost part of data.
    Right( )             Construct TPtrC for rightmost part of data.
    Mid( )               Construct TPtrC for portion of data.
    Alloc( ),            Construct an HBufC for this descriptor.
    AllocL( ), AllocLC( )
    HufEncode( )         Huffman encode
    HufDecode( )         Huffman decode
    operators < <= > >= == Comparison operators
    operator [ ]         Indexing operator


Construction

e32.descriptors.TBufC.construction

TBufC( ) Default C++ constructor

TfBufC( );

Description

The default C++ constructor is used construct a non-modifiable buffer descriptor.

The integer template parameter<TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the descriptor object.

The length of the constructed descriptor is set to zero.

Notes

Use the assignment operators to initialise the non-modifiable buffer descriptor.

TBufC( ) Copy constructor

TBuf(const TBufC<S>& aLcb);

Description

The C++ copy constructor constructs a new TBufC<S> object from the existing one.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor.

aLcb's data is copied into the constructed descriptor's data area.

The length of the constructed descriptor is set to the length of aLcb.

TBufC( ) C++ constructor [with any descriptor]

TBufC(const TDesC& aDes);

Description

The C++ constructor is used to construct the TBufC<S> with any kind of descriptor.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor.

aDes's data is copied into the constructed descriptor's data area.

The length of the constructed descriptor is set to the length of aDes.

Arguments

const TDesC& aDes A reference to any type of descriptor used to construct the TBufC<S>.

Notes

The length of aDes must not be greater than the value of the integer template parameter <TInt S> otherwise the constructor will panic with ETDes8LengthOutOfRange for the 8 bit variant or ETDes16LengthOutOfRange for the 16 bit variant.

TBufC( ) C++ constructor[with zero terminated string]

TBufC(const TText* aString);

Description

The C++ constructor is used to construct the TBufC<S> with a zero terminated string.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor object.

The string, excluding the zero terminator, is copied into the constructed descriptor's data area.

The length of the constructed descriptor is set to the length of the string, excluding the zero terminator.

Arguments

const TText* aString The address of the zero terminated string used to construct the TBufC<S>.

Notes

The length of the string, excluding the zero terminator, must not be greater than the value of the integer template parameter <TInt S> otherwise the constructor will panic with ETDes8LengthOutOfRange for the 8 bit variant or ETDes16LengthOutOfRange for the 16 bit variant.

Create a Modifiable Pointer Descriptor

e32.descriptors.TBufC.create-TPtr

Des( ) Create & return a TPtr

TPtr Des( );

Description

Use this function to construct and return a modifiable pointer descriptor to represent this descriptor.

The content of a non-modifiable buffer descriptor cannot be altered but creating a modifiable pointer descriptor provides a mechanism for modifying that data.

The length of the new TPtr is set to the length of this descriptor.

The maximum length of the new TPtr is set to the value of the integer template parameter <TInt S>.

The new TPtr is set to point to this descriptor. This descriptor's data is neither copied nor moved.

This descriptor's data can be modified through the newly constructed TPtr. If there is any change to the length of the data, then the length of both this descriptor and the TPtr is modified to reflect that change.

Return value

TPtr A modifiable pointer descriptor representing this non-modifiable buffer descriptor.

Assignment Operators

e32.descriptors.TBufC.assignment-operators

See also e32.descriptors.TDes.assignment-operators.

operator= Operator=taking a TBufC<S>

TBufC<S>& operator=(const TBufC<S>& aLcb);

Description

This assignment operator copies the content of the non-modifiable buffer descriptor aLcb into this non-modifiable buffer descriptor.

aLcb's data is copied into this descriptor's data area, replacing the existing content. The length of this descriptor is set to the length of aLcb.

Arguments

const TBufC<S>& aLcb A reference to a non-modifiable buffer descriptor whose content is to be copied.

Return value

TBufC<S>& A reference to this descriptor.

operator= Operator=taking any descriptor

TBufC<S>& operator=(const TDesC& aDes);

Description

This assignment operator copies the content of any type of descriptor aDes into this non-modifiable buffer descriptor. aDes's data is copied into this descriptor's data area, replacing the existing content. The length of this descriptor is set to the length of aDes.

Arguments

const TDesc& aDes A reference to any type of descriptor whose data is to be copied.

Return value

TBufC<S>& A reference to this descriptor.

Notes

The length of aDes must not be greater than the value of the integer template parameter <TInt S> otherwise the operation will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

operator=Operator=taking zero terminated string

TBufC<S>& operator=(const TText* aString);

Description

This assignment operator copies a zero terminated string, excluding the zero terminator, into this non-modifiable buffer descriptor.

The copied string replaces the existing content of this descriptor. The length of this descriptor is set to the length of the string, excluding the zero terminator.

Arguments

const TText* aString The address of the zero terminated string to be copied.

Return value

TBufC<S>& A reference to this descriptor.

Notes

The length of the string, excluding the zero terminator, must not be greater than the value of the template parameter <TInt S> otherwise the operation will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

TBuf<TInt S> Class Modifiable Buffer Descriptor

Overview

Derivation

TDesC Abstract: implements descriptor behaviour which does not modify data.

TDes Abstract: implements descriptor behaviour which can change data.

A modifiable buffer descriptor.

TBuf<TInt S>

Defined In

e32des8.h for the 8 bit variant (TBuf<TInt S>).

e32des16.h for the 16 bit variant (TBuf<TInt S>).

Description

Create a TBuf descriptor to provide a buffer of fixed length for containing, accessing and manipulating data.

Five constructors are available to build a TBuf descriptor and include a default constructor.

The content of a TBuf descriptor can be replaced after construction using the assignment operators.

For example, to create a buffer of length 8 initially set to contain the characters "ABC"

TBuf<8> str(_L("ABC"));

The content of the buffer descriptor can be replaced provided the length of the new data does not exceed the value of the integer template parameter, for example:

str=_L("xyz"); //OK

str=_L("rstuvwxyz"); //causes an exception

To create a buffer which is intended to contain general binary data, explicitly construct the 8 bit variant TBuf8, for example, to create a 256 byte buffer:

TBuf8<256> buf;

. . .

buf= . . . ;

All the member functions described under the TDesC and TDes classes are available for use by a TBuf descriptor. In summary these are:
    Length( )            Fetch length of descriptor data.
    Size( )              Fetch the number of bytes occupied by
                         descriptor data.
    Ptr( )               Fetch address of descriptor data.
    Compare( ),          Compare data (normally), (folded), (collated).
    CompareF( ),
    CompareC( )
    Match( ),            Pattern match data (normally), (folded),
    MatchF( ), MatchC( ) (collated).
    Locate( ), LocateF( ) Locate a character in forwards direction
                         (normally), (folded).
    LocateReverse( ),    Locate a character in reverse direction
    LocateReverseF( )    (normally), (folded).
    Find( ),             Find data (normally), (folded), (collated).
    FindF( ), FindC
    Left( )              Construct TPtrC for leftmost part of data.
    Right( )             Construct TPtrC for rightmost part of data.
    Mid( )               Construct TPtrC for portion of data.
    Alloc( ),            Construct an HBufC for this descriptor.
    AllocL( ), AllocLC( )
    HufEncode( )         Huffman encode
    HufDecode( )         Huffman decode
    MaxLength( )         Fetch maximum length of descriptor.
    MaxSize( )           Fetch maximum size of descriptor
    SetLength( )         Set length of descriptor data
    Zero( )              Set length of descriptor data to zero
    SetMax( )            Set length of descriptor data to the
                         maximum value.
    Swap( )              Swap data between two descriptors.
    Copy( ),             Copy data (normally), (and fold), (and collate).
    CopyF( ), CopyC( )
    CopyLC( )            Copy data and convert to lower case.
    CopyUC( )            Copy data and convert to upper case
    CopyCP( )            Copy data and capitalise
    Repeat( )            Copy and repeat.
    Justify( )           Copy and justify.
    Insert( )            Insert data.
    Delete( )            Delete data.
    Replace( )           Replace data.
    TrimLeft( )          Delete spaces from left side of data area.
    TrimRight( )         Delete spaces from right side of data area.
    Trim( )              Delete spaces from both left and right side of
                         data area.
    Fold( )              Fold characters.
    Collate( )           Collate characters.
    LowerCase( )         Convert to lower case.
    UpperCase( )         Convert to upper case.
    Capitalise( )        Capitalise.
    Fill( )              Fill with specified character.
    FillZ( )             Fill with 0x00.
    Num( )               Convert numerics to character (hex digits to
                         lower case).
    NumUC( )             Convert numerics to (upper case) character.
    Format( ),           Convert multiple arguments to character
    FormatList( )        according to format specification.
    Append( )            Append data.
    AppendFill( )        Append with fill characters.
    AppendJustify( )     Append data and justify
    AppendNum( )         Append from converted numerics (hex digits
                         to lower case).
    AppendNumUC( )       Append from converted numerics; convert
                         to uppercase.
    AppendFormat( ),     Append from converted multiple arguments.
    AppendFormatList( )
    ZeroTerminate( )     Append zero terminator.
    PtrZ( )              Append zero terminator and return a pointer.
    operators < <= > >= == Comparison operators.
    operator +=          Appending operator.
    operator [ ]         Indexing operator.


Construction

e32.descriptors.TBuf.construction

TBuf( ) Default C++ constructor

TBuf( );

Description

The default C++ constructor is used to construct a modifiable buffer descriptor.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor.

The length of the constructed descriptor is set to zero and the maximum length is set to the value of the integer template parameter <TInt S>.

TBuf( ) C++ constructor[with length]

TBuf(TInt aLength);

Description

The C++ constructor is used to construct the TBuf<S> with the length.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor.

The length of the constructed descriptor is set to aLength and the maximum length is set to the value of the integer template parameter <TInt S>.

Arguments

TInt aLength The length of the constructed modifiable buffer descriptor.

This value must be non-negative and not greater than the value of the integer template parameter <1Int S> otherwise the constructor will panic with ETDes8LengthOutOfRange for the 8 bit variant or ETDes16LengthOutOfRange for the 16 bit variant

TBuf( ) Copy constructor

TBuf(const TBuf<S>& aBuf);

Description

The C++ copy constructor constructs a new TBuf<S> object from the existing one.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor object.

aBuf's data is copied into the constructed descriptor's data area.

The length of the constructed descriptor is set to the length of aBuf and the maximum length is set to the value of the integer template parameter <TInt S>.

TBuf( ) C++ constructor [with any descriptor]

TBuf(const TDesC& aDes);

Description

The C++ constructor is used to construct the TBuf<S> with any kind of descriptor.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor.

aDes's data is copied into the constructed descriptor's data area.

The length of the constructed descriptor is set to the length of aDes and the maximum length is set to the value of the integer template parameter <TInt S>.

Arguments

const TDesC& aDes A reference to any type of descriptor used to construct the TBuf<S>.

Notes

The length of aDes must not be greater than the value of the integer template parameter <TInt S> otherwise the constructor will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

TBuf( ) C++ constructor [with zero terminated string]

TBuf(const TText aString);

Description

The Cup constructor is used to construct the TBuf<S> with a zero terminated string.

The integer template parameter <TInt S> is used, by the compiler, to calculate the size of the data area to be created as part of the constructed descriptor.

The string, excluding the zero terminator, is copied into the constructed descriptor's data area.

The length of the constructed descriptor is set to the length of the string, excluding the zero terminator, and the maximum length is set to the value of the integer template parameter <TInt S>.

Arguments

const Text* aString The address of the zero terminated string used to construct the TBuf<S>.

Notes

The length of the string, excluding the zero terminator must not be greater than the value of the integer template parameter <TInt S> otherwise the constructor will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

Assignment Operators

e32.descriptors.TBuf.assignment-operators

See also e32.descriptors.TDes.assignment-operators.

operator= Operator=taking a TBuf<S>

TBuf<S>& operator=(const TBuf<S>& aBuf);

Description

This assignment operator copies the content of the modifiable buffer descriptor aBuf into this modifiable buffer descriptor.

aBuf's data is copied into this descriptor's data area, replacing the existing content. The length of this descriptor is set to the length of aBuf.

Arguments

const TBuf<S>& aBuf A reference to the modifiable pointer descriptor whose content is to be copied.

Return value

TBuf<S>& A reference to this descriptor.

Operator= Operator=taking any descriptor

TBuf<S>& operator=(const TDesC& aDes);

Description

This assignment operator copies the content of any type of descriptor aDes into this modifiable buffer descriptor.

aDes's data is copied into this descriptor's data area, replacing the existing content. The length of this descriptor is set to the length of aDes.

Arguments

const TDesc& aDes A reference to any type of descriptor whose content is to be copied.

Return value

TBuf<S>& A reference to this descriptor.

Notes

The length of aDes must not be greater than the value of the integer template parameter <TInt S> otherwise the operation will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

operator= Operator=taking a zero terminated string

TBuf<S>& operator=(const TText* aString);

Description

This assignment operator copies a zero terminated string, excluding the zero terminator, into this modifiable buffer descriptor.

The copied string replaces the existing content of this descriptor.

The length of this descriptor is set to the length of the string, excluding the zero terminator.

Arguments

const TText* aString The address of the zero terminated string to be copied.

Return value

TBuf<S>& A reference to this descriptor.

Notes

The length of the string, excluding the zero terminator, must not be greater than the value of the template parameter <TInt S> otherwise the operation will panic with ETDes8Overflow for the 8 bit variant or ETDes16Overflow for the 16 bit variant

HBufC Class Heap Descriptor

Overview

Derivation

TDesC Abstract: implements descriptor behaviour which does not modify data.

TBufCBase Abstract: implementation convenience.

HBufC A heap descriptor.

Defined in

e32des8.h for the 8 bit variant (HBufC8).

e32des16.h for the 16 bit variant (HBufC)

Description

Create an HBufC descriptor to provide a buffer of fixed length for containing and accessing data.

The data held in an HBufC descriptor cannot be modified, although it can be replaced using the assignment operators.

The descriptor exists only on the heap but has the important property that it can be resized, i.e. made either larger or smaller, to change the size of its data area. This is achieved by reallocating the descriptor. Unlike the behaviour of dynamic buffers (see e32.dynamic-buffers) reallocation is not done automatically.

An HBufC descriptor is useful in situations where a large fixed length buffer may be required initially but, thereafter, a smaller fixed length buffer is sufficient.

An HBufC descriptor must be constructed using the static member functions New( ), NewL( ) or NewLC( ) and resized using the ReAlloc( ) or ReAllocL( ) member functions. A code fragment illustrates bow these might be used:
            class CAnyClass: CBase
                {
            public:
                void AddToBuf(const TDesC& aSrcBuf);
            private:
                HBufC* iTgtBuf;
                TInt iAllocLen;
                }
            void CAnyClass::AddToBuf(const TDesC& aSrcBuf)
                {
                TInt SrcLen = aSrcBuf.Length( );
                if(iTgtBuf)
                    {
                    if (SrcLen > iAllocLen)
                       {
                       iTgtBuf = iTgtBuf->ReAllocL(SrcLen);
                       iAllocLen = SrcLen;
                       }
                    }
                else
                    {
                    iTgtBuf = HBufC::NewL(SrcLen);
                    iAllocLen = SrcLen;
                    }
                *iTgtBuf = aSrcBuf;
                }


In practice, the use of ReAlloc( ) here is a little inefficient as the data in the HBufC descriptor is saved across the re-allocation but is then discarded when the content of aSrcBuf is assigned to it.

All the member functions described under the TDesC class are available for use by a TBufC descriptor. In summary these are:
    Length( )            Fetch length of descriptor data.
    Size( )              Fetch the number of bytes occupied by
                         descriptor data.
    Ptr( )               Fetch address of descriptor data.
    Compare( ),          Compare data (normally), (folded), (collated).
    CompareF( ),
    CompareC( )
    Match( ),            Pattern match data (normally), (folded),
    MatchF( ), MatchC( ) (collated).
    Locate( ), LocateF( ) Locate a character in forwards direction
                         (normally), (folded).
    LocateReverse( ),    Locate a character in reverse direction
    LocateReverseF( )    (normally), (folded).
    Find( ), FindF( ), FindC Find data (normally), (folded), (collated).
    Left( )              Construct TPtrC for leftmost part of data.
    Right( )             Construct TPtrC for rightmost part of data.
    Mid( )               Construct TPtrC for portion of data.
    Alloc( ),            Construct an HBufC for this descriptor.
    AllocL( ), AllocLC( )
    HufEncode( )         Huffman encode
    HufDecode( )         Huffman decode
    operators < <= > >= == Comparison operators
    operator [ ]         Indexing operator


Allocation and Construction

e32.descriptors.HBufC.allocation-and-construction

New( ), NewL( ), NewLC( ) Create new HBufC

e32.descriptors.new

static HBufC* New(TInt aMaxLength);

static HBufC* NewL(TInt aMaxLength);

static HBufC* NewLC(TInt aMaxLength);

Description

Use these functions to construct a new HBufC descriptor on the heap.

The functions attempt to acquire a single cell large enough to hold an HBufC object containing a data area with a length which is at least aMaxLength. The resulting length of the data a