os/ossrv/lowlevellibsandfws/apputils/engineering/stringpool/StringPool.dox
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/** @mainpage
sl@0
     2
sl@0
     3
	@section Header
sl@0
     4
	<center>
sl@0
     5
	<Table>
sl@0
     6
	<tr><td>Owner:</td><td>Application Frameworks & Protocols</td></tr>
sl@0
     7
	<tr><td>Author:</td><td>Leon Clarke</td></tr>
sl@0
     8
	<tr><td>Last Revised:</td><td>20 March 2002.</td></tr>
sl@0
     9
	<tr><td>Revision:</td><td>3.0</td></tr>
sl@0
    10
	<tr><td>Status:</td><td>Released</td></tr>
sl@0
    11
	<tr><td>Reviewers:</td><td></td></tr>
sl@0
    12
	<tr><td>Approval:</td><td>(PM) Urmi Shah, (ESM) Akin Oyesola, (Architect) Andrew Baldwin</td></tr>
sl@0
    13
	</Table>
sl@0
    14
	</center>
sl@0
    15
	<hr>
sl@0
    16
sl@0
    17
	@section Revision History
sl@0
    18
	<Table>
sl@0
    19
	<tr><td>Date</td><td>Version</td><td>Status</td><td>Description</td></tr>
sl@0
    20
	<tr><td>21-05-2001</td><td>1.0</td><td>Issued</td><td>Issued</td></tr>
sl@0
    21
	<tr><td>05-07-2001</td><td>1.1</td><td>Added more detail, in particular about static tables.</td><td>Issued</td></tr>
sl@0
    22
	<tr><td>05-07-2001</td><td>1.2</td><td>Minor editorial changes following T3 review comments.</td><td>Issued</td></tr>
sl@0
    23
	<tr><td>23-07-2001</td><td>1.3</td><td>Added reference to example code.</td><td>Issued</td></tr>
sl@0
    24
	<tr><td>09-11-2001</td><td>2.0</td><td>Added mutiple table support and case-sensitive strings</td><td>Issued</td></tr>
sl@0
    25
	<tr><td>20-03-2002</td><td>3.0</td><td>Incorporated changes following defect fixing</td><td>Released</td></tr>
sl@0
    26
	</Table>
sl@0
    27
sl@0
    28
sl@0
    29
	@section Introduction
sl@0
    30
sl@0
    31
   The string pool is a way of storing strings that makes comparison
sl@0
    32
   almost instantaneous at the expense of string creation. It is
sl@0
    33
   particularly efficient at handling string constants that are known
sl@0
    34
   at compile time. It currently only supports 8 bit strings. The
sl@0
    35
   basic algorithm is to ensure that the pool only contains one string
sl@0
    36
   of any particular value, using reference counts to keep track of
sl@0
    37
   it. Subsequent strings with the same value will actualy refer to
sl@0
    38
   the same copy.
sl@0
    39
sl@0
    40
   To use the string pool, you need an RStringPool object. Strings
sl@0
    41
   from different string pools can't be compared, so there should only
sl@0
    42
   be 1 string pool open per thread (unless one is in a component that
sl@0
    43
   doesn't export its use of the string pool). Of course, you can have
sl@0
    44
   multiple RStringPool objects, as long as they are all handles to
sl@0
    45
   the same string pool.
sl@0
    46
sl@0
    47
   Within this object, there are 2 distinct pools of strings, one
sl@0
    48
   comprising strings that are 'case-sensitive' (represented using the
sl@0
    49
   RString class) and another representing strings that are 'case-insensitive' (RStringF). Case-sensitive strings behave in a
sl@0
    50
   straightforward way. Case-insensitive strings should be used in a
sl@0
    51
   situation where case doesn't matter at all; if you create a new
sl@0
    52
   RStringF that differs from an existing RStringF only in terms of
sl@0
    53
   case, when you read back the value of the 'new' string, it will
sl@0
    54
   have the same value as the 'existing' one. This can be very useful
sl@0
    55
   in situations where strings are considered case-insensitive, but
sl@0
    56
   there is a 'traditional case' that is normaly used. As long as the
sl@0
    57
   first value to be added is in the 'traditional case', all
sl@0
    58
   subsequent additions will be corrected to match this first entry.
sl@0
    59
sl@0
    60
   Case-insensitivity assumes a character set of us-ascii (i.e.it only
sl@0
    61
   considers A-Z to be equivalent to a-z)
sl@0
    62
sl@0
    63
   If a string has a more complex or different case-sensitivity
sl@0
    64
   requirement that this model doesn't match, then it may be necessary
sl@0
    65
   to compare strings outside the pool, which may make the string pool
sl@0
    66
   inapplicable.
sl@0
    67
sl@0
    68
   Corresponding to RString and RStringF are the classes RStringToken
sl@0
    69
   and RStringTokenF. These are smaller (4 bytes long rather than 8)
sl@0
    70
   but need to be turned into String or StringF classes before you can
sl@0
    71
   do anything useful with them. In particular, you can't directly
sl@0
    72
   find the contents of a string token. They should be used when space
sl@0
    73
   is absoluteley at a premium, for instance storing a lot of strings
sl@0
    74
   in an array, or similar applications.
sl@0
    75
sl@0
    76
   @section Static Tables
sl@0
    77
sl@0
    78
   A very important aspect of the string pool is the concept of static string
sl@0
    79
   table. This is best thought of as an array of common
sl@0
    80
   strings. Integers can be transformed into the strings corresponding
sl@0
    81
   to that index position in the array via the String and StringF
sl@0
    82
   functions. In addition, a string can be cast back to an integer,
sl@0
    83
   allowing a switch statement on strings (it returns -1 if the string
sl@0
    84
   isn't one from any static table of the pool). Another advantage to using the
sl@0
    85
   static table is that the function to create the string can't leave,
sl@0
    86
   and the string doesn't need to be closed (although closing it is
sl@0
    87
   harmless)
sl@0
    88
sl@0
    89
   Multiple case-insensitive and case-sensitive string tables are supported. 
sl@0
    90
sl@0
    91
   A static table is written as a .st file, and is processed by
sl@0
    92
   stringtable.pl early in the build process to generate the actual
sl@0
    93
   cpp and header files at compile time. The format of the .st file is
sl@0
    94
   basicaly as follows. The first noncomment line consists of
sl@0
    95
   fstringtable <TableName> for a case-insensitive table and stringtable <TableName>
sl@0
    96
   for a case-sensitive table. Each subsequent non-comment line consists
sl@0
    97
   of the name of an enum followed by the value of the string. Comment
sl@0
    98
   lines start with # and can be added anywhere. You can also have
sl@0
    99
   lines starting in !, which will be output into the header file if
sl@0
   100
   you want additional comments in the header. e.g.
sl@0
   101
sl@0
   102
   @code
sl@0
   103
   # Example String Table
sl@0
   104
   fstringtable ExampleStringTable
sl@0
   105
   !// Some types of fruit
sl@0
   106
   # This comment won't appear in the .h file, but the one above is.
sl@0
   107
   EApple apple
sl@0
   108
   EOrange orange
sl@0
   109
   EBanana banana
sl@0
   110
   # Some animals
sl@0
   111
   ECat cat
sl@0
   112
   EDog dog
sl@0
   113
   @endcode
sl@0
   114
sl@0
   115
   The string table name must be a valid C++ class name, and the
sl@0
   116
   generated code includes a class that contains within it an enum
sl@0
   117
   corresponding to the elements in the array, so entries in the above
sl@0
   118
   example could be referred to as MyStringTable::ECat and so on.
sl@0
   119
sl@0
   120
   The stringpool.pl script takes a .st file and creates .cpp and .h
sl@0
   121
   files of the same name in the same directory. The easiest way to
sl@0
   122
   use this is to export the .st file to /epoc32/generated/, create an
sl@0
   123
   extension makefile that runs the script during the makefile phase
sl@0
   124
   and then copies the generated .h file to epoc32, and then compile
sl@0
   125
   the .cpp file as normal from an mmp files. Look at the example code
sl@0
   126
   in //EPOC/main/generic/bafl/docs/stringtableexample/... for a
sl@0
   127
   simple example of how to do this.
sl@0
   128
sl@0
   129
   To be notified when the String Pool is closing you can derive from the mix-in class    MStringPoolCloseCallBack and implement the StringPoolClosing() function. The OpenL(const    TStringTable& aTable, MStringPoolCloseCallBack& aCallBack) overridden function must be    used to register the callback with the String Pool. Where aCallback is the pointer to the    callback. The StringPoolClosing() function will then get called when the String Pool is    closing. 
sl@0
   130
sl@0
   131
sl@0
   132
sl@0
   133
 **/