use unique_ptr<string> in ColStringValue to save space in variant

This commit is contained in:
2021-08-17 15:04:27 +02:00
parent 7685d0bb37
commit 0a0e4af8b3
5 changed files with 28 additions and 29 deletions

18
row.h
View File

@@ -73,19 +73,21 @@ namespace usql {
struct ColStringValue : ColValue {
explicit ColStringValue(const std::string &value) : m_string(value) {};
ColStringValue(const ColStringValue &other) : m_string(other.m_string) {};
explicit ColStringValue(const std::string &value) : m_string(std::make_unique<std::string>(value)) {};
ColStringValue(const ColStringValue &other) : m_string(std::make_unique<std::string>(*other.m_string)) {};
ColStringValue & operator=(ColStringValue other);
ColumnType getColType() override { return ColumnType::varchar_type; };
long getIntValue() override { return std::stoi(m_string); };
double getDoubleValue() override { return std::stod(m_string); };
std::string getStringValue() override { return m_string; };
long getDateValue() override { return std::stoi(m_string); };
long getIntValue() override { return std::stoi(*m_string); };
double getDoubleValue() override { return std::stod(*m_string); };
std::string getStringValue() override { return *m_string; };
long getDateValue() override { return std::stoi(*m_string); };
bool getBoolValue() override { throw Exception("Not supported on ColStringValue"); };
int compare(ColValue &other) override;
std::string m_string;
std::unique_ptr<std::string> m_string;
};
struct ColDateValue : ColValue {
@@ -125,7 +127,7 @@ namespace usql {
class Row {
public:
explicit Row(int cols_count);
explicit Row(int cols_count) : m_columns(cols_count, ColNullValue()) {};
Row(const Row &other);
Row &operator=(Row other);