#include "attrtype.hpp" struct Attribute { Attribute(unsigned t, unsigned s, const char *n) ~Attribute(); unsigned type; unsigned size; char name[64]; }; class TupleLayout { TupleLayout(const TupleLayout&); //dont copy TupleLayout& operator=(const TupleLayout&); //dont copy public: TupleLayout(int vrs); virtual ~TupleLayout(); const Attribute& operator[](int i) const { return a[i]; } void * queryPointer(int i, void *buf) const; const void *queryPointer(int i, const void *buf) const { return queryPointer(i,(void*)buf); } int count() const { return as; } TupleLayout& operator+=(const Attribute &na); private: Attribute *a; int *offset; int attributes; int variablerecsize; }; static const int typesize[]= 0, //not used sizeof(bool), sizeof(uint8), sizeof(sint8), sizeof(uint16), sizeof(sint16), sizeof(uint32), sizeof(sint32), sizeof(uint64), sizeof(float32), sizeof(float64), sizeof(float80), sizeof(decimal), 0, //char may be variable size 0, //varchar has variable size 0 //binary has per-table-fixed size, byt system-wide variable size }; Attribute::Attribute(unsigned t, unsigned s, const char *n) { type = t; if(t!=ATTRTYPE_VARCHAR) size = typesize[t]; else size = s; strcpy(name,n); } TupleLayout::TupleLayout(int vrs) : a(0), offset(0), attributes(0), variablerecsize(vrs) { } TupleLayout::~TupleLayout() { delete[] a; delete[] offset; } TupleLayout& TupleLayout::operator+=(const Attribute &newa) { Attribute *na = (Attribute*) new char[sizeof(Attribute)*(as+1)]; memcpy(na,a,sizeof(Attribute)*as); int *noffset; if(!variablerecsize) { noffset = new int[as+1]; memcpy(noffset,offset,sizeof(int)*as); } else noffset=0; delete[] a; delete[] offset; a = na; offset = noffset; a[as] = newa; if(!variablerecsize) { if(as>0) offset[as] = offset[as-1] + a[as-1].size; else offset[as] = a[as-1].size; } as++; } void *TupleLayout::queryPointer(int i, void *buf) const { char *p=(char*)buf; if(variablerecsize) { for(int j=0; j