Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.

Commit e4cd481

Browse files
committed
clean up
1 parent 6e1cd73 commit e4cd481

File tree

15 files changed

+186
-188
lines changed

15 files changed

+186
-188
lines changed

db/detail/meta_ops.hpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <bark/db/meta.hpp>
77
#include <bark/detail/grid.hpp>
8-
#include <bark/detail/unicode.hpp>
98
#include <boost/algorithm/cxx11/any_of.hpp>
109
#include <boost/range/algorithm/find_if.hpp>
1110
#include <boost/range/algorithm/search.hpp>
@@ -39,26 +38,23 @@ template <class Indexes, class ColumnNames>
3938
bool indexed(Indexes&& indexes, ColumnNames&& col_nms)
4039
{
4140
return boost::algorithm::any_of(indexes, [&](auto& idx) {
42-
return boost::range::search(idx.columns,
43-
col_nms,
44-
unicode::case_insensitive_equal_to{}) ==
41+
return boost::range::search(idx.columns, col_nms) ==
4542
idx.columns.begin();
4643
});
4744
}
4845

49-
template <class Rng>
50-
auto find(Rng&& rng, std::string_view name)
46+
template <class Columns>
47+
auto find(Columns&& cols, std::string_view col_nm)
5148
{
52-
return boost::range::find_if(rng, [&](auto& item) {
53-
return unicode::case_insensitive_equal_to{}(name, item.name);
54-
});
49+
return boost::range::find_if(cols,
50+
[=](auto& col) { return col_nm == col.name; });
5551
}
5652

57-
template <class Rng>
58-
auto names(Rng&& rng)
53+
template <class Columns>
54+
auto names(Columns&& cols)
5955
{
60-
return as<std::vector<std::string>>(rng,
61-
[&](auto& item) { return item.name; });
56+
return as<std::vector<std::string>>(cols,
57+
[&](auto& col) { return col.name; });
6258
}
6359

6460
inline geometry::box_rtree make_tiles(size_t count, geometry::box ext)

db/detail/postgres_dialect.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ struct postgres_dialect : dialect {
2525

2626
void columns_sql(sql_builder& bld, const qualified_name& tbl_nm) override
2727
{
28+
auto& tbl = tbl_nm.back();
2829
auto& scm = tbl_nm.at(-2);
2930
bld << "SELECT column_name, LOWER(CASE data_type WHEN "
3031
<< param{"USER-DEFINED"}
3132
<< " THEN udt_name ELSE data_type END), numeric_scale FROM "
3233
"information_schema.columns WHERE table_schema = "
33-
<< param{scm} << " AND table_name = " << param{tbl_nm.back()}
34+
<< param{scm} << " AND table_name = " << param{tbl}
3435
<< " ORDER BY ordinal_position";
3536
}
3637

db/detail/table_guide.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class table_guide {
6868
tbl.columns.push_back(col);
6969
}
7070
if (tbl.columns.empty())
71-
throw std::runtime_error(
72-
"no columns: " + boost::lexical_cast<std::string>(tbl.name));
71+
throw std::runtime_error(concat("no columns: ", tbl.name));
7372
}
7473

7574
void load_indexes(meta::table& tbl)

db/meta.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ inline std::ostream& operator<<(std::ostream& os, const column& col)
5858
if (!col.projection.empty())
5959
opts.push_back(proj::abbreviation(col.projection));
6060
if (!col.tiles.empty())
61-
opts.push_back("BOX" +
62-
boost::lexical_cast<std::string>(
63-
boost::geometry::dsv(bounds(col.tiles))));
61+
opts.push_back(
62+
concat("BOX", boost::geometry::dsv(bounds(col.tiles))));
6463
if (!opts.empty())
6564
os << " (" << list{opts, ", "} << ")";
6665
}

db/mysql/command.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class command : public db::command, private transaction<mysql::command> {
109109
: nullptr};
110110
unsigned cols = res ? mysql_num_fields(res.get()) : 0;
111111

112-
std::vector<std::string> names(cols);
112+
auto names = std::vector<std::string>(cols);
113113
binds_.resize(cols);
114114
memset(binds_.data(), 0, binds_.size() * sizeof(MYSQL_BIND));
115115
cols_.resize(cols);

