using std::variant instead of pointer
This commit is contained in:
25
row.h
25
row.h
@@ -4,6 +4,7 @@
|
||||
#include "parser.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace usql {
|
||||
@@ -119,6 +120,8 @@ namespace usql {
|
||||
bool m_bool;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Row {
|
||||
|
||||
public:
|
||||
@@ -139,14 +142,32 @@ namespace usql {
|
||||
void setColumnValue(ColDefNode *col_def, ColValue &col_value);
|
||||
void setColumnValue(ColDefNode *col_def, ValueNode *col_value);
|
||||
|
||||
ColValue &operator[](int i) const { return *m_columns[i]; }
|
||||
ColValue &operator[](int i) const {
|
||||
auto type_index = m_columns[i].index();
|
||||
switch (type_index) {
|
||||
case 0:
|
||||
return (ColValue &) *std::get_if<ColNullValue>(&m_columns[i]);
|
||||
case 1:
|
||||
return (ColValue &) *std::get_if<ColIntegerValue>(&m_columns[i]);
|
||||
case 2:
|
||||
return (ColValue &) *std::get_if<ColDoubleValue>(&m_columns[i]);
|
||||
case 3:
|
||||
return (ColValue &) *std::get_if<ColStringValue>(&m_columns[i]);
|
||||
case 4:
|
||||
return (ColValue &) *std::get_if<ColDateValue>(&m_columns[i]);
|
||||
case 5:
|
||||
return (ColValue &) *std::get_if<ColBooleanValue>(&m_columns[i]);
|
||||
}
|
||||
throw Exception("should not happen");
|
||||
}
|
||||
|
||||
int compare(const Row &other) const;
|
||||
|
||||
void print(const std::vector<ColDefNode> &col_defs);
|
||||
static int print_get_column_size(const ColDefNode &col_def);
|
||||
private:
|
||||
std::vector<std::unique_ptr<ColValue>> m_columns;
|
||||
// xx std::vector<std::unique_ptr<ColValue>> m_columns;
|
||||
std::vector<std::variant<ColNullValue, ColIntegerValue, ColDoubleValue, ColStringValue, ColDateValue, ColBooleanValue>> m_columns;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user