#include "enginedata.h" #include "util.h" #include #include #include using namespace std; RowItem RowItem::copy(const ColHeader &header){ RowItem ri; switch(header.type){ case RH_INT32: ri.v.rh_int32=v.rh_int32; break; case RH_UINT32: ri.v.rh_uint32=v.rh_uint32; break; case RH_BYTES: ri.v.rh_bytes=new unsigned char[header.arg]; memcpy(ri.v.rh_bytes,v.rh_bytes,header.arg); break; } return ri; } Row::Row(void):nc(0),table(NULL){} Row::Row(const int _nc,Table *_t):nc(_nc),table(_t){ items=new RowItem[nc]; } Row::~Row(void){ if(items)delete[] items; } Row::Row(Row &&other):nc(other.nc),table(other.table),items(other.items){ //move constr other.items=nullptr; } Row::Row(const Row &other):nc(other.nc),table(other.table){ //copy constr items=new RowItem[nc]; for(int i=0;iheader[i]); } } Row& Row::operator=(const Row &other){ //copy assignment nc=other.nc; table=other.table; items=new RowItem[nc]; for(int i=0;iheader[i]); } return *this; } ostream& operator<<(ostream &os,const Row &r){ os<<'['; for(int i=0;iheader[i],r.items[i]); } os<<']'; return os; } Table::Table(const string &_n,const int _nc,const ColHeader *const _hd):name(_n),nc(_nc){ header=new ColHeader[nc]; memcpy(header,_hd,nc*sizeof(ColHeader)); } Table::~Table(void){ if(header)delete[] header; } Table::Table(const Table &other):name(other.name),nc(other.nc),rows(other.rows){ memcpy(header,other.header,nc*sizeof(ColHeader)); } Table::Table(Table &&other):name(move(other.name)),nc(other.nc),header(other.header),rows(move(other.rows)){ other.header=nullptr; } string serialise(const ColHeader &header,const RowItem &rowitem){ switch(header.type){ case RH_INT32: return serialise(rowitem.v.rh_int32); case RH_UINT32: return serialise(rowitem.v.rh_uint32); case RH_BYTES: return serialise(rowitem.v.rh_bytes,header.arg); default: assert(false); } } string serialise(int32_t v){return to_string(v);} string serialise(uint32_t v){return to_string(v);} string serialise(unsigned char *v,int len){return string((char*)v,len);} int riCompare(const ColHeader &header,const RowItem &ri1,const RowItem &ri2){ switch(header.type){ case RH_INT32: return riCompare(ri1.v.rh_int32,ri2.v.rh_int32); case RH_UINT32: return riCompare(ri1.v.rh_uint32,ri2.v.rh_uint32); case RH_BYTES: return riCompare(ri1.v.rh_bytes,ri2.v.rh_bytes,header.arg); default: assert(false); } } int riCompare(int32_t v1,int32_t v2){return v1-v2;} int riCompare(uint32_t v1,uint32_t v2){return v1-v2;} int riCompare(unsigned char *v1,unsigned char *v2,int len){ int i; // cerr<<"Comparing "<<(void*)v1<<" ("<