db/provider.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct provider {
3535

3636
/// Returns a balanced data grid.
3737

38-
/// @param layer is a data set;
38+
/// @param layer is a data set identifier;
3939
/// @param extent is a spatial filter;
4040
/// @param pixel selects the level of the raster pyramid.
4141
virtual geometry::multi_box tile_coverage(const qualified_name& layer,
@@ -45,7 +45,7 @@ struct provider {
4545
/// Returns @ref rowset with spatial data set.
4646

4747
/// Columns @code GEOMETRY[,IMAGE][,ATTRIBUTES...] @endcode
48-
/// @param layer is a data set;
48+
/// @param layer is a data set identifier;
4949
/// @param extent is a spatial filter;
5050
/// @param pixel selects the level of the raster pyramid.
5151
virtual rowset spatial_objects(const qualified_name& layer,
@@ -147,6 +147,13 @@ sql_builder insert_sql(provider& pvd,
147147
return res;
148148
};
149149

150+
inline sql_builder insert_sql(provider& pvd,
151+
const qualified_name& tbl_nm,
152+
const rowset& rows)
153+
{
154+
return insert_sql(pvd, tbl_nm, rows.columns, select(rows));
155+
}
156+
150157
inline sql_builder drop_sql(provider& pvd, const qualified_name& tbl_nm)
151158
{
152159
auto res = builder(pvd);

db/rowset.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,16 @@ inline auto select(const rowset& from)
2828

2929
/// Returns tuples of @ref variant_t
3030
template <class Columns>
31-
auto select(const Columns& columns, const rowset& from)
31+
auto select(const Columns& cols, const rowset& from)
3232
{
33-
auto cols = as<std::vector<std::string>>(
34-
columns, [](const auto& col) { return unicode::to_lower(col); });
35-
36-
auto idxs = as<std::vector<size_t>>(from.columns, [&](const auto& col) {
37-
auto it = std::find(cols.begin(), cols.end(), unicode::to_lower(col));
38-
return std::distance(cols.begin(), it);
33+
auto idxs = as<std::vector<size_t>>(from.columns, [&](auto&& col) {
34+
auto it = std::find(std::begin(cols), std::end(cols), col);
35+
return std::distance(std::begin(cols), it);
3936
});
4037

4138
auto res = std::vector<std::vector<variant_t>>{};
4239
for (auto is = variant_istream{from.data}; !is.data.empty();) {
43-
auto& row = res.emplace_back(cols.size());
40+
auto& row = res.emplace_back(idxs.size());
4441
for (size_t idx : idxs)
4542
if (idx < row.size())
4643
is >> row[idx];

detail/lru_cache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class lru_cache {
4444
auto res = mapped_type::result_of(std::forward<F>(f),
4545
std::forward<Args>(args)...);
4646
insert({scoped_key, res});
47-
return res.get();
47+
return std::move(res).get();
4848
}
4949

5050
template <class Key>

detail/unicode.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ auto to_upper(const Str& str)
7979
return unicode::to_string<range_value_t<Str>>(wstr);
8080
}
8181

82-
struct case_insensitive_equal_to {
83-
template <class Lhs, class Rhs>
84-
bool operator()(const Lhs& lhs, const Rhs& rhs) const
85-
{
86-
return to_lower(lhs) == to_lower(rhs);
87-
}
88-
};
89-
9082
} // namespace bark::unicode
9183

9284
#endif // BARK_UNICODE_HPP

detail/utility.hpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,32 +133,31 @@ constexpr size_t variant_index()
133133
/// expected<T> is either a T or the exception preventing its creation.
134134
template <class T>
135135
class expected {
136+
std::variant<std::exception_ptr, T> val_;
137+
136138
public:
137139
template <class F, class... Args>
138140
static expected result_of(F&& f, Args&&... args) noexcept
139141
{
140142
expected res;
141143
try {
142-
res.state_ =
144+
res.val_ =
143145
std::invoke(std::forward<F>(f), std::forward<Args>(args)...);
144146
}
145-
catch (const std::exception&) {
146-
res.state_ = std::current_exception();
147+
catch (...) {
148+
res.val_ = std::current_exception();
147149
}
148150
return res;
149151
}
150152

151-
T get()
153+
T get() &&
152154
{
153-
return std::visit(overloaded{[](T& val) -> T { return std::move(val); },
154-
[](std::exception_ptr& e) -> T {
155-
std::rethrow_exception(std::move(e));
156-
}},
157-
state_);
155+
return std::visit(
156+
overloaded{
157+
[](std::exception_ptr e) -> T { std::rethrow_exception(e); },
158+
[](T&& val) -> T { return std::move(val); }},
159+
std::move(val_));
158160
}
159-
160-
private:
161-
std::variant<std::exception_ptr, T> state_;
162161
};
163162

164163
/// Joins 'items' by adding user defined separator.
@@ -240,6 +239,11 @@ streamable(T) -> streamable<T>;
240239
/// @see https://en.cppreference.com/w/cpp/named_req/TimedLockable
241240
template <class T, class Hash = std::hash<T>, class Equal = std::equal_to<T>>
242241
class timed_lockable {
242+
T val_;
243+
inline static std::mutex guard_;
244+
inline static std::condition_variable notifier_;
245+
inline static std::unordered_set<T, Hash, Equal> locked_;
246+
243247
public:
244248
explicit timed_lockable(const T& val) : val_{val} {}
245249

@@ -260,12 +264,6 @@ class timed_lockable {
260264
}
261265
notifier_.notify_all();
262266
}
263-
264-
private:
265-
T val_;
266-
inline static std::mutex guard_;
267-
inline static std::condition_variable notifier_;
268-
inline static std::unordered_set<T, Hash, Equal> locked_;
269267
};
270268

271269
} // namespace bark

0 commit comments

Comments
 (0)