From bf3ec07d55f2d6edd3aa0db4c49580d36ac97f49 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 20 Sep 2015 21:23:57 +0100 Subject: Switch columns collection to forward declared pointer and add helper function for adding columns --- libdbpp/selectcommand.cpp | 22 ++++++++++++++++------ libdbpp/selectcommand.h | 7 ++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/libdbpp/selectcommand.cpp b/libdbpp/selectcommand.cpp index 6cb8759..f6b1d33 100644 --- a/libdbpp/selectcommand.cpp +++ b/libdbpp/selectcommand.cpp @@ -1,5 +1,7 @@ #include "selectcommand.h" #include "error.h" +#include +#include namespace DB { class ColumnIndexOutOfRange : public Error { @@ -17,19 +19,21 @@ namespace DB { }; DB::SelectCommand::SelectCommand(const std::string & sql) : - DB::Command(sql) + DB::Command(sql), + columns(new Columns) { } DB::SelectCommand::~SelectCommand() { + delete columns; } const DB::Column& DB::SelectCommand::operator[](unsigned int n) const { - if (n < columns.size()) { - return **columns.get<0>().find(n); + if (n < columns->size()) { + return **columns->get<0>().find(n); } throw ColumnIndexOutOfRange(n); } @@ -38,8 +42,8 @@ const DB::Column& DB::SelectCommand::operator[](const Glib::ustring & n) const { typedef Columns::nth_index<1>::type CbyName; - CbyName::iterator i = columns.get<1>().find(n); - if (i != columns.get<1>().end()) { + CbyName::iterator i = columns->get<1>().find(n); + if (i != columns->get<1>().end()) { return **i; } throw ColumnDoesNotExist(n); @@ -54,6 +58,12 @@ DB::SelectCommand::getOrdinal(const Glib::ustring & n) const unsigned int DB::SelectCommand::columnCount() const { - return columns.size(); + return columns->size(); +} + +void +DB::SelectCommand::insertColumn(ColumnPtr col) +{ + columns->insert(col); } diff --git a/libdbpp/selectcommand.h b/libdbpp/selectcommand.h index a5788ea..8ebaf9c 100644 --- a/libdbpp/selectcommand.h +++ b/libdbpp/selectcommand.h @@ -3,9 +3,9 @@ #include "command.h" #include "column.h" -#include +#include #include -#include +#include #include #include @@ -21,6 +21,7 @@ namespace DB { const Column & operator[](const Glib::ustring &) const; unsigned int columnCount() const; unsigned int getOrdinal(const Glib::ustring &) const; + void insertColumn(ColumnPtr); typedef boost::multi_index_container>, @@ -28,7 +29,7 @@ namespace DB { >> Columns; protected: - Columns columns; + Columns * columns; }; } -- cgit v1.2.3