casa
$Rev:20696$
|
Store strings in the Standard Storage Manager. More...
#include <SSMStringHandler.h>
Public Member Functions | |
SSMStringHandler (SSMBase *aBase) | |
Default constructor initializes last string bucket to -1. | |
~SSMStringHandler () | |
void | setLastStringBucket (Int lastStringBucket) |
Set or get last string bucketnr. | |
Int | lastStringBucket () const |
void | put (Int &bucketNr, Int &offset, Int &length, const String &string) |
Put a single string or an array of strings into a bucket. | |
void | put (Int &bucketNr, Int &offset, Int &length, const Array< String > &string, Bool handleShape) |
void | putShape (Int &bucketNr, Int &offset, Int &length, const IPosition &aShape) |
Put a single string or an array of strings into a bucket. | |
void | getShape (IPosition &aShape, Int bucket, Int &offset, Int length) |
Get the shape in the given bucket and offset. | |
void | remove (Int bucketNr, Int offset, Int length) |
Remove data with the given length from a bucket. | |
void | get (String &string, Int bucket, Int offset, Int length) |
Get a string or an array of strings. | |
void | get (Array< String > &string, Int bucket, Int offset, Int length, Bool handleShape) |
void | flush () |
Flush the currently used string bucket. | |
void | init () |
Initialize the StringHandler. | |
void | resync () |
Resynchronize (after a table lock was acquired). | |
Private Member Functions | |
SSMStringHandler (const SSMStringHandler &) | |
Forbid copy constructor and assignment. | |
SSMStringHandler & | operator= (const SSMStringHandler &) |
void | getBucket (uInt bucketNr, Bool isNew=False) |
Get the given bucket and make it current. | |
void | getNewBucket (Bool doConcat) |
Get a new bucket and make it current. | |
void | putData (Int length, const Char *data) |
Put the data with the given length at the end of the current bucket. | |
void | getData (Int length, Char *data, Int &offset) |
Get the data with the given length from the curent bucket at the given offset. | |
void | replace (Int bucketNr, Int offset, Int length, const String &string) |
Replace the current data with the new data. | |
void | replace (Int bucketNr, Int offset, Int length, Int totalLength, const IPosition &aShape) |
void | replace (Int bucketNr, Int offset, Int length, Int totalLength, const Array< String > &string, Bool handleShape) |
void | replaceData (Int &offset, Int length, const Char *data) |
Private Attributes | |
SSMBase * | itsSSMPtr |
Int | itsCurrentBucket |
Int | itsLength |
Int | itsNDeleted |
Int | itsUsedLength |
Int | itsNextBucket |
char * | itsData |
char * | itsIntBuf |
Bool | isChanged |
uInt | itsIntSize |
Int | itsLastBucket |
uInt | itsStart |
Store strings in the Standard Storage Manager.
Internal
SSMStringHandler handles strings for the Standard Storage Manager.
Variable length strings cannot be stored in the data bucket. Only short (<8 characters) strings can be stored directly. Class SSMStringhandler is used by the SSM to store strings in so-called string buckets. A string bucket has the following layout:
itsUsedLength
tells how many bytes have been used. Thus it tells the next free byte in the string part. In principle it always increases. Only if data are removed from the last part of the string part, it is decreased, thus the deleted part can be reused again. itsNDeleted
tells how many bytes of the string part are deleted (i.e. not used). Initially it is the length of the string part of the bucket (i.e. bucketsize minus 4 Ints). When a string is stored, its length is subtracted from itsNDeleted. When a string is removed, its length is added again. When the string part is deleted, the bucket is added to the free bucket list. itsNextBucket
tells the next bucket if the last entry in the bucket is continued in another bucket. Normally this field is -1 (meaning not continued), but long strings or string arrays might be continued in another bucket (and continued from there again). The string part is a sequence of bytes containing the string data. When a value is to be stored, it will replace the current value if the new value is not longer. Otherwise the current value (if any) is deleted and the new value is appended to the end of the string part in the last bucket used.
For a scalar string only its characters are stored. Its length (and bucketnr and offset in string bucket) are stored in the data bucket.
A fixed length array is stored as an array of bytes. That byte array contains length-value pairs for each element of the array. The total length (and bucketnr and offset) are stored in the data bucket.
A variable length array is stored as the shape, a flag, optionally followed by the string array as length-value pairs (as above). The shape consists of the nr of dimensions followed by the length of each dimension. The flag indicates if a string array is actually stored. It is not if only the shape of the array is set, but no data put yet.
SSMStringHandler keeps a copy of the current bucket in use to reduce the number of accesses to the bucket cache.
It also keeps the bucket number of the last bucket where data were added to. It tells which bucket to use when new data has to be stored.
Definition at line 120 of file SSMStringHandler.h.
casa::SSMStringHandler::SSMStringHandler | ( | SSMBase * | aBase | ) |
Default constructor initializes last string bucket to -1.
casa::SSMStringHandler::SSMStringHandler | ( | const SSMStringHandler & | ) | [private] |
Forbid copy constructor and assignment.
void casa::SSMStringHandler::flush | ( | ) |
Flush the currently used string bucket.
void casa::SSMStringHandler::get | ( | String & | string, |
Int | bucket, | ||
Int | offset, | ||
Int | length | ||
) |
Get a string or an array of strings.
The array must have the correct shape. handleShape
will be True for variable shaped arrays indicating that the data are preceeded by the shape.
void casa::SSMStringHandler::get | ( | Array< String > & | string, |
Int | bucket, | ||
Int | offset, | ||
Int | length, | ||
Bool | handleShape | ||
) |
void casa::SSMStringHandler::getBucket | ( | uInt | bucketNr, |
Bool | isNew = False |
||
) | [private] |
Get the given bucket and make it current.
It first writes the current bucket if it has changed.
If isNew
is True the bucket is new, so the Ints at its beginning do not have to be interpreted.
void casa::SSMStringHandler::getData | ( | Int | length, |
Char * | data, | ||
Int & | offset | ||
) | [private] |
Get the data with the given length from the curent bucket at the given offset.
If sets the offset to the byte after the data read. Continuation buckets are followed (and made current).
void casa::SSMStringHandler::getNewBucket | ( | Bool | doConcat | ) | [private] |
Get a new bucket and make it current.
If doConcat
is True, the new bucket is a continuation, so itsNextBucket
in the currently used bucket is filled with the new bucket number.
void casa::SSMStringHandler::getShape | ( | IPosition & | aShape, |
Int | bucket, | ||
Int & | offset, | ||
Int | length | ||
) |
Get the shape in the given bucket and offset.
It sets the offset to the data right after the shape. The IPosition object is resized as needed.
void casa::SSMStringHandler::init | ( | ) |
Initialize the StringHandler.
Int casa::SSMStringHandler::lastStringBucket | ( | ) | const [inline] |
Definition at line 256 of file SSMStringHandler.h.
References itsLastBucket.
Referenced by setLastStringBucket().
SSMStringHandler& casa::SSMStringHandler::operator= | ( | const SSMStringHandler & | ) | [private] |
void casa::SSMStringHandler::put | ( | Int & | bucketNr, |
Int & | offset, | ||
Int & | length, | ||
const String & | string | ||
) |
Put a single string or an array of strings into a bucket.
If its length does not exceed the given length, it reuses the currently used space (given by bucketnr and offset). Otherwise it adds the data to the last string bucket. It fills the offset and bucketnr where the data are stored and the length occupied in the buckets. An array of strings is flattened first (a la SSMColumn::writeString).
If handleShape
is True (for variable shaped arrays), the shape will be put first.
void casa::SSMStringHandler::put | ( | Int & | bucketNr, |
Int & | offset, | ||
Int & | length, | ||
const Array< String > & | string, | ||
Bool | handleShape | ||
) |
void casa::SSMStringHandler::putData | ( | Int | length, |
const Char * | data | ||
) | [private] |
Put the data with the given length at the end of the current bucket.
If they do not fit, they are continued in a new bucket.
void casa::SSMStringHandler::putShape | ( | Int & | bucketNr, |
Int & | offset, | ||
Int & | length, | ||
const IPosition & | aShape | ||
) |
Put a single string or an array of strings into a bucket.
If its length does not exceed the given length, it reuses the currently used space (given by bucketnr and offset). Otherwise it adds the data to the last string bucket. It fills the offset and bucketnr where stored and the length occupied in the buckets.
void casa::SSMStringHandler::remove | ( | Int | bucketNr, |
Int | offset, | ||
Int | length | ||
) |
Remove data with the given length from a bucket.
If the data are continued in next bucket(s), they will be removed there as well.
void casa::SSMStringHandler::replace | ( | Int | bucketNr, |
Int | offset, | ||
Int | length, | ||
const String & | string | ||
) | [private] |
Replace the current data with the new data.
It is used by put
after having assured that the new length does not exceed the current one. It follows continuation buckets as needed.
void casa::SSMStringHandler::replace | ( | Int | bucketNr, |
Int | offset, | ||
Int | length, | ||
Int | totalLength, | ||
const IPosition & | aShape | ||
) | [private] |
void casa::SSMStringHandler::replace | ( | Int | bucketNr, |
Int | offset, | ||
Int | length, | ||
Int | totalLength, | ||
const Array< String > & | string, | ||
Bool | handleShape | ||
) | [private] |
void casa::SSMStringHandler::replaceData | ( | Int & | offset, |
Int | length, | ||
const Char * | data | ||
) | [private] |
void casa::SSMStringHandler::resync | ( | ) |
Resynchronize (after a table lock was acquired).
It clears the itsCurrentBucket variable to assure that buckets are reread.
void casa::SSMStringHandler::setLastStringBucket | ( | Int | lastStringBucket | ) | [inline] |
Set or get last string bucketnr.
Setting is needed when an existing table is opened.
Definition at line 251 of file SSMStringHandler.h.
References itsLastBucket, and lastStringBucket().
Bool casa::SSMStringHandler::isChanged [private] |
Definition at line 244 of file SSMStringHandler.h.
Int casa::SSMStringHandler::itsCurrentBucket [private] |
Definition at line 237 of file SSMStringHandler.h.
char* casa::SSMStringHandler::itsData [private] |
Definition at line 242 of file SSMStringHandler.h.
char* casa::SSMStringHandler::itsIntBuf [private] |
Definition at line 243 of file SSMStringHandler.h.
uInt casa::SSMStringHandler::itsIntSize [private] |
Definition at line 245 of file SSMStringHandler.h.
Int casa::SSMStringHandler::itsLastBucket [private] |
Definition at line 246 of file SSMStringHandler.h.
Referenced by lastStringBucket(), and setLastStringBucket().
Int casa::SSMStringHandler::itsLength [private] |
Definition at line 238 of file SSMStringHandler.h.
Int casa::SSMStringHandler::itsNDeleted [private] |
Definition at line 239 of file SSMStringHandler.h.
Int casa::SSMStringHandler::itsNextBucket [private] |
Definition at line 241 of file SSMStringHandler.h.
SSMBase* casa::SSMStringHandler::itsSSMPtr [private] |
Definition at line 236 of file SSMStringHandler.h.
uInt casa::SSMStringHandler::itsStart [private] |
Definition at line 247 of file SSMStringHandler.h.
Int casa::SSMStringHandler::itsUsedLength [private] |
Definition at line 240 of file SSMStringHandler.h.