another ugly basic implementation

This commit is contained in:
2021-07-04 15:03:13 +02:00
parent b55115f7c3
commit b4711985b3
12 changed files with 417 additions and 60 deletions

View File

@@ -7,22 +7,40 @@ Table::Table(const std::string name, const std::vector<ColDefNode> columns) {
m_rows.clear();
}
ColDefNode Table::get_column_def(const std::string col_name) {
ColDefNode Table::get_column_def(const std::string& col_name) {
auto name_cmp = [col_name](ColDefNode cd){ return cd.name == col_name; };
auto col_def = std::find_if(begin(m_col_defs), end(m_col_defs), name_cmp );
if (col_def != std::end(m_col_defs)) {
return *col_def;
} else {
// TODO throw exception
throw Exception("column not exists (" + col_name + ")");
}
}
Row Table::createEmptyRow() {
return Row(columns_count());
}
void Table::print() {
std::cout << "** " << m_name << " **" << std::endl;
for(auto row : m_rows) {
for( auto col : row) {
std::cout << col << ",";
for(int ci = 0; ci < columns_count(); ci++) {
auto v = row[ci].stringValue();
std::cout << v << ",";
}
std::cout << std::endl;
}
}
}
Table::Table(const Table& other) {
m_name = other.m_name;
m_col_defs = other.m_col_defs;
m_rows.clear(); // row not copied now
}
void Table::addRow(const Row &row) {
m_rows.push_back(row);
}