aboutsummaryrefslogtreecommitdiff
path: root/enginedata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'enginedata.cpp')
-rw-r--r--enginedata.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/enginedata.cpp b/enginedata.cpp
index 5cc357f..8b4d3fa 100644
--- a/enginedata.cpp
+++ b/enginedata.cpp
@@ -6,6 +6,23 @@
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,const Table *const _t):nc(_nc),table(_t){
items=new RowItem[nc];
@@ -18,12 +35,9 @@ Row::Row(Row &&other):nc(other.nc),table(other.table),items(other.items){ //move
}
Row::Row(const Row &other):nc(other.nc),table(other.table){ //copy constr
items=new RowItem[nc];
- memcpy(items,other.items,nc*sizeof(RowItem));
+ //memcpy(items,other.items,nc*sizeof(RowItem));
for(int i=0;i<nc;i++){
- if(table->header[i].type==RH_BYTES){
- items[i].rh_bytes=new unsigned char[table->header[i].arg];
- memcpy(items[i].rh_bytes,other.items[i].rh_bytes,table->header[i].arg);
- }
+ items[i]=other.items[i].copy(table->header[i]);
}
}
ostream& operator<<(ostream &os,const Row &r){
@@ -55,9 +69,9 @@ Table::Table(Table &&other):name(move(other.name)),nc(other.nc),header(other.hea
string serialise(const ColHeader &header,const RowItem &rowitem){
switch(header.type){
- case RH_INT32: return serialise(rowitem.rh_int32);
- case RH_UINT32: return serialise(rowitem.rh_uint32);
- case RH_BYTES: return serialise(rowitem.rh_bytes,header.arg);
+ 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);
}
}
@@ -67,9 +81,9 @@ 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.rh_int32,ri2.rh_int32);
- case RH_UINT32: return riCompare(ri1.rh_uint32,ri2.rh_uint32);
- case RH_BYTES: return riCompare(ri1.rh_bytes,ri2.rh_bytes,header.arg);
+ 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);
}
}