137 #include "StDbTableDescriptor.h"
140 #include "stdb_streams.h"
144 template <
typename T>
150 #define st_alignof(TYPE) (size_t)&(((StCompilerAlignTest<TYPE>*)0)->m1)
154 StDbTableDescriptor::StDbTableDescriptor(){ init(); }
158 StDbTableDescriptor::StDbTableDescriptor(
int structID,
int schemaID){
169 StDbTableDescriptor::init(){
174 offsetToNextEmptyByte = 0;
175 offsetToLast4Bytes = -4;
181 mschemaID=mstructID=0;
186 mAlign[Stchar] = st_alignof(
char);
187 mAlign[Stuchar] = st_alignof(
unsigned char);
188 mAlign[Stshort] = st_alignof(
short);
189 mAlign[Stushort] = st_alignof(
unsigned short);
190 mAlign[Stint] = st_alignof(
int);
191 mAlign[Stuint] = st_alignof(
unsigned int);
192 mAlign[Stlong] = st_alignof(
long);
193 mAlign[Stulong] = st_alignof(
unsigned long);
194 mAlign[Stlonglong] = st_alignof(
long long);
195 mAlign[Stfloat] = st_alignof(
float);
196 mAlign[Stdouble] = st_alignof(
double);
198 maxAlign = mAlign[Stchar];
206 mCur = (int)d.getNumElements()-1;
207 mMax = d.getCurrentInternalSize();
208 offsetToNextEmptyByte = 0;
209 offsetToLast4Bytes = 0;
210 mcols = d.getTableDescriptor();
211 mnumElements=d.getNumElements();
212 mtableSize = d.getTotalSizeInBytes();
213 mschemaID=d.getSchemaID();
214 mstructID=d.getStructID();
215 misValid=d.IsValid();
216 mhasDouble=d.mhasDouble;
218 rowSizeTT = d.rowSizeTT;
220 mAlign[Stchar] = st_alignof(
char);
221 mAlign[Stuchar] = st_alignof(
unsigned char);
222 mAlign[Stshort] = st_alignof(
short);
223 mAlign[Stushort] = st_alignof(
unsigned short);
224 mAlign[Stint] = st_alignof(
int);
225 mAlign[Stuint] = st_alignof(
unsigned int);
226 mAlign[Stlong] = st_alignof(
long);
227 mAlign[Stulong] = st_alignof(
unsigned long);
228 mAlign[Stlonglong] = st_alignof(
long long);
229 mAlign[Stfloat] = st_alignof(
float);
230 mAlign[Stdouble] = st_alignof(
double);
237 StDbTableDescriptor::getTableDescriptor()
const {
248 StDbTableDescriptor::getCpy(){
257 StDbTableDescriptor::fillElement(
StDbBuffer* buff,
int tableID){
263 if(!(buff->ReadScalar(schemaID,
"schemaID") && (schemaID==tableID)) ){
273 buff->ReadScalar(mname,
"name");
274 if(mname)strcpy(mcols[i].name,mname);
275 if(mname)
delete [] mname;
276 if(buff->ReadScalar(mtype,
"type")){
277 mcols[i].type = getType(mtype);
278 if(mtype)
delete [] mtype;
280 if(buff->ReadScalar(length,
"length"))fillSizeAndOffset(length,i);
281 if(length)
delete [] length;
284 if (mcols[i].type==Stlonglong || mcols[i].type==Stdouble ) mhasDouble=
true;
285 if (getAlign(mcols[i].type) > maxAlign) { maxAlign = getAlign(mcols[i].type); }
293 if ( ( rowpad = offsetToNextEmptyByte%2 ) ) { rowpad = 2 - rowpad; }
298 mtableSize = int(ceil(
float(offsetToNextEmptyByte) /
float(maxAlign)) * maxAlign);
310 StDbTableDescriptor::reSize(){
314 if(mCur<mMax)
return;
316 int newMax = mMax+10;
319 if(mcols)
delete [] mcols;
328 StDbTableDescriptor::fillLengths(
char* length,
int elementNum){
332 char*
id= strstr(length,
",");
336 int k= (int)(
sizeof(mcols[i].dimensionlen)/
sizeof(ip));
337 for(
int j=0;j<k;j++)mcols[i].dimensionlen[j]=1;
341 mcols[i].dimensionlen[ip] = atoi(length);
345 id= strstr(length,
",");
347 mcols[i].dimensionlen[ip]=atoi(length);
354 StDbTableDescriptor::fillSizeAndOffset(
char* length,
int elementNum){
356 fillLengths(length,elementNum);
357 StTypeE type = mcols[elementNum].type;
360 mcols[elementNum].size = getSize(mcols[elementNum].type);
362 int k= (int)(
sizeof(mcols[elementNum].dimensionlen)/
sizeof(j));
363 for (j=0; j<k; j++) mcols[elementNum].size *= mcols[elementNum].dimensionlen[j];
365 int offp = int(ceil(
float(offsetToNextEmptyByte) /
float(getAlign(type))) * getAlign(type));
366 mcols[elementNum].offset = offp;
367 offsetToNextEmptyByte = mcols[elementNum].offset + mcols[elementNum].size;
374 StDbTableDescriptor::getType(
char* type) {
376 StTypeE retVal=Stchar;
379 const char* typenames[] = {
"char",
"uchar",
"short",
"ushort",
"int",
"uint",
"long",
"ulong",
"longlong",
"float",
"double",
"ascii",
"string"};
381 for(
int i=0; i<12;i++){
382 if(strcmp(type,typenames[i])==0){
392 void StDbTableDescriptor::endRowPadding(){
400 int checkPadding=mtableSize%8;
401 if(checkPadding>0 && checkPadding<5)mtableSize+=4;