#include "table.hpp"
using namespace sqlpp;
Table::Table(const std::string& create_cmd):_create_cmd(create_cmd),_index_is_string(false)
{
}
Table::~Table()
{
}
std::vector<row_digit>& Table::get_rows(void)throw()
{
if (_index_is_string)
{
trans_to_digit();
}
return _rows;
}
std::vector<row_string>& Table::get_rows_index_string(void)throw()
{
if (!_index_is_string)
{
trans_to_string();
}
return _rows_string;
}
field_list& Table::get_fields(void) throw()
{
return _fields;
}
const std::string& Table::get_create_cmd(void)const throw()
{
return _create_cmd;
}
const std::vector<std::string>& Table::get_update_cmds(void)const throw()
{
return _update_cmds;
}
void Table::trans_to_digit(void)throw()
{
_rows.clear();
_rows.resize(_rows_string.size());
row_digit row;
while (!_rows_string.empty())
{
for (int k=0; k<_fields.size(); k++)
{
row[k] = _rows_string.front()[_fields[k]];
}
_rows_string.erase(_rows_string.begin());
_rows.push_back(row);
}
}
void Table::trans_to_string(void)throw()
{
_rows_string.clear();
//for save time
_rows_string.resize(_rows.size());
row_string row;
//assign a row,delete it,for save space
while (!_rows.empty())
{
for (int k=0; k<_fields.size(); k++)
{
row[_fields[k]] = _rows.front()[k];
}
_rows.erase(_rows.begin());
_rows_string.push_back(row);
}
_index_is_string = true;
}
using namespace sqlpp;
Table::Table(const std::string& create_cmd):_create_cmd(create_cmd),_index_is_string(false)
{
}
Table::~Table()
{
}
std::vector<row_digit>& Table::get_rows(void)throw()
{
if (_index_is_string)
{
trans_to_digit();
}
return _rows;
}
std::vector<row_string>& Table::get_rows_index_string(void)throw()
{
if (!_index_is_string)
{
trans_to_string();
}
return _rows_string;
}
field_list& Table::get_fields(void) throw()
{
return _fields;
}
const std::string& Table::get_create_cmd(void)const throw()
{
return _create_cmd;
}
const std::vector<std::string>& Table::get_update_cmds(void)const throw()
{
return _update_cmds;
}
void Table::trans_to_digit(void)throw()
{
_rows.clear();
_rows.resize(_rows_string.size());
row_digit row;
while (!_rows_string.empty())
{
for (int k=0; k<_fields.size(); k++)
{
row[k] = _rows_string.front()[_fields[k]];
}
_rows_string.erase(_rows_string.begin());
_rows.push_back(row);
}
}
void Table::trans_to_string(void)throw()
{
_rows_string.clear();
//for save time
_rows_string.resize(_rows.size());
row_string row;
//assign a row,delete it,for save space
while (!_rows.empty())
{
for (int k=0; k<_fields.size(); k++)
{
row[_fields[k]] = _rows.front()[k];
}
_rows.erase(_rows.begin());
_rows_string.push_back(row);
}
_index_is_string = true;
}