From 82407c1c4c9526e7dc408e936478c8619ded8c66 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 11 May 2015 18:39:56 +0200 Subject: Fix up makefile and add functional insert and find implementation --- enginedata.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'enginedata.cpp') diff --git a/enginedata.cpp b/enginedata.cpp index f1e9b2c..43a50ce 100644 --- a/enginedata.cpp +++ b/enginedata.cpp @@ -1,21 +1,32 @@ #include "enginedata.h" +#include +#include using namespace std; -Row::Row(const int nc,const Table *const _t):table(_t){ +Row::Row(const int _nc,const Table *const _t):nc(_nc),table(_t){ items=new RowItem[nc]; } Row::~Row(void){ if(items)delete[] items; } -Row::Row(Row &&other):table(other.table),items(other.items){ //move constr - other.table=NULL; - other.items=NULL; +Row::Row(Row &&other):nc(other.nc),table(other.table),items(other.items){ //move constr + other.table=nullptr; + other.items=nullptr; } -Row::Row(const Row &other):table(other.table){ //copy constr +Row::Row(const Row &other):nc(other.nc),table(other.table){ //copy constr items=new RowItem[table->nc]; memcpy(items,other.items,table->nc*sizeof(RowItem)); } +ostream& operator<<(ostream &os,const Row &r){ + os<<'['; + for(int i=0;iheader[i],r.items[i]); + } + os<<']'; + return os; +} //copies from _hd, so you can freely delete or edit the passed colheader array @@ -27,12 +38,42 @@ Table::~Table(void){ if(header)delete[] header; } Table::Table(Table &&other):name(move(other.name)),nc(other.nc),header(other.header),rows(move(other.rows)){ - other.header=NULL; + other.header=nullptr; } void Table::insert(Row &&row){ - rows.push_back(move(row)); + string key=serialise(this->header[0],row.items[0]); + cerr<<"Inserting into table '"<name<<"' key="<name<<"' key="<