changes here and there

This commit is contained in:
2021-07-12 18:45:51 +02:00
parent 5e69ce1047
commit 5e4480c767
18 changed files with 1692 additions and 1309 deletions

150
row.h
View File

@@ -5,116 +5,128 @@
#include <vector>
class ColumnValue {
namespace usql {
class ColumnValue {
private:
ColumnType m_type;
union {
int int_value;
double float_value;
private:
ColumnType m_type;
union {
int int_value;
double float_value;
};
};
};
struct ColValue {
struct ColValue {
virtual bool isNull() { return false; };
virtual bool isNull() { return false; };
virtual bool isInteger() { return false; };
virtual bool isFloat() { return false; };
virtual bool isString() { return false; };
virtual bool isInteger() { return false; };
virtual int integerValue() { throw Exception("Not supported"); };
virtual double floatValue() { throw Exception("Not supported"); };
virtual std::string stringValue() { throw Exception("Not supported"); };
virtual bool isFloat() { return false; };
virtual void print() {std::cout << "ColValue:" << std::endl; };
};
virtual bool isString() { return false; };
virtual int integerValue() { throw Exception("Not supported"); };
virtual double floatValue() { throw Exception("Not supported"); };
virtual std::string stringValue() { throw Exception("Not supported"); };
};
struct ColNullValue : ColValue {
struct ColNullValue : ColValue {
virtual bool isNull() { return true; };
virtual bool isNull() { return true; };
virtual void print() {std::cout << "ColNullValue:" << std::endl; };
};
virtual std::string stringValue() { return "null"; };
};
struct ColIntegerValue : ColValue {
struct ColIntegerValue : ColValue {
ColIntegerValue(int value) : m_integer(value) {};
ColIntegerValue(const ColIntegerValue &other) : m_integer(other.m_integer) {}
ColIntegerValue(int value) : m_integer(value) {};
virtual bool isInteger() { return true; };
ColIntegerValue(const ColIntegerValue &other) : m_integer(other.m_integer) {}
virtual int integerValue() { return m_integer; };
virtual double floatValue() { return (double) m_integer; };
virtual std::string stringValue() { return std::to_string(m_integer); };
virtual bool isInteger() { return true; };
virtual void print() {std::cout << "ColIntegerValue: " << m_integer <<std::endl; };
virtual int integerValue() { return m_integer; };
int m_integer;
};
virtual double floatValue() { return (double) m_integer; };
virtual std::string stringValue() { return std::to_string(m_integer); };
int m_integer;
};
struct ColFloatValue : ColValue {
struct ColFloatValue : ColValue {
ColFloatValue(double value) : m_float(value) {};
ColFloatValue(const ColFloatValue &other) : m_float(other.m_float) {}
ColFloatValue(double value) : m_float(value) {};
virtual bool isFloat() { return true; }
ColFloatValue(const ColFloatValue &other) : m_float(other.m_float) {}
virtual int integerValue() { return (int) m_float; };
virtual double floatValue() { return m_float; };
virtual std::string stringValue() { return std::to_string(m_float); };
virtual bool isFloat() { return true; }
virtual void print() {std::cout << "ColFloatValue: " << m_float <<std::endl; };
virtual int integerValue() { return (int) m_float; };
double m_float;
};
virtual double floatValue() { return m_float; };
virtual std::string stringValue() { return std::to_string(m_float); };
double m_float;
};
struct ColStringValue : ColValue {
struct ColStringValue : ColValue {
ColStringValue(const std::string value) : m_string(value) {};
ColStringValue(const ColStringValue &other) : m_string(other.m_string) {};
ColStringValue(const std::string value) : m_string(value) {};
virtual bool isString() { return true; }
ColStringValue(const ColStringValue &other) : m_string(other.m_string) {};
virtual int integerValue() { return std::stoi(m_string); };
virtual double floatValue() { return std::stod(m_string); };
virtual std::string stringValue() { return m_string; };
virtual bool isString() { return true; }
virtual void print() {std::cout << "ColStringValue: " << m_string <<std::endl; };
virtual int integerValue() { return std::stoi(m_string); };
std::string m_string;
};
virtual double floatValue() { return std::stod(m_string); };
virtual std::string stringValue() { return m_string; };
std::string m_string;
};
class Row {
class Row {
public:
Row(int cols_count);
public:
Row(int cols_count);
Row(const Row &other);
Row& operator=(Row other);
Row(const Row &other);
void setColumnValue(int col_index, int value);
void setColumnValue(int col_index, double value);
void setColumnValue(int col_index, std::string value);
Row &operator=(Row other);
ColValue& operator[](int i) {
return *m_columns[i];
}
void setColumnValue(int col_index, int value);
ColValue* ithColumn(int i) {
return m_columns[i].get();
}
void setColumnValue(int col_index, double value);
void print();
void setColumnValue(int col_index, std::string value);
private:
std::vector<std::unique_ptr<ColValue>> m_columns;
};
ColValue &operator[](int i) {
return *m_columns[i];
}
ColValue *ithColumn(int i) {
return m_columns[i].get();
}
void print();
private:
std::vector<std::unique_ptr<ColValue>> m_columns;
};
}