![]() | InDesign SDK 20.5 |
#include <StringStorage.h>
Public Types | |
| enum | { kDefaultLength = 16 } |
| typedef int32 | size_type |
Public Member Functions | |
| operator const UTF16TextChar * (void) const | |
| UTF16TextChar | operator[] (int pos) const |
| StringStorage * | MakeSize (size_type requestedSize) |
| size_type | capacity () const |
| UTF16TextChar * | GetBuffer () |
| const UTF16TextChar * | ConstBuffer () const |
| StringStorage * | Copy () |
| void | Dispose () |
| bool | IsUnique () const |
Static Public Member Functions | |
| static StringStorage * | CreateStringStorage (int32 initialLength=kDefaultLength, StringStorage *sourceStr=nil) |
Protected Member Functions | |
| StringStorage (int32 initialLength, size_type adjustedLength) | |
| StringStorage (const StringStorage &srcStorage, size_type initialLength, size_type adjustedLength) | |
Protected Attributes | |
| int32 | fMemorySize |
| int32 | fRequestedSize |
| size_type | fReferenceCount |
| UTF16TextChar | fFirstCharOfBuffer [1] |
StringStorage encapsulates management of the buffer of a string. A StringStorage may be used by
multiple strings, and the shared storage makes copying strings cheaper (you can just copy the reference to the StringStorage instead of allocating a block and doing a memcpy). The owning string must acquire a unique reference inorder to update the StringStorage.
A StringStorage and the buffer it holds are allocated as a single block of memory. The StringStorage is in the start of the block, and the buffer follows immediately after (the last field of the StringStorage is the first character of the buffer).
StringStorage holds 16-bit characters and is null terminated. The buffer must be big enough for the string and for the null character.
This class just maintains an array of textchars; all handling of Unicode surrogates, etc., must be done in the client code.
| protected |
Constructor
| initialLength | - The initial expected size of the string, as the number of textchars required for storing characters. |
| adjustedLength | - The actual size in textchars of the buffer that was allocated. |
| protected |
Constructor - create a new StringStorage based on an existing one
| srcStorage | - The storage we're copying from |
| initialLength | - The initial expected size of the string, as the number of textchars required for storing characters. |
| adjustedLength | - The actual size in textchars of the buffer that was allocated. |
| inline |
Returns the size in textchars that has been allocated for the string buffer.
| inline |
ConstBuffer returns a const pointer to the start of the character storage (it's a const safe
version of GetBuffer().
| inline |
"Copies" the string storage. Really it justs increments the ref-count. Returns a pointer
to the storage that the copy can use (always the same as this). If you wanted to turn off copy-on-write, you could override this function, and make it allocate a new StringStorage instead. Call this when you are copying from one string to another, and want to have the two strings use the same StringStorage.
| static |
Factory function for creating StringStorage objects. Allocates a single block for the StringStorage and for the buffer, based on the initial requested size, and calls the placement new operator on StringStorage. The actual size of the buffer that is allocated is adjusted upward to make room for expected edits (this is an optimization).
| initialLength | - The initial expected size of the string, as the number of textchars required for storing characters. |
| sourceStr | - The new string will be a copy of the source string. The StringStorage may be copied because the string the references needs a copy it owns so it can update it, or because the buffer needs to be enlarged. |
| void StringStorage::Dispose | ( | ) |
Releases the StringStorage. Decrements the ref-count, and if the ref-count goes to zero, also
deletes the StringStorage (since no one is using it). Call this when you are all done with the string storage.
| inline |
GetBuffer returns a pointer to the start of the character storage. The caller MUST make sure
that it holds the only reference on the storage first, and that it has requested enough storage space for what it needs to do (e.g., by calling MakeSize()).
| inline |
Checks if this storage is shared (ref count is greater than one).
| StringStorage* StringStorage::MakeSize | ( | size_type | requestedSize | ) |
Call this before making changes to the buffer data. It will create a new StringStorage of the
requested size if either this StringStorage has multiple references on it, or if it is too small.
| requestedSize | - size in textchars of the buffer |