casacore
Loading...
Searching...
No Matches
SSMStringHandler.h
Go to the documentation of this file.
1// # SSMStringHandler.h: Store strings in the Standard Storage Manager
2// # Copyright (C) 2000
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_SSMSTRINGHANDLER_H
27#define TABLES_SSMSTRINGHANDLER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/OS/Conversion.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/casa/Arrays/Array.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward Declarations.
38class SSMBase;
39
40// <summary>
41// Store strings in the Standard Storage Manager.
42// </summary>
43
44// <use visibility=local>
45
46// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSSMStringHandler.cc">
47// </reviewed>
48
49// <prerequisite>
50// # Classes you should understand before using this one.
51// <li> <linkto class=SSMBase>SSMBase</linkto>
52// </prerequisite>
53
54// <etymology>
55// SSMStringHandler handles strings for the Standard Storage Manager.
56// </etymology>
57
58// <synopsis>
59// Variable length strings cannot be stored in the data bucket.
60// Only short (<8 characters) strings can be stored directly.
61// Class SSMStringhandler is used by the SSM to store strings in
62// so-called string buckets.
63// A string bucket has the following layout:
64// <ul>
65// <li> The first Int is reserved to be used for the free bucket list.
66// <li> <src>itsUsedLength</src> tells how many bytes have been used.
67// Thus it tells the next free byte in the string part.
68// In principle it always increases. Only if data are removed
69// from the last part of the string part, it is decreased, thus
70// the deleted part can be reused again.
71// <li> <src>itsNDeleted</src> tells how many bytes of the string part
72// are deleted (i.e. not used). Initially it is the length of the
73// string part of the bucket (i.e. bucketsize minus 4 Ints).
74// When a string is stored, its length is subtracted from itsNDeleted.
75// When a string is removed, its length is added again.
76// When the string part is deleted, the bucket is added to the
77// free bucket list.
78// <li> <src>itsNextBucket</src> tells the next bucket if the last
79// entry in the bucket is continued in another bucket.
80// Normally this field is -1 (meaning not continued), but long
81// strings or string arrays might be continued in another bucket
82// (and continued from there again).
83// <li> The string part is a sequence of bytes containing the string
84// data. When a value is to be stored, it will replace the current
85// value if the new value is not longer. Otherwise the current
86// value (if any) is deleted and the new value is appended to
87// the end of the string part in the last bucket used.
88// <p>
89// For a scalar string only its characters are stored. Its length
90// (and bucketnr and offset in string bucket) are stored in the data
91// bucket.
92// <br>
93// A fixed length array is stored as an array of bytes. That byte
94// array contains length-value pairs for each element of the array.
95// The total length (and bucketnr and offset) are stored in the data
96// bucket.
97// <br>
98// A variable length array is stored as the shape, a flag, optionally
99// followed by the string array as length-value pairs (as above).
100// The shape consists of the nr of dimensions followed by the
101// length of each dimension. The flag indicates if a string array
102// is actually stored. It is not if only the shape of the array
103// is set, but no data put yet.
104// </ul>
105// SSMStringHandler keeps a copy of the current bucket in use to reduce
106// the number of accesses to the bucket cache.
107// <p>
108// It also keeps the bucket number of the last bucket where data were
109// added to. It tells which bucket to use when new data has to be stored.
110// </synopsis>
111
112// # <todo asof="$DATE:$">
113// # A List of bugs, limitations, extensions or planned refinements.
114// # </todo>
115
117 public:
118 // Default constructor initializes last string bucket to -1.
120
122
123 // Forbid copy constructor.
125
126 // Forbid assignment.
128
129 // Set or get last string bucketnr.
130 // Setting is needed when an existing table is opened.
131 // <group>
133 Int lastStringBucket() const;
134 // </group>
135
136 // Put a single string or an array of strings into a bucket.
137 // If its length does not exceed the given length, it reuses
138 // the currently used space (given by bucketnr and offset).
139 // Otherwise it adds the data to the last string bucket.
140 // It fills the offset and bucketnr where the data are stored and the
141 // length occupied in the buckets.
142 // An array of strings is flattened first (a la SSMColumn::writeString).
143 // <br>
144 // If <src>handleShape</src> is True (for variable shaped arrays), the
145 // shape will be put first.
146 // <group>
147 void put(Int& bucketNr, Int& offset, Int& length, const String& string);
148 void put(Int& bucketNr, Int& offset, Int& length, const Array<String>& string, Bool handleShape);
149 // </group>
150
151 // Put a single string or an array of strings into a bucket.
152 // If its length does not exceed the given length, it reuses
153 // the currently used space (given by bucketnr and offset).
154 // Otherwise it adds the data to the last string bucket.
155 // It fills the offset and bucketnr where stored and the
156 // length occupied in the buckets.
157 void putShape(Int& bucketNr, Int& offset, Int& length, const IPosition& aShape);
158
159 // Get the shape in the given bucket and offset.
160 // It sets the offset to the data right after the shape.
161 // The IPosition object is resized as needed.
162 void getShape(IPosition& aShape, Int bucket, Int& offset, Int length);
163
164 // Remove data with the given length from a bucket.
165 // If the data are continued in next bucket(s), they will be
166 // removed there as well.
167 void remove(Int bucketNr, Int offset, Int length);
168
169 // Get a string or an array of strings.
170 // The array must have the correct shape.
171 // <src>handleShape</src> will be True for variable shaped arrays
172 // indicating that the data are preceeded by the shape.
173 // <group>
174 void get(String& string, Int bucket, Int offset, Int length);
175 void get(Array<String>& string, Int bucket, Int offset, Int length, Bool handleShape);
176 // </group>
177
178 // Flush the currently used string bucket.
179 void flush();
180
181 // Initialize the StringHandler
182 void init();
183
184 // Resynchronize (after a table lock was acquired).
185 // It clears the itsCurrentBucket variable to assure that buckets
186 // are reread.
187 void resync();
188
189 private:
190 // Get the given bucket and make it current.
191 // It first writes the current bucket if it has changed.
192 // <br>
193 // If <src>isNew</src> is True the bucket is new,
194 // so the Ints at its beginning do not have to be interpreted.
195 void getBucket(uInt bucketNr, Bool isNew = False);
196
197 // Get a new bucket and make it current.
198 // If <src>doConcat</src> is True, the new bucket is a continuation,
199 // so <src>itsNextBucket</src> in the currently used bucket is filled
200 // with the new bucket number.
201 void getNewBucket(Bool doConcat);
202
203 // Put the data with the given length at the end of the current bucket.
204 // If they do not fit, they are continued in a new bucket.
205 void putData(Int length, const Char* data);
206
207 // Get the data with the given length from the curent bucket at the
208 // given offset. If sets the offset to the byte after the data read.
209 // Continuation buckets are followed (and made current).
210 void getData(Int length, Char* data, Int& offset);
211
212 // Replace the current data with the new data.
213 // It is used by <src>put</src> after having assured that the
214 // new length does not exceed the current one.
215 // It follows continuation buckets as needed.
216 // <group>
217 void replace(Int bucketNr, Int offset, Int length, const String& string);
218 void replace(Int bucketNr, Int offset, Int length, Int totalLength, const IPosition& aShape);
219 void replace(Int bucketNr, Int offset, Int length, Int totalLength, const Array<String>& string,
220 Bool handleShape);
221 void replaceData(Int& offset, Int length, const Char* data);
222 // </group>
223
224 SSMBase* itsSSMPtr; // Pointer to SSMBase stucture
225 Int itsCurrentBucket; // bucketnr of current string bucket (-1 is none)
226 Int itsLength; // length of bucket in use (only the string part)
227 Int itsNDeleted; // #bytes deleted from the string part of the bucket
228 Int itsUsedLength; // #bytes used from the string part of the bucket
229 Int itsNextBucket; // next bucket for long strings
230 char* itsData; // bucket string data
231 char* itsIntBuf; // buffer for initialisation params
232 Bool isChanged; // has current bucket been changed?
233 uInt itsIntSize; // size of integers in this system
234 Int itsLastBucket; // last string bucket used
235 uInt itsStart; // Start position of actual data in bucket
236};
237
241
243
244} // namespace casacore
245
246#endif
SSMStringHandler(SSMBase *aBase)
Default constructor initializes last string bucket to -1.
void get(String &string, Int bucket, Int offset, Int length)
Get a string or an array of strings.
void init()
Initialize the StringHandler.
void replaceData(Int &offset, Int length, const Char *data)
void setLastStringBucket(Int lastStringBucket)
Set or get last string bucketnr.
void remove(Int bucketNr, Int offset, Int length)
Remove data with the given length from a bucket.
void get(Array< String > &string, Int bucket, Int offset, Int length, Bool handleShape)
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, Int totalLength, const Array< String > &string, Bool handleShape)
SSMStringHandler & operator=(const SSMStringHandler &)=delete
Forbid assignment.
void resync()
Resynchronize (after a table lock was acquired).
void flush()
Flush the currently used string bucket.
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 putData(Int length, const Char *data)
Put the data with the given length at the end of the current bucket.
void getNewBucket(Bool doConcat)
Get a new bucket and make it current.
void getBucket(uInt bucketNr, Bool isNew=False)
Get the given bucket and make it current.
void put(Int &bucketNr, Int &offset, Int &length, const String &string)
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.
SSMStringHandler(const SSMStringHandler &)=delete
Forbid copy constructor.
void putShape(Int &bucketNr, Int &offset, Int &length, const IPosition &aShape)
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)
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
int offset(int, int) const
compute a linear offset from array indicies
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode length(const LatticeExprNode &expr, const LatticeExprNode &axis)
2-argument function to get the length of an axis.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
char Char
Definition aipstype.h:44