Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
yangacer committed Jun 20, 2019
1 parent d5f2003 commit 91a5111
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 44 deletions.
21 changes: 8 additions & 13 deletions sqlite3cpp.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace sqlite3cpp {
namespace detail {
// An tag type for row iter session
struct session {};
} // namespace detail
} // namespace detail

/**
* row_iter impl
Expand All @@ -61,10 +61,8 @@ row_iter::row_iter(cursor &csr, std::weak_ptr<void> session) noexcept
}

row_iter &row_iter::operator++() {
if (!m_session.expired())
m_csr->step();
if (m_session.expired())
m_csr = nullptr;
if (!m_session.expired()) m_csr->step();
if (m_session.expired()) m_csr = nullptr;
return *this;
}

Expand Down Expand Up @@ -115,13 +113,12 @@ void cursor::step() {
}

row_iter cursor::begin() noexcept {
if (!m_stmt)
return {};
if (!m_stmt) return {};
// NOTE(acer): There is actually a redundant reset as we invoke
// |execute().begin()|. It's possible to be eliminated, though I keep it for
// ensuring non-query SQL can be executed right away after calling |execute()|.
// Besides, results of previous |step()| should be cached by sqlite3 s.t.
// performance penality would be minor.
// ensuring non-query SQL can be executed right away after calling
// |execute()|. Besides, results of previous |step()| should be cached by
// sqlite3 s.t. performance penality would be minor.
m_session.reset((void *)new detail::session,
[](void *s) { delete (detail::session *)s; });
sqlite3_reset(m_stmt.get());
Expand All @@ -148,9 +145,7 @@ transaction::~transaction() {
}
}

void transaction::commit() noexcept {
m_params.end_sql = "end";
}
void transaction::commit() noexcept { m_params.end_sql = "end"; }

/**
* database impl
Expand Down
20 changes: 10 additions & 10 deletions sqlite3cpp.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct SQLITE3CPP_EXPORT transaction {
// will be executed right away. The |end_sql| will be executed in
// |~transaction()|.
transaction(database &db, params_t const &params);
transaction(transaction&&) = default;
transaction(transaction &&) = default;

// Commit or rollback this transaction per |params|. Default to rollback.
~transaction();
Expand Down Expand Up @@ -262,15 +262,15 @@ struct SQLITE3CPP_EXPORT database {
std::string version() const;

private:
using xfunc_t = std::function<void(sqlite3_context *, int, sqlite3_value **)>;
using xfinal_t = std::function<void(sqlite3_context *)>;
using xreset_t = std::function<void()>;

struct aggregate_wrapper_t {
xfunc_t step;
xfinal_t fin;
xreset_t reset;
xreset_t release;
using xfunc_t = std::function<void(sqlite3_context *, int, sqlite3_value **)>;
using xfinal_t = std::function<void(sqlite3_context *)>;
using xreset_t = std::function<void()>;

struct aggregate_wrapper_t {
xfunc_t step;
xfinal_t fin;
xreset_t reset;
xreset_t release;
};

static void forward(sqlite3_context *ctx, int argc, sqlite3_value **argv);
Expand Down
38 changes: 17 additions & 21 deletions sqlite3cpp.ipp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ namespace detail {
template <int>
struct placeholder_tmpl {};

template<int... Ints>
template <int... Ints>
using indexes = std::integer_sequence<int, Ints...>;

template<int Max>
template <int Max>
using make_indexes_t = std::make_integer_sequence<int, Max>;
}
} // namespace sqlite3cpp::detail
} // namespace detail
} // namespace sqlite3cpp

// custome placeholders
namespace std {
template <int N>
struct is_placeholder<sqlite3cpp::detail::placeholder_tmpl<N>>
: integral_constant<int, N + 1> {};
}
} // namespace std

namespace sqlite3cpp {
namespace detail {
Expand Down Expand Up @@ -94,11 +94,10 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *, int index,

inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index,
std::string &val) {
char const* res = (char const *)sqlite3_column_text(stmt, index);
char const *res = (char const *)sqlite3_column_text(stmt, index);
if (!res) {
int ec = sqlite3_errcode(db);
if (ec != SQLITE_OK)
throw error(ec);
if (ec != SQLITE_OK) throw error(ec);
}
val.assign(res, sqlite3_column_bytes(stmt, index));
}
Expand All @@ -108,8 +107,7 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index,
char const *res = (char const *)sqlite3_column_text(stmt, index);
if (!res) {
int ec = sqlite3_errcode(db);
if (ec != SQLITE_OK)
throw error(ec);
if (ec != SQLITE_OK) throw error(ec);
}
val = std::string_view{
(char const *)sqlite3_column_text(stmt, index),
Expand All @@ -118,11 +116,10 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index,

inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index,
std::optional<std::string> &val) {
char const* res = (char const *)sqlite3_column_text(stmt, index);
char const *res = (char const *)sqlite3_column_text(stmt, index);
if (!res) {
int ec = sqlite3_errcode(db);
if (ec != SQLITE_OK)
val.reset();
if (ec != SQLITE_OK) val.reset();
}
val = std::string{res,
(std::string::size_type)sqlite3_column_bytes(stmt, index)};
Expand All @@ -133,8 +130,7 @@ inline void get_col_val_aux(sqlite3_stmt *stmt, sqlite3 *db, int index,
char const *res = (char const *)sqlite3_column_text(stmt, index);
if (!res) {
int ec = sqlite3_errcode(db);
if (ec != SQLITE_OK)
val.reset();
if (ec != SQLITE_OK) val.reset();
}
val = std::string_view{
res, (std::string_view::size_type)sqlite3_column_bytes(stmt, index)};
Expand Down Expand Up @@ -172,8 +168,7 @@ inline int bind_val(sqlite3_stmt *stmt, int index, std::nullptr_t _) {
template <typename T, typename... Args>
void bind_to_stmt(sqlite3_stmt *stmt, int index, T &&val, Args &&... args) {
int ec = 0;
if (0 != (ec = bind_val(stmt, index, std::forward<T>(val))))
throw error(ec);
if (0 != (ec = bind_val(stmt, index, std::forward<T>(val)))) throw error(ec);
bind_to_stmt(stmt, index + 1, std::forward<Args>(args)...);
}

Expand All @@ -200,7 +195,8 @@ inline std::string get(Type<std::string>, sqlite3_value **v, int const index) {
(size_t)sqlite3_value_bytes(v[index]));
}

inline std::string_view get(Type<std::string_view>, sqlite3_value **v, int const index) {
inline std::string_view get(Type<std::string_view>, sqlite3_value **v,
int const index) {
return std::string_view((char const *)sqlite3_value_text(v[index]),
(size_t)sqlite3_value_bytes(v[index]));
}
Expand Down Expand Up @@ -296,8 +292,8 @@ typename function_traits<F>::f_type bind_this(F f, C *this_) {
using traits = function_traits<F>;
return bind_this(f, this_, make_indexes_t<traits::arity>{});
}
}
} // namespace sqlite3cpp::detail
} // namespace detail
} // namespace sqlite3cpp

namespace sqlite3cpp {

Expand Down Expand Up @@ -362,8 +358,8 @@ void database::create_scalar(std::string const &name, FUNC func, int flags) {

template <typename AG>
void database::create_aggregate(std::string const &name, int flags) {
using detail::make_invoker;
using detail::bind_this;
using detail::make_invoker;
using detail::result;
using traits = detail::function_traits<decltype(&AG::step)>;

Expand Down

0 comments on commit 91a5111

Please sign in to comment.