using std::variant instead of pointer
This commit is contained in:
40
row.cpp
40
row.cpp
@@ -38,7 +38,7 @@ int ColBooleanValue::compare(ColValue &other) {
|
||||
Row::Row(int cols_count) {
|
||||
m_columns.reserve(cols_count);
|
||||
for (int i = 0; i < cols_count; i++) {
|
||||
m_columns.emplace_back(std::make_unique<ColNullValue>());
|
||||
m_columns.emplace_back(ColNullValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,29 +46,29 @@ Row::Row(const Row &other) {
|
||||
m_columns.reserve(other.m_columns.size());
|
||||
// PERF here we first set cols null and then immediately replace it
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
m_columns.emplace_back(std::make_unique<ColNullValue>());
|
||||
m_columns.emplace_back(ColNullValue());
|
||||
}
|
||||
|
||||
for (int i = 0; i < other.m_columns.size(); i++) {
|
||||
if (other.m_columns[i]->isNull())
|
||||
if (other[i].isNull())
|
||||
continue; // for null NOP
|
||||
|
||||
ColumnType col_type = other.m_columns[i]->getColType();
|
||||
ColumnType col_type = other[i].getColType();
|
||||
switch (col_type) {
|
||||
case ColumnType::integer_type :
|
||||
setIntColumnValue(i, (static_cast<ColIntegerValue *>(other.m_columns[i].get())->getIntValue()));
|
||||
setIntColumnValue(i, other[i].getIntValue());
|
||||
break;
|
||||
case ColumnType::float_type :
|
||||
setFloatColumnValue(i, (static_cast<ColDoubleValue *>(other.m_columns[i].get())->getDoubleValue()));
|
||||
setFloatColumnValue(i, other[i].getDoubleValue());
|
||||
break;
|
||||
case ColumnType::varchar_type :
|
||||
setStringColumnValue(i, (static_cast<ColStringValue *>(other.m_columns[i].get())->getStringValue()));
|
||||
setStringColumnValue(i, other[i].getStringValue());
|
||||
break;
|
||||
case ColumnType::date_type :
|
||||
setDateColumnValue(i, (static_cast<ColDateValue *>(other.m_columns[i].get())->getDateValue()));
|
||||
setDateColumnValue(i, other[i].getDateValue());
|
||||
break;
|
||||
case ColumnType::bool_type :
|
||||
setBoolColumnValue(i, (static_cast<ColBooleanValue *>(other.m_columns[i].get())->getBoolValue()));
|
||||
setBoolColumnValue(i, other[i].getBoolValue());
|
||||
break;
|
||||
default:
|
||||
throw Exception("unsupported column type");
|
||||
@@ -83,36 +83,36 @@ Row &Row::operator=(Row other) {
|
||||
}
|
||||
|
||||
void Row::setColumnNull(int col_index) {
|
||||
m_columns[col_index] = std::make_unique<ColNullValue>();
|
||||
m_columns[col_index] = ColNullValue();
|
||||
}
|
||||
|
||||
void Row::setIntColumnValue(int col_index, long value) {
|
||||
m_columns[col_index] = std::make_unique<ColIntegerValue>(value);
|
||||
m_columns[col_index] = ColIntegerValue(value);
|
||||
}
|
||||
|
||||
void Row::setFloatColumnValue(int col_index, double value) {
|
||||
m_columns[col_index] = std::make_unique<ColDoubleValue>(value);
|
||||
m_columns[col_index] = ColDoubleValue(value);
|
||||
}
|
||||
|
||||
void Row::setStringColumnValue(int col_index, const std::string &value) {
|
||||
m_columns[col_index] = std::make_unique<ColStringValue>(value);
|
||||
m_columns[col_index] = ColStringValue(value);
|
||||
}
|
||||
|
||||
void Row::setDateColumnValue(int col_index, long value) {
|
||||
m_columns[col_index] = std::make_unique<ColDateValue>(value);
|
||||
m_columns[col_index] = ColDateValue(value);
|
||||
}
|
||||
|
||||
void Row::setDateColumnValue(int col_index, const std::string &value) {
|
||||
m_columns[col_index] = std::make_unique<ColDateValue>(Settings::string_to_date(value));
|
||||
m_columns[col_index] = ColDateValue(Settings::string_to_date(value));
|
||||
}
|
||||
|
||||
void Row::setBoolColumnValue(int col_index, bool value) {
|
||||
m_columns[col_index] = std::make_unique<ColBooleanValue>(value);
|
||||
m_columns[col_index] = ColBooleanValue(value);
|
||||
}
|
||||
|
||||
void Row::setBoolColumnValue(int col_index, const std::string &value) {
|
||||
bool v = (value == "Y" || value == "1");
|
||||
m_columns[col_index] = std::make_unique<ColBooleanValue>(v);
|
||||
m_columns[col_index] = ColBooleanValue(v);
|
||||
}
|
||||
|
||||
void Row::setColumnValue(ColDefNode *col_def, ColValue &col_value) {
|
||||
@@ -153,7 +153,7 @@ void Row::setColumnValue(ColDefNode *col_def, ValueNode *col_value) {
|
||||
|
||||
int Row::compare(const Row &other) const {
|
||||
for (int ci = 0; ci < m_columns.size(); ci++) {
|
||||
int cmp = m_columns[ci]->compare(other[ci]);
|
||||
int cmp = this->operator[](ci).compare(other[ci]);
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
return 0;
|
||||
@@ -167,9 +167,9 @@ void Row::print(const std::vector<ColDefNode> &col_defs) {
|
||||
int col_size = print_get_column_size(col_def);
|
||||
|
||||
if (col_def.type==ColumnType::integer_type || col_def.type==ColumnType::float_type || col_def.type==ColumnType::bool_type)
|
||||
out.append(string_padd(m_columns[ci]->getStringValue(), col_size, ' ', false) + " | ");
|
||||
out.append(string_padd(this->operator[](ci).getStringValue(), col_size, ' ', false) + " | ");
|
||||
else
|
||||
out.append(string_padd(m_columns[ci]->getStringValue(), col_size, ' ', true) + " | ");
|
||||
out.append(string_padd(this->operator[](ci).getStringValue(), col_size, ' ', true) + " | ");
|
||||
}
|
||||
|
||||
std::cout << out << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user