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
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/OS/Conversion.h>
33#include <casacore/casa/BasicSL/String.h>
34#include <casacore/casa/Arrays/Array.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations.
39class SSMBase;
40
41
42// <summary>
43// Store strings in the Standard Storage Manager.
44// </summary>
45
46// <use visibility=local>
47
48// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSSMStringHandler.cc">
49// </reviewed>
50
51// <prerequisite>
52//# Classes you should understand before using this one.
53// <li> <linkto class=SSMBase>SSMBase</linkto>
54// </prerequisite>
55
56// <etymology>
57// SSMStringHandler handles strings for the Standard Storage Manager.
58// </etymology>
59
60// <synopsis>
61// Variable length strings cannot be stored in the data bucket.
62// Only short (<8 characters) strings can be stored directly.
63// Class SSMStringhandler is used by the SSM to store strings in
64// so-called string buckets.
65// A string bucket has the following layout:
66// <ul>
67// <li> The first Int is reserved to be used for the free bucket list.
68// <li> <src>itsUsedLength</src> tells how many bytes have been used.
69// Thus it tells the next free byte in the string part.
70// In principle it always increases. Only if data are removed
71// from the last part of the string part, it is decreased, thus
72// the deleted part can be reused again.
73// <li> <src>itsNDeleted</src> tells how many bytes of the string part
74// are deleted (i.e. not used). Initially it is the length of the
75// string part of the bucket (i.e. bucketsize minus 4 Ints).
76// When a string is stored, its length is subtracted from itsNDeleted.
77// When a string is removed, its length is added again.
78// When the string part is deleted, the bucket is added to the
79// free bucket list.
80// <li> <src>itsNextBucket</src> tells the next bucket if the last
81// entry in the bucket is continued in another bucket.
82// Normally this field is -1 (meaning not continued), but long
83// strings or string arrays might be continued in another bucket
84// (and continued from there again).
85// <li> The string part is a sequence of bytes containing the string
86// data. When a value is to be stored, it will replace the current
87// value if the new value is not longer. Otherwise the current
88// value (if any) is deleted and the new value is appended to
89// the end of the string part in the last bucket used.
90// <p>
91// For a scalar string only its characters are stored. Its length
92// (and bucketnr and offset in string bucket) are stored in the data
93// bucket.
94// <br>
95// A fixed length array is stored as an array of bytes. That byte
96// array contains length-value pairs for each element of the array.
97// The total length (and bucketnr and offset) are stored in the data
98// bucket.
99// <br>
100// A variable length array is stored as the shape, a flag, optionally
101// followed by the string array as length-value pairs (as above).
102// The shape consists of the nr of dimensions followed by the
103// length of each dimension. The flag indicates if a string array
104// is actually stored. It is not if only the shape of the array
105// is set, but no data put yet.
106// </ul>
107// SSMStringHandler keeps a copy of the current bucket in use to reduce
108// the number of accesses to the bucket cache.
109// <p>
110// It also keeps the bucket number of the last bucket where data were
111// added to. It tells which bucket to use when new data has to be stored.
112// </synopsis>
113
114//# <todo asof="$DATE:$">
115//# A List of bugs, limitations, extensions or planned refinements.
116//# </todo>
117
119{
120public:
121 // Default constructor initializes last string bucket to -1.
123
125
126 // Forbid copy constructor.
128
129 // Forbid assignment.
131
132 // Set or get last string bucketnr.
133 // Setting is needed when an existing table is opened.
134 // <group>
136 Int lastStringBucket() const;
137 // </group>
138
139 // Put a single string or an array of strings into a bucket.
140 // If its length does not exceed the given length, it reuses
141 // the currently used space (given by bucketnr and offset).
142 // Otherwise it adds the data to the last string bucket.
143 // It fills the offset and bucketnr where the data are stored and the
144 // length occupied in the buckets.
145 // An array of strings is flattened first (a la SSMColumn::writeString).
146 // <br>
147 // If <src>handleShape</src> is True (for variable shaped arrays), the
148 // shape will be put first.
149 // <group>
150 void put (Int& bucketNr, Int& offset, Int& length,
151 const String& string);
152 void put (Int& bucketNr, Int& offset, Int& length,
153 const Array<String>& string, Bool handleShape);
154 // </group>
155
156 // Put a single string or an array of strings into a bucket.
157 // If its length does not exceed the given length, it reuses
158 // the currently used space (given by bucketnr and offset).
159 // Otherwise it adds the data to the last string bucket.
160 // It fills the offset and bucketnr where stored and the
161 // length occupied in the buckets.
162 void putShape (Int& bucketNr, Int& offset, Int& length,
163 const IPosition& aShape);
164
165 // Get the shape in the given bucket and offset.
166 // It sets the offset to the data right after the shape.
167 // The IPosition object is resized as needed.
168 void getShape (IPosition& aShape, Int bucket, Int& offset, Int length);
169
170 // Remove data with the given length from a bucket.
171 // If the data are continued in next bucket(s), they will be
172 // removed there as well.
173 void remove (Int bucketNr, Int offset, Int length);
174
175 // Get a string or an array of strings.
176 // The array must have the correct shape.
177 // <src>handleShape</src> will be True for variable shaped arrays
178 // indicating that the data are preceeded by the shape.
179 // <group>
180 void get (String& string, Int bucket, Int offset, Int length);
181 void get (Array<String>& string, Int bucket, Int offset,
182 Int length, Bool handleShape);
183 // </group>
184
185 // Flush the currently used string bucket.
186 void flush();
187
188 // Initialize the StringHandler
189 void init();
190
191 // Resynchronize (after a table lock was acquired).
192 // It clears the itsCurrentBucket variable to assure that buckets
193 // are reread.
194 void resync();
195
196private:
197 // Get the given bucket and make it current.
198 // It first writes the current bucket if it has changed.
199 // <br>
200 // If <src>isNew</src> is True the bucket is new,
201 // so the Ints at its beginning do not have to be interpreted.
202 void getBucket (uInt bucketNr, Bool isNew=False);
203
204 // Get a new bucket and make it current.
205 // If <src>doConcat</src> is True, the new bucket is a continuation,
206 // so <src>itsNextBucket</src> in the currently used bucket is filled
207 // with the new bucket number.
208 void getNewBucket (Bool doConcat);
209
210 // Put the data with the given length at the end of the current bucket.
211 // If they do not fit, they are continued in a new bucket.
212 void putData (Int length, const Char* data);
213
214 // Get the data with the given length from the curent bucket at the
215 // given offset. If sets the offset to the byte after the data read.
216 // Continuation buckets are followed (and made current).
217 void getData (Int length, Char* data, Int& offset);
218
219 // Replace the current data with the new data.
220 // It is used by <src>put</src> after having assured that the
221 // new length does not exceed the current one.
222 // It follows continuation buckets as needed.
223 // <group>
224 void replace (Int bucketNr, Int offset, Int length,
225 const String& string);
226 void replace (Int bucketNr, Int offset, Int length, Int totalLength,
227 const IPosition& aShape);
228 void replace (Int bucketNr, Int offset, Int length, Int totalLength,
229 const Array<String>& string, Bool handleShape);
230 void replaceData (Int& offset,Int length, const Char* data);
231 // </group>
232
233
234 SSMBase* itsSSMPtr; // Pointer to SSMBase stucture
235 Int itsCurrentBucket; // bucketnr of current string bucket (-1 is none)
236 Int itsLength; // length of bucket in use (only the string part)
237 Int itsNDeleted; // #bytes deleted from the string part of the bucket
238 Int itsUsedLength; // #bytes used from the string part of the bucket
239 Int itsNextBucket; // next bucket for long strings
240 char* itsData; // bucket string data
241 char* itsIntBuf; // buffer for initialisation params
242 Bool isChanged; // has current bucket been changed?
243 uInt itsIntSize; // size of integers in this system
244 Int itsLastBucket; // last string bucket used
245 uInt itsStart; // Start position of actual data in bucket
246};
247
248
249inline void SSMStringHandler::setLastStringBucket (Int lastStringBucket)
250{
252}
253
255{
256 return itsLastBucket;
257}
258
259
260
261} //# NAMESPACE CASACORE - END
262
263#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:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
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