47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
|
|
#include "table.h"
|
|
|
|
Table::Table(const std::string name, const std::vector<ColDefNode> columns) {
|
|
m_name = name;
|
|
m_col_defs = columns;
|
|
m_rows.clear();
|
|
}
|
|
|
|
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 {
|
|
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(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);
|
|
}
|
|
|