--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#pragma once
+
+#include "type.hxx"
+
+#include <string>
+#include <vector>
+
+namespace qxx {
+namespace internal {
+
+template<typename... Base>
+class ColumnPack {
+public:
+ template<typename ColumnType>
+ std::string getName(ColumnType&&) const noexcept { return std::string(); }
+ std::vector<std::string> getNames(void) const noexcept { return {}; }
+
+ int size() const noexcept { return 0; }
+};
+
+template<typename Front, typename... Rest>
+class ColumnPack<Front, Rest...> : public ColumnPack<Rest...> {
+public:
+ using Column = Front;
+ using TableType = typename Column::TableType;
+
+ explicit ColumnPack(Front&& front, Rest&& ...rest);
+
+ template<typename ColumnType>
+ std::string getName(ColumnType&& type) const noexcept;
+ std::vector<std::string> getNames(void) const noexcept;
+
+ int size() const noexcept { return Base::size() + 1; }
+
+private:
+ using Base = ColumnPack<Rest...>;
+
+ Column column;
+};
+
+template<typename Front, typename... Rest>
+ColumnPack<Front, Rest...>::ColumnPack(Front&& front, Rest&& ...rest) :
+ Base(std::forward<Rest>(rest)...), column(front)
+{
+}
+
+template<typename Front, typename... Rest>
+std::vector<std::string> ColumnPack<Front, Rest...>::getNames(void) const noexcept
+{
+ auto names = Base::getNames();
+ names.emplace_back(this->column.name);
+
+ return names;
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string ColumnPack<Front, Rest...>::getName(ColumnType&& type) const noexcept
+{
+ if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
+ return column.name;
+
+ return Base::template getName<ColumnType>(std::forward<ColumnType>(type));
+}
+
+} // namespace internal
+} // namespace qxx
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#pragma once
-
-#include "table.hxx"
-
-#include <vector>
-#include <set>
-#include <string>
-
-namespace qxx {
-namespace internal {
-
-template<typename... Base>
-class DatabaseImpl {
-public:
- template<typename Table>
- std::string getTableName(Table&&) const noexcept { return std::string(); }
-
- template<typename Column>
- std::string getColumnName(Column&&) const noexcept { return std::string(); }
-};
-
-template<typename Front, typename... Rest>
-class DatabaseImpl<Front, Rest...> : public DatabaseImpl<Rest...> {
-public:
- using Table = Front;
-
- DatabaseImpl(Front&& front, Rest&& ...rest) :
- Base(std::forward<Rest>(rest)...), table(front) {}
-
- Table table;
-
- template<typename Table>
- std::string getTableName(Table&& table) const noexcept
- {
- if (this->table.compare(table))
- return this->table.name;
-
- return Base::template getTableName<Table>(std::forward<Table>(table));
- }
-
- template<typename Column>
- std::string getColumnName(Column&& column) const noexcept
- {
- using ColumnType = typename std::decay<Column>::type;
- using TableType = typename ColumnType::TableType;
- if (this->table.compare(TableType())) {
- auto cname = this->table.getColumnName(column.type);
- return this->table.name + "." + cname;
- }
-
- return Base::template getColumnName<Column>(std::forward<Column>(column));
- }
-
-private:
- using Base = DatabaseImpl<Rest...>;
-};
-
-} // namespace internal
-} // namespace qxx
#include <sstream>
#include <algorithm>
-#include "database-impl.hxx"
+#include "table-pack.hxx"
#include "tuple-helper.hxx"
#include "condition.hxx"
#include "expression.hxx"
std::string name;
private:
- using ImplType = internal::DatabaseImpl<Tables...>;
+ using TablePackType = internal::TablePack<Tables...>;
using ColumnNames = std::vector<std::string>;
using TableNames = std::set<std::string>;
- explicit Database(const std::string& name, ImplType&& impl);
+ explicit Database(const std::string& name, TablePackType&& tablePack);
template<typename ...Ts>
friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
std::vector<std::string> getColumnNames(Cs&& tuple);
struct GetTableNames {
- ImplType impl;
+ TablePackType tablePack;
std::set<std::string> names;
- GetTableNames(const ImplType &_impl) : impl(_impl) {}
+ GetTableNames(const TablePackType& tablePack) : tablePack(tablePack) {}
template <typename T>
void operator()(T&& type)
{
auto column = make_column("anonymous", type);
using TableType = typename decltype(column)::TableType;
- auto name = this->impl.getTableName(TableType());
+ auto name = this->tablePack.getName(TableType());
if (!name.empty())
names.emplace(name);
}
};
struct GetColumnNames {
- ImplType impl;
+ TablePackType tablePack;
std::vector<std::string> names;
- GetColumnNames(const ImplType &_impl) : impl(_impl) {}
+ GetColumnNames(const TablePackType& tablePack) : tablePack(tablePack) {}
template <typename T>
void operator()(T&& type)
{
auto column = make_column("anonymous", type);
- auto name = this->impl.getColumnName(std::move(column));
+ auto name = this->tablePack.getColumnName(std::move(column));
if (!name.empty())
names.emplace_back(name);
}
template<typename Expr>
std::string processWhere(Expr expr);
- ImplType impl;
+ TablePackType tablePack;
std::vector<std::string> cache;
};
template<typename ...Tables>
Database<Tables...> make_database(const std::string& name, Tables&& ...tables)
{
- auto impl = internal::DatabaseImpl<Tables...>(std::forward<Tables>(tables)...);
- return Database<Tables...>(name, std::move(impl));
+ auto tablePack = internal::TablePack<Tables...>(std::forward<Tables>(tables)...);
+ return Database<Tables...>(name, std::move(tablePack));
}
template<typename ...Tables>
-Database<Tables...>::Database(const std::string& name, ImplType&& impl)
- : name(name), impl(std::move(impl)) {}
+Database<Tables...>::Database(const std::string& name, TablePackType&& tablePack)
+ : name(name), tablePack(std::move(tablePack)) {}
template<typename... Tables>
template<typename... ColumnTypes>
std::stringstream ss;
ss << condition::to_string(type) << " ";
ss << "JOIN ";
- ss << this->impl.getTableName(Table());
+ ss << this->tablePack.getName(Table());
this->cache.emplace_back(ss.str());
return *this;
std::stringstream ss;
ss << "ON ";
- auto lname = this->impl.getColumnName(std::move(expr.l));
+ auto lname = this->tablePack.getColumnName(std::move(expr.l));
ss << lname << " ";
ss << std::string(expr) << " ";
- auto rname = this->impl.getColumnName(std::move(expr.r));
+ auto rname = this->tablePack.getColumnName(std::move(expr.r));
ss << rname;
this->cache.emplace_back(ss.str());
template<typename Cs>
std::set<std::string> Database<Tables...>::getTableNames(Cs&& tuple)
{
- GetTableNames closure(this->impl);
+ GetTableNames closure(this->tablePack);
tuple_helper::for_each(std::forward<Cs>(tuple), closure);
return closure.names;
template<typename Cs>
std::vector<std::string> Database<Tables...>::getColumnNames(Cs&& tuple)
{
- GetColumnNames closure(this->impl);
+ GetColumnNames closure(this->tablePack);
tuple_helper::for_each(std::forward<Cs>(tuple), closure);
return closure.names;
std::string Database<Tables...>::processWhere(Expr expr)
{
std::stringstream ss;
- ss << this->impl.getColumnName(expr.l);
+ ss << this->tablePack.getColumnName(expr.l);
ss << " " << std::string(expr) << " ?";
return ss.str();
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-#pragma once
-
-#include "type.hxx"
-
-#include <string>
-#include <vector>
-
-namespace qxx {
-namespace internal {
-
-template<typename... Base>
-class TableImpl {
-public:
- std::vector<std::string> getColumnNames() const noexcept { return {}; }
-
- template<class Type>
- std::string getColumnName(Type&&) const noexcept { return std::string(); }
-
- int size() const noexcept { return 0; }
-};
-
-template<typename Front, typename... Rest>
-class TableImpl<Front, Rest...> : public TableImpl<Rest...> {
-public:
- using Column = Front;
- using TableType = typename Column::TableType;
-
- explicit TableImpl(Front&& front, Rest&& ...rest) :
- Base(std::forward<Rest>(rest)...), column(front) {}
-
- int size() const noexcept { return Base::size() + 1; }
-
- std::vector<std::string> getColumnNames(void) const noexcept
- {
- auto names = Base::getColumnNames();
- names.emplace_back(this->column.name);
- return names;
- }
-
- template<typename ColumnType>
- std::string getColumnName(ColumnType&& type) const noexcept
- {
- if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
- return column.name;
-
- return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(type));
- }
-
-private:
- using Base = TableImpl<Rest...>;
-
- Column column;
-};
-
-} // namespace internal
-} // namespace qxx
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#pragma once
+
+#include <vector>
+#include <set>
+#include <string>
+
+namespace qxx {
+namespace internal {
+
+template<typename... Base>
+class TablePack {
+public:
+ template<typename TableType>
+ std::string getName(TableType&&) const noexcept { return std::string(); }
+
+ template<typename ColumnType>
+ std::string getColumnName(ColumnType&&) const noexcept { return std::string(); }
+};
+
+template<typename Front, typename... Rest>
+class TablePack<Front, Rest...> : public TablePack<Rest...> {
+public:
+ using Table = Front;
+
+ TablePack(Front&& front, Rest&& ...rest);
+
+ template<typename TableType>
+ std::string getName(TableType&& table) const noexcept;
+
+ template<typename ColumnType>
+ std::string getColumnName(ColumnType&& column) const noexcept;
+
+private:
+ using Base = TablePack<Rest...>;
+
+ Table table;
+};
+
+template<typename Front, typename... Rest>
+TablePack<Front, Rest...>::TablePack(Front&& front, Rest&& ...rest) :
+ Base(std::forward<Rest>(rest)...), table(front)
+{
+}
+
+template<typename Front, typename... Rest>
+template<typename TableType>
+std::string TablePack<Front, Rest...>::getName(TableType&& table) const noexcept
+{
+ if (this->table.compare(table))
+ return this->table.name;
+
+ return Base::template getName<TableType>(std::forward<TableType>(table));
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string TablePack<Front, Rest...>::getColumnName(ColumnType&& column) const noexcept
+{
+ using DecayColumnType = typename std::decay<ColumnType>::type;
+ using DecayTableType = typename DecayColumnType::TableType;
+ if (this->table.compare(DecayTableType())) {
+ auto cname = this->table.getColumnName(column.type);
+ return this->table.name + "." + cname;
+ }
+
+ return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(column));
+}
+
+} // namespace internal
+} // namespace qxx
#pragma once
#include "column.hxx"
-#include "table-impl.hxx"
+#include "column-pack.hxx"
#include "tuple-helper.hxx"
#include "expression.hxx"
#include "util.hxx"
class Table {
public:
using Self = Table<Columns...>;
- using ImplType = internal::TableImpl<Columns...>;
- using TableType = typename ImplType::TableType;
+ using ColumnPackType = internal::ColumnPack<Columns...>;
+ using TableType = typename ColumnPackType::TableType;
template<typename... ColumnTypes>
Self& select(ColumnTypes&&... cts);
std::string name;
private:
- explicit Table(const std::string& name, ImplType&& impl);
+ explicit Table(const std::string& name, ColumnPackType&& columnPack);
template<typename ...Cs>
friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
std::vector<std::string> getColumnNames(void) const noexcept;
struct GetColumnNames {
- ImplType impl;
+ ColumnPackType columnPack;
std::vector<std::string> names;
- GetColumnNames(const ImplType &impl) : impl(impl) {}
+ GetColumnNames(const ColumnPackType& columnPack) : columnPack(columnPack) {}
template <typename T>
void operator()(T&& type)
{
- auto name = this->impl.getColumnName(std::forward<T>(type));
+ auto name = this->columnPack.getName(std::forward<T>(type));
if (!name.empty())
names.emplace_back(name);
}
template<typename Expr>
std::string processWhere(Expr expr);
- ImplType impl;
+ ColumnPackType columnPack;
std::vector<std::string> cache;
};
template<typename ...Columns>
Table<Columns...> make_table(const std::string& name, Columns&& ...cs)
{
- auto impl = internal::TableImpl<Columns...>(std::forward<Columns>(cs)...);
- return Table<Columns...>(name, std::move(impl));
+ auto columnPack = internal::ColumnPack<Columns...>(std::forward<Columns>(cs)...);
+ return Table<Columns...>(name, std::move(columnPack));
}
template<typename... Columns>
-Table<Columns...>::Table(const std::string& name, ImplType&& impl)
- : name(name), impl(std::move(impl)) {}
+Table<Columns...>::Table(const std::string& name, ColumnPackType&& columnPack)
+ : name(name), columnPack(std::move(columnPack)) {}
template<typename... Columns>
template<typename... ColumnTypes>
template<typename Cs>
std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& tuple)
{
- GetColumnNames closure(this->impl);
+ GetColumnNames closure(this->columnPack);
tuple_helper::for_each(std::forward<Cs>(tuple), closure);
return closure.names;
template<typename... Columns>
int Table<Columns...>::size() const noexcept
{
- return this->impl.size();
+ return this->columnPack.size();
}
template<typename... Columns>
std::vector<std::string> Table<Columns...>::getColumnNames(void) const noexcept
{
- return this->impl.getColumnNames();
+ return this->columnPack.getNames();
}
template<typename... Columns>
template<typename ColumnType>
std::string Table<Columns...>::getColumnName(ColumnType&& type) const noexcept
{
- return this->impl.getColumnName(std::forward<ColumnType>(type));
+ return this->columnPack.getName(std::forward<ColumnType>(type));
}
template<typename... Columns>
std::string Table<Columns...>::processWhere(Expr expr)
{
std::stringstream ss;
- ss << this->impl.getColumnName(expr.l.type);
+ ss << this->columnPack.getName(expr.l.type);
ss << " " << std::string(expr) << " ?";
return ss.str();