diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-05-11 21:24:57 +0200 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-05-11 21:24:57 +0200 |
commit | ce356164bac0f739fea97b8bee61c066b9f2ae87 (patch) | |
tree | bf73239c76e0288de9378f06c322766889ef1fb9 /enginedata.cpp | |
parent | bfd76241386fe54c4394171c861f4b1676b5bf32 (diff) |
Add <<debug<< log, clean up some code and let find return a list instead of 1 element
Diffstat (limited to 'enginedata.cpp')
-rw-r--r-- | enginedata.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/enginedata.cpp b/enginedata.cpp index 43a50ce..ecb4c82 100644 --- a/enginedata.cpp +++ b/enginedata.cpp @@ -1,5 +1,7 @@ #include "enginedata.h" +#include "util.h" #include <iostream> +#include <list> #include <cassert> using namespace std; @@ -41,24 +43,26 @@ Table::Table(Table &&other):name(move(other.name)),nc(other.nc),header(other.hea other.header=nullptr; } -void Table::insert(Row &&row){ +bool Table::insert(Row &&row){ string key=serialise(this->header[0],row.items[0]); - cerr<<"Inserting into table '"<<this->name<<"' key="<<key<<" row="<<row<<endl; - rows.emplace(key,move(row)); + cerr<<debug<<"Inserting into table '"<<this->name<<"' key="<<key<<" row="<<row<<endl; + return rows.emplace(key,move(row)).second; } -void Table::insert(Row &row){ +bool Table::insert(Row &row){ string key=serialise(this->header[0],row.items[0]); - cerr<<"Inserting into table '"<<this->name<<"' key="<<key<<" row="<<row<<endl; - rows.emplace(key,row); + cerr<<debug<<"Inserting into table '"<<this->name<<"' key="<<key<<" row="<<row<<endl; + return rows.emplace(key,row).second; } -Maybe<Row> Table::find(const string &key){ +list<Row> Table::find(const string &key){ typedef map<string,Row>::const_iterator cit_t; cit_t end=rows.cend(); + list<Row> ret; for(cit_t it=rows.cbegin();it!=end;it++){ - if(serialise(it->second.table->header[0],it->second.items[0])==key)return Maybe<Row>(it->second); + if(serialise(it->second.table->header[0],it->second.items[0])==key) + ret.emplace_back(it->second); } - return Maybe<Row>(); + return ret; } |