changes here and there
This commit is contained in:
94
row.cpp
94
row.cpp
@@ -1,53 +1,59 @@
|
||||
|
||||
#include "row.h"
|
||||
|
||||
namespace usql {
|
||||
|
||||
Row::Row(int cols_count) {
|
||||
m_columns.reserve(cols_count);
|
||||
for (int i = 0; i < cols_count; i++) {
|
||||
m_columns.push_back(std::make_unique<ColValue>());
|
||||
}
|
||||
}
|
||||
|
||||
Row::Row(const Row &other) {
|
||||
m_columns.reserve(other.m_columns.size());
|
||||
// TODO fixme this is nonsense
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
m_columns.push_back(std::make_unique<ColNullValue>());
|
||||
Row::Row(int cols_count) {
|
||||
m_columns.reserve(cols_count);
|
||||
for (int i = 0; i < cols_count; i++) {
|
||||
m_columns.push_back(std::make_unique<ColValue>());
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
if (ColIntegerValue* other_v = dynamic_cast<ColIntegerValue*>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->integerValue());
|
||||
}
|
||||
if (ColFloatValue* other_v = dynamic_cast<ColFloatValue*>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->floatValue());
|
||||
}
|
||||
if (ColStringValue* other_v = dynamic_cast<ColStringValue*>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->stringValue());
|
||||
}
|
||||
Row::Row(const Row &other) {
|
||||
m_columns.reserve(other.m_columns.size());
|
||||
// TODO fixme this is nonsense
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
m_columns.push_back(std::make_unique<ColNullValue>());
|
||||
}
|
||||
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
if (ColIntegerValue *other_v = dynamic_cast<ColIntegerValue *>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->integerValue());
|
||||
}
|
||||
if (ColFloatValue *other_v = dynamic_cast<ColFloatValue *>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->floatValue());
|
||||
}
|
||||
if (ColStringValue *other_v = dynamic_cast<ColStringValue *>(other.m_columns[i].get())) {
|
||||
setColumnValue(i, other_v->stringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row& Row::operator=(Row other) {
|
||||
std::swap(m_columns, other.m_columns);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, int value) {
|
||||
m_columns[col_index] = std::make_unique<ColIntegerValue>(value);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, double value) {
|
||||
m_columns[col_index] = std::make_unique<ColFloatValue>(value);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, std::string value) {
|
||||
m_columns[col_index] = std::make_unique<ColStringValue>(value);
|
||||
};
|
||||
|
||||
void Row::print() {
|
||||
for(int i=0; i<m_columns.size(); i++) {
|
||||
m_columns[i].get()->print();
|
||||
Row &Row::operator=(Row other) {
|
||||
std::swap(m_columns, other.m_columns);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, int value) {
|
||||
m_columns[col_index] = std::make_unique<ColIntegerValue>(value);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, double value) {
|
||||
m_columns[col_index] = std::make_unique<ColFloatValue>(value);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(int col_index, std::string value) {
|
||||
m_columns[col_index] = std::make_unique<ColStringValue>(value);
|
||||
};
|
||||
|
||||
void Row::print() {
|
||||
for (int ci = 0; ci < m_columns.size(); ci++) {
|
||||
if (ci > 0) std::cout << ",";
|
||||
auto v = m_columns[ci]->stringValue();
|
||||
std::cout << v;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user