diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-20 21:23:57 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-09-20 21:23:57 +0100 |
commit | bf3ec07d55f2d6edd3aa0db4c49580d36ac97f49 (patch) | |
tree | 271a6048798ebf2592c418eeb68f6ea26f953d0b | |
parent | Add adhoc factory support (diff) | |
download | libdbpp-bf3ec07d55f2d6edd3aa0db4c49580d36ac97f49.tar.bz2 libdbpp-bf3ec07d55f2d6edd3aa0db4c49580d36ac97f49.tar.xz libdbpp-bf3ec07d55f2d6edd3aa0db4c49580d36ac97f49.zip |
Switch columns collection to forward declared pointer and add helper function for adding columns
-rw-r--r-- | libdbpp/selectcommand.cpp | 22 | ||||
-rw-r--r-- | 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 <boost/multi_index_container.hpp> +#include <boost/multi_index/ordered_index.hpp> 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 <boost/multi_index_container.hpp> +#include <boost/multi_index_container_fwd.hpp> #include <boost/multi_index/indexed_by.hpp> -#include <boost/multi_index/ordered_index.hpp> +#include <boost/multi_index/ordered_index_fwd.hpp> #include <boost/multi_index/member.hpp> #include <visibility.h> @@ -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<ColumnPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique<boost::multi_index::member<DB::Column, const unsigned int, &DB::Column::colNo>>, @@ -28,7 +29,7 @@ namespace DB { >> Columns; protected: - Columns columns; + Columns * columns; }; } |