Software Patent: Object oriented operating system
Table of contents:
Bibliography
|
Title |
|
|
Title - german |
|
|
Title - french |
|
|
Granted. Opposition window closed |
|
|
WO1998GB01717 19980612; GB19970012455 19970613 |
|
|
AT, BE, CH, DE, DK, ES, FR, GB, GR, IE, IT, LI, LU, MC, NL, PT, SE, FI |
|
|
|
|
|
EP922250-A3, WO9857258-A3, EP922250-B1, US6836879-B1, WO9857258-A2 |
|
|
ep922250 |
|
|
EP19980928464 19980612 |
Abstract
||<#ffd0d0>[[patent( 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. )]] ||
Description
[[patent( Description of corresponding document: <strong>US6836879</strong><br/> <br/> <br/> BACKGROUND<br/> [0002] 1. Field of the Invention<br/> [0003] 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.<br/> [0004] 2. Description of the Related Art<br/> [0005] 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.<br/> [0006] 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).<br/> [0007] 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.<br/> [0008] 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.<br/> Some Terminology<br/> "Objects of the String Class"<br/> [0011] 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.<br/> [0012] 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: <br/>
set aside a buffer location in memory <br/> read the text into the buffer using a file reading service <br/> use a string creation service to turn the buffered data into an Object of the String Class <br/> discard the buffer contents<br/> [0017] 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.<br/> Multiple Classes of Objects of the String Class<br/> [0019] 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.<br/> [0020] Two examples of conventional C++ memory management illustrate this:<br/> Example 1: C++ Handling of Literal Text<br/> [0022] 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.<br/> [0023] 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.<br/> Example 2: C++ Handling of Length Limited Text<br/> [0025] 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.<br/> [0026] 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.<br/> <br/> SUMMARY<br/> [0027] 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.<br/> [0028] 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.<br/> [0029] 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.<br/> [0030] 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.<br/> [0031] 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; <br/>
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.<br/> [0033] 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.<br/> [0034] 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.<br/> [0035] 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).<br/> [0036] Preferably, the operating system is adapted to handle not only text but also raw data using the same three fold structure.<br/> [0037] 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.<br/> [0038] 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; <br/>
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.<br/> [0040] 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; <br/>
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.<br/> [0042] 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; <br/>
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.<br/> [0044] In a fifth aspect, there is provided computer readable media encoded with an operating system adapted to handle objects related to text strings; <br/>
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.<br/> <br/> BRIEF DESCRIPTION OF THE DRAWINGS<br/> [0046] FIG. 1 is an illustration of a constant pointer descriptor;<br/> [0047] FIG. 2A is an illustration of a modifiable pointer descriptor pointing to an area in at memory;<br/> [0048] FIG. 2B is an illustration of a modifiable pointer descriptor pointing to another descriptor;<br/> [0049] FIG. 3 is an illustration of a constant buffer descriptor;<br/> [0050] FIG. 4 is an illustration of a modifiable pointer descriptor pointing to a constant buffer descriptor;<br/> [0051] FIG. 5 is an illustration of a modifiable buffer descriptor;<br/> [0052] FIG. 6 is an illustration of a constant heap descriptor;<br/> [0053] FIG. 7 is an illustration of a modifiable pointer descriptor pointing to an allocated constant heap descriptor;<br/> [0054] FIG. 8 is an illustration of the member functions available to members of the various descriptor classes;<br/> [0055] FIGS. 9, 10 illustrate an example to construct a pointer descriptor for leftmost part of data;<br/> [0056] FIGS. 11, 12 illustrate an example to construct a pointer descriptor for rightmost part of data;<br/> [0057] FIGS. 13, 14 illustrate an example to create a new heap descriptor;<br/> [0058] FIGS. 15, 16 illustrate an example to copy from a descriptor and justify;<br/> [0059] FIG. 17 illustrates an example to append a descriptor and justify;<br/> [0060] FIG. 18 illustrates an example to append part of a descriptor and justify; and<br/> [0061] FIG. 19 illustrates an example to append a zero terminator.<br/> <br/> DETAILED DESCRIPTION<br/> [0062] 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.<br/> [0063] 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.<br/> [0064] 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:<br/> Example 1: Literal Text in EPOC32<br/> [0066] 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.<br/> [0067] 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.<br/> Example 2: Length Limited Text in EPOC32<br/> [0069] 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.<br/> [0070] 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.<br/> [0071] 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.)<br/> [0072] EPOC32 exhibits several other significant features which lead to minimising code size and cycle overhead, namely that: <br/>
String and Raw Data Buffer Class Objects act as 'flat' structures <br/> Descriptors give polymorphic characteristics <br/> Descriptors allow for UNICODE and ASCII invariant codingString and Raw Data Buffer Class Objects as Flat Structures<br/> [0077] 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++.<br/> [0078] This is achieved in EPOC32 as follows, for Buffers and Pointers: <br/>
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++. <br/> 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<br/> [0082] 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.<br/> [0083] 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.<br/> UNICODE and ASCII Invariant Code<br/> [0085] 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.<br/> [0086] 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.<br/> Additional Advantages of EPOC32<br/> [0088] 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.<br/> Summary of Descriptors Features<br/>
Descriptors come 3 classes: Pointer Descriptors, Buffer Descriptors and Heap Descriptors <br/> Pointer Descriptors come in two forms: constant Pointer Descriptors: TPtrC and modifiable Pointer Descriptors: TPtr <br/> constant Pointer Descriptors: TPtrC. <br/> Data cannot be modified through this. <br/> All member functions are constant. <br/> Is used to reference constant strings or data (e.g. data that must not be altered). <br/> Is derived from TDesC and hence has a large number of member functions. <br/> modifiable Pointer Descriptors: TPtr. <br/> Data can be modified though this Descriptor, so long as the data does not extend beyond the maximum length set by the constructor. <br/> Points directly to a memory area containing the area to be modified. <br/> Pointer length determines number of data items that are contained. <br/> Inherits all the TDesC member functions, plus TDes member functions for manipulating and changing data. <br/> Pointer Descriptors are separate from the data represented; but are constructed from a pre-existing area in memory. <br/> Buffer Descriptors come in two forms <br/> constant Buffer Descriptor, TBufC<TInt S> <br/> data can be set into the Descriptor at construction time or by the assignment operator (operator=) later on. <br/> length is defined by an integer template: TBufC<40> contains 40 data items. <br/> Inherits all the TDesC member functions <br/> a modifiable Buffer Descriptor:, TBuf<TInt S> <br/> contains data that can be modified, so long as the data is not modified to extend beyond the maximum length. <br/> maximum length defines the max. number of data items <br/> actual length defines actual number of data items <br/> length is defined by an integer template: TBuf<40> contains 40 data items and no more. <br/> the data area is part of the Descriptor object <br/> useful for containing data which needs to be manipulated and changed, but whose length will not exceed a known maximum (e.g. WP text). <br/> Inherits all the TDesC member functions, plus TDes member functions for manipulating and changing data. <br/> Heap Descriptors come in one form only <br/> constant Heap Descriptor HBufC <br/> contains a length followed by data <br/> the data area is part of the Descriptor object; the whole object occupies a cell allocated from the heap. <br/> Data can be set into the Descriptor at construction time or by the assignment operator (operator=) later on. <br/> Inherits all the TDesC member functions <br/> can be re-allocated: data area can expand or contract<br/> [0123] 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.<br/> [0124] 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.<br/> [0125] 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.<br/> [0126] 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.<br/> [0127] 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.<br/> [0128] 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.<br/> [0129] 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.<br/> [0130] 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.<br/> EXAMPLE FUNCTIONS (See Appendix 1 for details and additional functions)<br/> <tb><sep>The code fragments illustrate the use of Left( ).<br/> <tb><sep>. . .<br/> <tb><sep>TBufC<8>str(_L("abcdefg"));<br/> <tb><sep>. . .<sep>// returns a TPtrC descriptor<br/> <tb><sep>str.Left(4);<sep> / representing the sting<br/> <tb><sep>. . . //<sep>"abcd"<br/> [0132] 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.<br/> <tb><sep>The code fragments illustrate the use of Right( ).<br/> <tb><sep>. . .<br/> <tb><sep>TBufC<8>str(_L("abcdefg"));<br/> <tb><sep>. . .<sep>// returns a TPtrC descriptor<br/> <tb><sep>str.Right(4);<sep> // representing the string<br/> <tb><sep>. . .<sep>// "defg"<br/> [0133] 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.<br/> [0134] The code fragments illustrate the use of AllocL( ).<br/> <tb><sep>. . .<br/> <tb><sep>TBufC<16>str(_L("abcdefg"));<br/> <tb><sep>HBufC* ptr;<br/> <tb><sep>. . .<br/> <tb><sep>ptr = str.AllocL( );<sep> // Returns address of new HBufC descriptor<br/> <tb><sep>. . .<sep>// holding the string "abcdefg".<br/> <tb><sep>ptr.Length( );<sep>// Returns the length 7<br/> <tb><sep>. . .<br/> [0135] The result of this specific example can be visualised in a before (FIG. 13) and after (FIG. 14) fashion.<br/> [0136] The following code fragments illustrate the use of Justify( ). <br/>
. . . <br/> TBuf<16> tgt(_L("abc")); <br/> . . . <br/> tgt.JustifyLL("xyz"),8,ECenter,'@');<br/> [0141] 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.<br/> [0142] 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. <br/>
. . . <br/> TBuf<8> tgtLL("abc")); . . . <br/> . . . <br/> tgt.JustifyLL("xyz"),9,ECenter,'@');<br/> [0147] This call to Justify( ) will panic because the resulting length of data in tgt would exceed the maximum length of tgt. <br/>
. . . <br/> TBuf<16> tgt(_L("abc")); <br/> . . . <br/> tgt.Justify(_L("rstuvwxyz"),8,ECenter,'@');<br/> [0152] 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.<br/> [0153] The following code fragments illustrate the use of AppendJustify( ). <br/>
. . . <br/> TBuf<16> tgt(_L("abc")); <br/> tgt.AppendJustify(_L("xyz"),8,ECenter,'@');<br/> [0157] 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.<br/> [0158] The following code fragments illustrate the use of AppendJustify( ). <br/>
. . . <br/> TBuf<16> tgt(_L("abc")); <br/> tgt.AppendJustify(_L("xyz01234456',789"),3,8,ECenter,'@');<br/> [0162] 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.<br/> [0163] The following code fragment depited in FIG. 19 illustrates the use of ZeroTerminate( ). <br/>
. . . <br/> TBuf<8> tgt(_L("abcde")); <br/> . . . <br/> tgt.ZeroTerminate( ) <br/> . . .<br/> [0169] The length of the descriptor tgt is 5 both before and after the call to ZeroTerminate( ).<br/> [0170] 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. <br/>
#if defined(_UNICODE) <br/> . . . <br/> typedef TPtr16 TPtr; <br/> #else <br/> . . . <br/> typedef Ttr8 TPtr; <br/> . . . <br/> #endif<br/> [0179] 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.<br/> For example,<br/>
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. <br/> _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.<br/> [0185] 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.<br/> Length and Size<br/> [0187] E3232.descriptors.length-and-size<br/> [0188] 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.<br/> [0189] 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<28> .<br/> Text and Binary Data<br/> [0191] E3232.descriptors.text-and-binary<br/> [0192] 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.<br/> Memory Allocation<br/> [0194] E3232.descriptors.alloc<br/> [0195] 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.<br/> Exceptions<br/> [0197] E3232.descriptors.exceptions<br/> [0198] 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.<br/> The Descriptor Types<br/> [0200] E3232.descriptors.types<br/> [0201] There are three kinds of Descriptor object: <br/>
pointer Descriptors. <br/> 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: <br/> a constant pointer Descriptor, TPtrC <br/> a modifiable pointer Descriptor, TPtr <br/> buffer Descriptors. <br/> The data area is part of the Descriptor object. They come in two forms: <br/> a constant buffer Descriptor, TBufC<TInt S> <br/> a modifiable buffer Descriptor, TBuf<TInt S> <br/> heap Descriptor. <br/> 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: <br/> a constant heap Descriptor, HBufCPointer Descriptor-TPtrC<br/> [0214] E3232.descriptors.buffer-descriptor.TPtrC<br/> [0215] 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.<br/> Pointer Descriptor-TPtr<br/> [0217] E3232.descriptors.buffer-descriptor.TPtr<br/> [0218] 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.<br/> [0219] 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.<br/> [0220] 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.<br/> Buffer Descriptor-TBufC<TInt S><br/> [0222] E3232.descriptors.buffer-descriptor.TBufC<br/> [0223] 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.<br/> [0224] 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.<br/> Buffer Descriptor-TBuf<TInt S><br/> [0226] E3232.descriptors.buffer-descriptor.TBuf<br/> [0227] 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.<br/> Heap Descriptor-HBufC<br/> [0229] E3232.descriptors.buffer-descriptor.HBufC<br/> [0230] 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.<br/> [0231] 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.<br/> The Descriptor Classes' Relationships<br/> [0233] E32.descriptors.classes<br/> [0234] 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.<br/> [0235] 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<br/> [0236] 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.<br/> [0237] 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??*.<br/> Using Descriptors for Function Interfaces<br/> [0239] e32.descriptors.using-function-interfaces<br/> [0240] 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.<br/> There are four main cases:<br/>
Passing a constant string <br/> In 'C': StringRead(const char* aString); <br/> The length of the string is implied by the zero terminator; therefore, the function does not require the length to be explicitly specified. <br/> In E32: StringRead(const TDesC& aString); <br/> The descriptor contains both the string and its length. <br/> Passing a string which can be changed. <br/> In 'C': StringWrite(char* aString, int aMaxLength); <br/> The length of the passed string is implied by the zero terminator. aMaxLength indicates the maximum length to which the string may be extended. <br/> In E32: StringWrite(TDes& aString); <br/> The descriptor contains the string, its length and the maximum length to which the string may be extended. <br/> Passing a buffer containing general binary data <br/> In 'C': BufferRead(const void* aBuffer, int aLength); <br/> Both the address and length of the buffer must be specified. <br/> In E32: BufferRead(const TDes8& aBuffer); <br/> 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. <br/> Passing a buffer containing general binary data which can be changed. <br/> In 'C': <br/> BufferWrite(void* aBuffer, int& aLength, int aMaxLength); <br/> 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. <br/> In E32: BufferRead(TDes8& aBuffer); <br/> 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<br/> [0264] e32.descriptors.folding-collating<br/> [0265] There are two techniques that may be used to modify the characters in a descriptor prior to performing some operations on text: <br/>
folding <br/> collatingVariants of member functions that fold or collate are provided where appropriate.Folding<br/> [0270] e32.descriptors.folding<br/> [0271] 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.<br/> Collating<br/> [0273] e32.descriptors.collating<br/> [0274] 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.<br/> Using Descriptors<br/> [0276] e32.descriptors.using<br/> [0277] The following series of examples show how descriptors can be used. Specifically, the examples illustrate: <br/>
the basic concepts of the pointer descriptors, TPtrC and TPtr. See e32.descriptors.using.pointer-descriptors. <br/> the basic concepts of the buffer descriptors, TBufC and TBuf. See e32.descriptors.using.buffer-descriptors. <br/> how descriptors can represent general binary data. See e32.descriptors.using.general-binary-data. <br/> some of the member functions which do not modify the content of a descriptor. See e32.descriptors.using.non-modifying-functions. <br/> some of the member functions which modify the content of a descriptor. See e32.descriptors.using.modifying-functions. <br/> how descriptors can be used in interfaces. See e32.descritpors.using.interface-specifiers. <br/> the basic concepts of the heap descriptor, HBufC. See e32.descritpors.using.heap-descriptors.Pointer Descriptors<br/> [0286] e32.descriptors.using.pointer-descriptors<br/> [0287] 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.<br/> TPtrC<br/> [0289] The 8 bit variant<br/> [0290] 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.<br/> For example, define a constant 'C' style ASCII string:<br/>
const TText8* cstr8=(TText8*)"Hello World!";A TPtrC8 descriptor can be constructed to represent this pre-defined area containing the string "Hello World!": <br/> TPtrC8 ptrC8(cstr8);The descriptor is separate from the data it represents.<br/> [0296] 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: <br/>
ptrC8.Ptr( );is the same as same as the address of the original 'C' string, cstr8.<br/> [0299] The 16 bit variant (UNICODE)<br/> [0300] Similarly, define a constant 'C' style string of wide (or UNICODE) characters: <br/>
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!": <br/> 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: <br/> ptrc16.Ptr( );is the same as the address of the original 'C' string, cstr16.<br/> [0307] The _S macro and build independent names<br/> [0308] 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: <br/>
const TText* cstr=_S("Hello World!");The TPtrC descriptor: <br/> 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.<br/> [0313] 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.<br/> See e32.macro._S.<br/> [0315] The _L macro<br/> [0316] 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.<br/> [0317] 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 "\nThe _L macro constructs a TPtrC". <br/>
testConsole.Printf(_L("\n The _L macro constructs a TPtrC"));See e32.macro._L.TPtr<br/> [0321] 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": [mathematical formula - see original document]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. <br/>
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.<br/> [0326] The data can be completely replaced using the assignment operator: <br/>
ptr=_L("Hi there");<br/> [0328] Note the use of the _L macro to construct a TPtrC of the correct build variant as the source of the assignment.<br/> [0329] 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).<br/> [0330] 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: <br/>
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<br/> [0334] e32.descriptors.using.buffer-descriptors<br/> [0335] 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.<br/> TBufC<br/> [0337] A TBufC is a buffer descriptor where the data area is part of the descriptor itself.<br/> [0338] 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).<br/> For example:<br/>
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.<br/> [0342] The data within bufc2 cannot be modified but it can be replaced using the assignment operator: <br/>
bufc2=_L("Replacement text");<br/> [0344] To prevent any possibility of replacing the data, declare bufc2 as const.<br/> [0345] 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: <br/>
bufc2=_L("Hello World!"); <br/> TPtr ptr=bufc2.Des( ); <br/> ptr.Delete((ptr.Length( )-1),1); <br/> 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<br/> [0352] 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.<br/> For example:<br/>
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.<br/> [0356] The data can be modified directly: <br/>
buf.Append('@');changes buf's data to "Hello World!@" and its length to 13 while: <br/> buf.SetLength(3);changes it length to 3 and its data to "Hel".<br/> [0361] The maximum length of the descriptor always remains at 16.<br/> [0362] Like a TBufC descriptor, the data contained within a TBuf can be replaced entirely using the assignment operator: <br/>
buf=_L("Replacement text");replaces "Hello World" with "Replacement text" and changes the length of the descriptor to 16.<br/> [0365] An attempt to increase the length of the data beyond the maximum generates an exception (a panic). For example: <br/>
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<br/> [0369] e32.descriptors.using.general-binary-data<br/> [0370] 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.<br/> [0371] The kind of data represented or contained by descriptors is not restricted to text. Descriptors can also handle general binary data.<br/> [0372] 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.<br/> [0373] For example set up an area in memory initialised with binary data: <br/>
TUint8 data[6]={0x00,0x01,0x02,0xAD,0xAE,0xAF};<br/> [0375] Construct a modifiable buffer descriptor using the default constructor: <br/>
TBuf8<32> buffer;<br/> [0377] 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.<br/> <tb><sep>TInt index;<br/> <tb><sep>TInt counter;<br/> <tb><sep>buffer.Append(&data[0],sizeof(data));<br/> <tb><sep>buffer.Append(0xFD);<br/> <tb><sep>buffer.Append(0xFE);<br/> <tb><sep>buffer.Append(0xFF);<br/> <tb><sep>counter = buffer.Length( );<br/> <tb><sep>for (index = 0; index < counter; index++)<br/> <tb><sep>testConsole.Printf(_L("0x%02x"),buffer[index]);<br/> <tb><sep>testConsole.Printf(_L("; Length( )=%d;\n"),<br/> <tb><sep>buffer.Length( )<br/> <tb><sep>);<br/> <tb><sep>testConsole.Printf(_L("Size( )=%d; MaxLength( )=%d\n"),<br/> <tb><sep>buffer.Size( ),<br/> <tb><sep>buffer.MaxLength( )<br/> <tb><sep>);<br/> <tb><sep>Text and general binary data can be freely mixed; so that:<br/> <tb><sep>buffer.Append('A');<br/> <tb><sep>buffer.Append('B');<br/> <tb><sep>buffer.Append(0x11);<br/> <tb><sep>is acceptable.Non-modifying Functions<br/> [0379] e32.descriptors.using.non-modifying-functions<br/> [0380] 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<br/> [0381] 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: <br/>
const TBufC<16> bufc(_L("Hello World!"));Right( ) & Mid( )<br/> [0384] These functions construct a TPtrc to represent a portion of bufc's data <br/>
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.<br/> [0386] The Left( ) member function works in a similar way. <br/>
TPtrC ptrc2=bufc.Mid(3,6);<br/> [0388] 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.<br/> [0389] 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( )) <br/>
TInt pos; <br/> . . . <br/> pos=(bufc.Mid(3,6)).Locate('W');<br/> [0393] These functions can panic. For example, requesting the 13 right hand data items in bufc will cause an exception (there are only 12): <br/>
TPtrC ptrc3=bufc.Right(13);Compare( ) & CompareF( )<br/> [0396] 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( ).<br/> [0397] The following example compares the content of bufc with the content of a number of descriptors and displays the results at the test console:<br/> <tb><sep>. . .<br/> <tb><sep>TInt index;<br/> <tb><sep>. . .<br/> <tb><sep>TPtrC genptr;<br/> <tb><sep>const TBufC<19>lessthan(_L(" is less than "));<br/> <tb><sep>const TBufC<19>greaterthan(_L(" is greater than "));<br/> <tb><sep>const TBufC<19>equalto(_L(" is equal to "));<br/> <tb><sep>. . .<br/> <tb><sep>const TBufC<16>compstr[7] =<sep>{_L("Hello World!@@"),<br/> <tb><sep><sep>_L("Hello"),<br/> <tb><sep><sep>_L("Hello Worl"),<br/> <tb><sep><sep>_L("Hello World!"),<br/> <tb><sep><sep>_L("hello world!"),<br/> <tb><sep><sep>_L("Hello World"),<br/> <tb><sep><sep>_L("Hello World@"),<br/> <tb><sep><sep>};<br/> <tb><sep>for (index = 0; index < 7; index++)<br/> <tb><sep>{<br/> <tb><sep>if( (bufc.Compare(compstr[index])) < 0)<br/> <tb><sep>genptr.Set(lessthan);<br/> <tb><sep>else if( (bufc.Compare(compstr[index])) > 0)<br/> <tb><sep>genptr.Set(greaterthan);<br/> <tb><sep>else genptr.Set(equalto);<br/> <tb><sep>testConsole.Printf(_L("\"%S\"%S\"%S\"\n"),<br/> <tb><sep>&bufc,<br/> <tb><sep>&genptr,<br/> <tb><sep>&compstr[index]<br/> <tb><sep>);<br/> <tb><sep>}<br/> [0398] 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).<br/> [0399] Using CompareF( ), the case is not important; both the fourth and fifth comparisons return an equal result.<br/> Locate( ), LocateF( ) & LocateReverse( )<br/> [0401] The locate functions can be used to find the position (offset) of a character within text or a specific value within general binary data.<br/> [0402] 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:<br/> <tb>. . .<br/> <tb>TInt index;<br/> <tb>TInt pos;<br/> <tb>TPtrC genptr;<br/> <tb>const TBufC<9> notfound(_L("NOT FOUND")),<br/> <tb>const TBufC<5> found(_L("found"));<br/> <tb>. . .<br/> <tb>TChar ch[4] = {'H', '!', 'o', 'w'};<br/> <tb>. . .<br/> <tb>testConsole.Printf(_L("using Locate( )\n"));<br/> <tb>for (index = 0 ; index < 4; index++)<br/> <tb><sep>{<br/> <tb><sep>pos = bufc.Locate(ch[index]);<br/> <tb><sep>if (pos < 0)<br/> <tb><sep>genptr.Set(notfound);<br/> <tb><sep>else<br/> <tb><sep>genptr.Set(found);<br/> <tb><sep>testConsole.Printf(_L("\"%S\" Char %c is at pos %d (%S)\n"),<br/> <tb><sep>&bufc,<br/> <tb><sep>ch[index],<br/> <tb><sep>pos,<br/> <tb><sep>&genptr<br/> <tb><sep>);<br/> <tb><sep>}<br/> [0403] The character 'w' is not found using Locate( ) but is found using LocateF( ). This is because Locate( ) is case sensitive while LocateF( ).<br/> [0404] This example uses LocateReverse( ) which is used to find the position of a character starting from the end of the descriptor's data area<br/> <tb>. . .<br/> <tb>testConsole.Printf(_L("using LocateReverse( )\n"));<br/> <tb>for (index = 0 ; index < 4; index++)<br/> <tb><sep>{<br/> <tb><sep>pos = bufc.LocateReverse(ch[index]);<br/> <tb><sep>if(pos < 0)<br/> <tb><sep>genptr.Set(notfound);<br/> <tb><sep>else<br/> <tb><sep>genptr.Set(found);<br/> <tb><sep>testConsole.Printf(_L("\"%S\" Char %c is at pos %d (%S)\n"),<br/> <tb><sep>&bufc,<br/> <tb><sep>ch[index],<br/> <tb><sep>pos,<br/> <tb><sep>&genptr<br/> <tb><sep>);<br/> <tb><sep>}<br/> [0405] Note that the 2nd char 'o' in the string "Hello World!" is found this time.<br/> Match( ) & MatchF( )<br/> [0407] 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.<br/> <tb><sep>. . .<br/> <tb><sep>TInt index;<br/> <tb><sep>TInt pos;<br/> <tb><sep>TPtrC genptr;<br/> <tb><sep>const TBufC<9> notfound(_L("NOT FOUND"));<br/> <tb><sep>const TBufC<5> found(_L("found"));<br/> <tb><sep>. . .<br/> <tb><sep>TBufC<8>matchstr[7] =<sep>{_L("*World*"),<br/> <tb><sep><sep>_L("*W?rld*"),<br/> <tb><sep><sep>_L("*Wor*"),<br/> <tb><sep><sep>_L("Hello"),<br/> <tb><sep><sep>_L("*W*"),<br/> <tb><sep><sep>_L("hello"),<br/> <tb><sep><sep>_L("*"),<br/> <tb><sep><sep>};<br/> <tb><sep>for (index = 0 ; index < 7; index++)<br/> <tb><sep>{<br/> <tb><sep>pos = bufc.Match(matchstr[index]);<br/> <tb><sep>if(pos < 0)<br/> <tb><sep>genptr.Set(notfound);<br/> <tb><sep>else<br/> <tb><sep>genptr.Set(found);<br/> <tb><sep>testConsole.Printf(_L("%- 8S pos %2d (%S)\n"),<br/> <tb><sep>&matchstr[index],<br/> <tb><sep>pos,<br/> <tb><sep>&genptr<br/> <tb><sep>):<br/> <tb><sep>}<br/> [0408] Note that when using MatchF( ), the result is different when matching the 6th string where the case is ignored.<br/> Modifying Functions<br/> [0410] e32.descriptors.using.modifying-functions<br/> [0411] 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.<br/> [0412] These examples all use a TBuf descriptor constructed to contain the text "Hello World!". <br/>
TBuf<32> buf(_L("Hello World!"));Swap( )<br/> [0415] The contents, length and size of altbuf1 and buf are swapped; the maximum lengths of the descriptors do NOT change. <br/>
TBuf<16> altbuf1(_L("What a nice day")); <br/> . . . <br/> buf.Swap(altbuf1);Repeat( )<br/> [0420] The current length of buf is set to 16. Repeat copying the characters "Hello" generates the text sequence "HelloHelloHelloH" in buf. <br/>
buf.SetLength(16); <br/> buf.Repeat(_L("Hello"));<br/> [0423] Setting the length of buf to and re-doing the repeat generates the text sequence "HelloHel".<br/> Justify( )<br/> [0425] The example uses src as the source descriptor. <br/>
TBufVC<40> src(_"Hello World!")); <br/> . . . <br/> buf.Justify(src,16,ELeft,'@');<br/> [0429] The descriptor src has length 12.<br/> [0430] 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. <br/>
buf.Justify(src,16,ECenter,'@');<br/> [0432] 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 <br/>
buf.Justify(src,10,ECenter,'@');<br/> [0434] 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 <br/>
buf.Justify(src,KDefaultJustifyWidth,ECenter,'@');<br/> [0436] 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.<br/> Descriptors as Interface Specifiers<br/> [0438] e32.descriptors.using.interface-specifiers<br/> [0439] See the eudesint project for examples illustrating the use of descriptors in function interfaces.<br/> Heap Descriptors<br/> [0441] e32.descriptors.using.heap-descriptors<br/> [0442] 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.<br/> [0443] An HBufC is always constructed on the heap using the static member functions New( ), NewL( ) or NewLC( ). For example: <br/>
HBufC* buf; <br/> . . . <br/> buf=HBufC::NewL(15);<br/> [0447] 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: <br/>
*buf=_L("Hello World!");<br/> [0449] To allow more than 15 characters or data items to be assigned into the HBufC, it must be reallocated first. For example: <br/>
buf=buf-> ReAllocL(20);<br/> [0451] This permits the following assignment to be done without causing a panic: <br/>
*buf=_L("Hello World! Morning");<br/> [0453] 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.<br/> [0454] 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: <br/>
TPtr ptr=buf-> Des( ); <br/> . . . <br/> ptr.Delete((ptr.Length( )-9),9); <br/> ptr.Append(_L("& Hi"));<br/> [0459] This changes the data in the HBufC and the length of the HBufC.<br/> <br/> TPtrC Class Constant Pointer Descriptor<br/> Overview<br/> [0461] Derivation <br/> TDesC Abstract: implements descriptor behaviour which does not modify data. <br/> TPtrC A constant pointer descriptor.<br/> [0464] Defined in <br/> e32des8.h for the 8 bit variant (TPtr8). <br/> e32des16.h for the 16bit variant (TPtr16).<br/> [0467] Description<br/> [0468] 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).<br/> [0469] 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.<br/> [0470] Often, a TPtrC will appear as the right hand side of an expression or as an initialisation value for another descriptor, for example: <br/>
TBuf<16> str(_L"abcdefghijklmnop")); <br/> . . . <br/> str.Find(_L"abc"); <br/> str.Find(_L"bcde");<br/> [0475] 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).<br/> [0476] The 8 bit variant, TPtrC8 can be constructed to access binary data The 8 bit variant is always explicitly used for binary data.<br/> [0477] 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.<br/> [0478] All the member functions described under the TDesC class are available for use by a TPtrc descriptor. In summary these are:<br/> <tb>Length( )<sep>Fetch length of descriptor data.<br/> <tb>Size( )<sep>Fetch the number of bytes occupied by<br/> <tb><sep>descriptor data.<br/> <tb>Ptr( )<sep>Return a pointer to the descriptor data.<br/> <tb>Compare( ),<sep>Compare data (normally), (folded), (collated).<br/> <tb>CompareF( ),<br/> <tb>CompareC( )<br/> <tb>Match( ),<sep>Pattern match data (normally), (folded),<br/> <tb>MatchF( ), MatchC( )<sep>(collated).<br/> <tb>Locate( ), LocateF( )<sep>Locate a character in forwards direction<br/> <tb><sep>(normally), (folded).<br/> <tb>LocateReverse( ),<sep>Locate a character in reverse direction<br/> <tb>LocateReverseF( )<sep>(normally), (folded).<br/> <tb>Find( ), FindF( ), FindC<sep>Find data (normally), (folded), (collated).<br/> <tb>Left( )<sep>Construct TPtrC for leftmost part of data.<br/> <tb>Right( )<sep>Construct TPtrC for rightmost part of data.<br/> <tb>Mid( )<sep>Construct TPtrC for portion of data.<br/> <tb>Alloc( ),<sep>Construct an HBufC for this descriptor.<br/> <tb>AllocL( ), AllocLC( )<br/> <tb>HufEncode( )<sep>Huffman encode<br/> <tb>HufDecode( )<sep>Huffman decode<br/> <tb>operators < <= > >= ==<sep>Comparison operators<br/> <tb>operator [ ]<sep>Indexing operatorConstruction<br/> [0480] e32.descriptors.TPtrC.construction<br/> [0481] TPtrC( ) Default C++ constructor<br/> [0482] Description<br/> [0483] The default C++ constructor is used to construct a constant pointer descriptor.<br/> [0484] The length of the constructed descriptor is set to zero and its pointer is set to NULL.<br/> [0485] Notes<br/> [0486] Use the Set( ) member function to initialise the pointer descriptor.<br/> [0487] TPtrC( ) Copy constructor<br/> [0488] TPtrC(const TPtrC& aDes);<br/> [0489] Description<br/> [0490] The C++ copy constructor constructs a new TPtrC object from the existing one.<br/> [0491] The length of the constructed descriptor is set to the length of aDes and is set to point to aDes's. data.<br/> [0492] TPtrC( ) C++ constructor [with any descriptor]<br/> [0493] TPtrC(const TDesC& aDes);<br/> [0494] Description<br/> [0495] The C++ constructor is used to construct the TPtrC with any kind of descriptor.<br/> [0496] The length of the constructed descriptor is set to the length of aDes, and it is set to point to aDes's data.<br/> [0497] Arguments <br/> const TDesC& aDes A reference to any type of descriptor used to construct the TPtrC.<br/> [0499] Notes<br/> [0500] If aDes is a reference to a heap descriptor (HBufC), then the data also resides on the heap.<br/> [0501] TPtrC( ) C++ constructor [with zero terminated string]<br/> [0502] TPtrC(const TText* aString);<br/> [0503] Description<br/> [0504] The C++ constructor is used to construct the TPtrC object with a zero terminated string.<br/> [0505] The length of the descriptor is set to the length of the zero terminated string, excluding the zero terminator.<br/> [0506] The constructed descriptor is set to point to the location of the string, whether in RAM or ROM.<br/> [0507] Arguments <br/> const TText* aString A pointer to the zero terminated used to construct the TPtrC.<br/> [0509] TPtrC( )C++ constructor [with address and length]<br/> [0510] TPtrC(const TUint??* aBuf,TInt aLength);<br/> [0511] Description<br/> [0512] The C++ constructor is used to construct the TPtrC with the memory address and length.<br/> [0513] The length of the constructed descriptor is set to the value of aLength.<br/> [0514] The constructed descriptor is set to point to the memory address supplied in aBuf; the address can refer to RAM or ROM.<br/> [0515] Arguments <br/> const TUint??* aBuf The address which is to be the data area of the constant pointer descriptor. <br/>
TInt aLength The length of the constructed constant pointer descriptor. <br/>
[0521] e32.descriptors.TPtrC.late-initialisation<br/> [0522] Set( ) Initialisation taking any descriptor<br/> [0523] void Set(const TDesC& aDes);<br/> [0524] Description<br/> [0525] Use this function to initialise (or re-initialise) a constant pointer descriptor using the content of any kind of descriptor.<br/> [0526] The length of this constant pointer descriptor is set to the length of aDes.<br/> [0527] This descriptor is set (or re-set) to point to aDes's data<br/> [0528] Arguments <br/> const TDesC& aDes A reference to any descriptor whose content is to be used to initialise this constant pointer descriptor.<br/> [0530] Notes<br/> [0531] The Set( ) function can be used to initialise a constant pointer descriptor constructed using the default constructor.<br/> [0532] If aDes is a reference to a heap descriptor (HBufC), then the data also resides on the heap.<br/> [0533] Set( ) Initialisation taking address and length<br/> [0534] void Set(const TUint??* aBuf,TInt aLength);<br/> [0535] Use this function to initialise (or re-initialise) a constant pointer descriptor using the supplied memory address and length.<br/> [0536] The length of this constant pointer descriptor is set to the value of aLength.<br/> [0537] The descriptor is set to point to the memory address supplied in aBuf; the address can refer to RAM or ROM.<br/> [0538] Arguments <br/> const TUint??* aBuf The address which is to be the data area of the constant pointer descriptor. <br/>
TInt aLength The length of the constant pointer descriptor. <br/>
[0543] Notes<br/> [0544] The Set( ) function can be used to initialise a constant pointer descriptor constructed using the default constructor.<br/> <br/> TPtr Class Modifiable Pointer Descriptor<br/> Overview<br/> [0546] Derivation <br/> TDesC Abstract: implements descriptor behaviour which does not modify data. <br/> TDes Abstract: implements descriptor behaviour which can change data. <br/> TPtr A modifiable pointer descriptor.<br/> [0550] Defined in <br/> e32des8.h for the 8 bit variant (TPtr8). <br/> e32des16.h for the 16 bit variant (TPtr16).<br/> [0553] Description<br/> [0554] 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.<br/> [0555] 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: <br/>
TBufC<8> str(_L("abc")); <br/> str.Des( ).Append('x');<br/> [0558] TPtr is defined as either a TPtr8 or TPtr16 depending on the build variant and can be used to access text.<br/> [0559] The 8 bit variant, TPtr8 can be constructed to access binary data. The 8 bit variant is always explicitly used for binary data<br/> [0560] 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.<br/> [0561] All the member functions described under the TDesC and TDes classes are available for use by a TPtr descriptor. In summary these are:<br/> <tb>Length( )<sep>Fetch length of descriptor data.<br/> <tb>Size( )<sep>Fetch the number of bytes occupied by<br/> <tb><sep>descriptor data.<br/> <tb>Ptr( )<sep>Fetch address of descriptor data.<br/> <tb>Compare( ),<sep>Compare data (normally), (folded), (collated).<br/> <tb>CompareF( ),<br/> <tb>CompareC( )<br/> <tb>Match( ),<sep>Pattern match data (normally), (folded),<br/> <tb>MatchF( ), MatchC( )<sep>(collated).<br/> <tb>Locate( ), LocateF( )<sep>Locate a character in forwards direction<br/> <tb><sep>(normally), (folded).<br/> <tb>LocateReverse( ),<sep>Locate a character in reverse direction<br/> <tb>LocateReverseF( )<sep>(normally), (folded).<br/> <tb>Find( ), FindF( ), FindC<sep>Find data (normally), (folded), (collated).<br/> <tb>Left( )<sep>Construct TPtrC for leftmost part of data.<br/> <tb>Right( )<sep>Construct TPtrC for rightmost part of data.<br/> <tb>Mid( )<sep>Construct TPtrC for portion of data.<br/> <tb>Alloc( ),<sep>Construct an HBufC for this descriptor.<br/> <tb>AllocL( ), AllocLC( )<br/> <tb>HufEncode( )<sep>Huffman encode<br/> <tb>HufDecode( )<sep>Huffman decode<br/> <tb>MaxLength( )<sep>Fetch maximum length of descriptor.<br/> <tb>MaxSize( )<sep>Fetch maximum size of descriptor<br/> <tb>SetLength( )<sep>Set length of descriptor data<br/> <tb>Zero( )<sep>Set length of descriptor data to zero<br/> <tb>SetMax( )<sep>Set length of descriptor data to the<br/> <tb><sep>maximum value.<br/> <tb>Swap( )<sep>Swap data between two descriptors.<br/> <tb>Copy( ),<sep>Copy data (normally), (and fold), (and collate).<br/> <tb>CopyF( ), CopyC( )<br/> <tb>CopyLC( )<sep>Copy data and convert to lower case.<br/> <tb>CopyUC( )<sep>Copy data and convert to upper case<br/> <tb>CopyCP( )<sep>Copy data and capitalise<br/> <tb>Repeat( )<sep>Copy and repeat.<br/> <tb>Justify( )<sep>Copy and justify.<br/> <tb>Insert( )<sep>Insert data.<br/> <tb>Delete( )<sep>Delete data.<br/> <tb>Replace( )<sep>Replace data.<br/> <tb>TrimLeft( )<sep>Delete spaces from left side of data area.<br/> <tb>TrimRight( )<sep>Delete spaces from right side of data area.<br/> <tb>Trim( )<sep>Delete spaces from both left and right side of<br/> <tb><sep>data area.<br/> <tb>Fold( )<sep>Fold characters.<br/> <tb>Collate( )<sep>Collate characters.<br/> <tb>LowerCase( )<sep>Convert to lower case.<br/> <tb>UpperCase( )<sep>Convert to upper case.<br/> <tb>Capitalise( )<sep>Capitalise.<br/> <tb>Fill( )<sep>Fill with specified character.<br/> <tb>FillZ( )<sep>Fill with 0x00.<br/> <tb>Num( )<sep>Convert numerics to character (hex.digits to<br/> <tb><sep>lower case).<br/> <tb>NumUC( )<sep>Convert numerics to (upper case) character.<br/> <tb>Format( ),<sep>Convert multiple arguments to character<br/> <tb>FormatList( )<sep>according to format specification.<br/> <tb>Append( )<sep>Append data.<br/> <tb>AppendFill( )<sep>Append with fill characters.<br/> <tb>AppendJustify( )<sep>Append data and justify<br/> <tb>AppendNum( )<sep>Append from converted numerics.<br/> <tb>AppendNumUC( )<sep>Append from converted numerics; convert to<br/> <tb><sep>upper case.<br/> <tb>AppendFormat( ),<sep>Append from converted multiple arguments.<br/> <tb>AppendFormatList( )<br/> <tb>ZeroTerminate( )<sep>Append zero terminator.<br/> <tb>PtrZ( )<sep>Append zero terminator and return a pointer.<br/> <tb>operators < <= > >= ==<sep>Comparison operators.<br/> <tb>operator +=<sep>Appending operator.<br/> <tb>operator [ ]<sep>Indexing operator.Construction<br/> [0563] e32.descriptors.TPtr.construction<br/> [0564] TPtr( ) C++ constructor [with address and maximum length]<br/> [0565] TPtr(TUint??* aBuf,TInt aMaxLength);<br/> [0566] Description<br/> [0567] The C++ constructor is used to construct the TPtr with the address and maximum length.<br/> [0568] The length of the constructed descriptor is set to zero and its maximum length is set to aMaxLength.<br/> [0569] The constructed descriptor is set to point to the memory address supplied in aBuf which can refer either to RAM or ROM.<br/> [0570] Arguments <br/> TUint??* aBuf The address which is to be the data area of the modifiable pointer descriptor. <br/>
TInt aMaxLength The maximum length of the new modifiable pointer descriptor. <br/>
[0575] TPtr( ) C++ constructor [with address, length and maximum length]<br/> [0576] TPtr(TUint??* aBuf,TInt aLength,TInt aMaxLength);<br/> [0577] Description<br/> [0578] The C++ constructor is used to construct the TPtr with the address, length and maximum length.<br/> [0579] Use this to construct a modifiable pointer descriptor using the supplied memory address, length and maximum length to initialise it.<br/> [0580] The length of the constructed descriptor is set to aLength and its maximum length is set to aMaxLength.<br/> [0581] The constructed descriptor is set to point to the memory address supplied in aBuf which can refer either to RAM or ROM.<br/> [0582] Arguments <br/> TUint??* aBuf The address which is to be the data area of the modifiable pointer descriptor. <br/>
TInt aLength The length of the new modifiable pointer descriptor.<br/>
TInt aMaxLength The maximum length of the new modifiable pointer descriptor. <br/>
[0590] e32.descriptors.TPtr.late-initialisation<br/> [0591] Set( ) Initialisation by copying a TPtr<br/> [0592] void Set(TPtr& apt);<br/> [0593] 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.<br/> [0594] The length of the descriptor is set to the length of aPtr and its maximum length is set to the maximum length of aPtr.<br/> [0595] The descriptor is set (or re-set) to point to aPtr's data.<br/> [0596] Arguments <br/> TPtr& aPtr A reference to a modifiable pointer descriptor whose content is to be used to initialise this modifiable pointer descriptor.<br/> [0598] Set( ) Initialisation taking address, length and maximum length<br/> [0599] void Set(TUint??* aBuf,TInt aLength,TInt aMaxLength);<br/> [0600] Use this function to initialise (or re-initialise) a modifiable pointer descriptor using the supplied memory address, length and maximum length.<br/> [0601] The length of the resulting descriptor is set to the value of aLength and its maximum length is set to the value of aMaxLength.<br/> [0602] The descriptor is set (or re-set) to point to the memory address supplied in aBuf; the address can refer to RAM or ROM.<br/> [0603] Arguments <br/> TUint??* aBuf The address which is to be the data area of the modifiable pointer descriptor. <br/>
TInt aLength The length of the modifiable pointer descriptor. <br/>
TInt aMaxLength The maximum length of the modifiab |