Use std::optional<bool> instead of OptionalBool

This commit is contained in:
louiz’
2018-03-16 01:13:50 +01:00
parent 3f088e7b3a
commit ba879a882e
8 changed files with 41 additions and 58 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ class Database
struct RecordHistory: Column<bool> { static constexpr auto name = "recordhistory_";
RecordHistory(): Column<bool>(true) {}};
struct RecordHistoryOptional: Column<OptionalBool> { static constexpr auto name = "recordhistory_"; };
struct RecordHistoryOptional: Column<std::optional<bool>> { static constexpr auto name = "recordhistory_"; };
struct VerifyCert: Column<bool> { static constexpr auto name = "verifycert_";
VerifyCert(): Column<bool>(true) {} };
+6 -6
View File
@@ -11,11 +11,11 @@ void actual_bind(Statement& statement, const std::int64_t& value, int index)
statement.bind_int64(index, value);
}
void actual_bind(Statement& statement, const OptionalBool& value, int index)
void actual_bind(Statement& statement, const std::optional<bool>& value, int index)
{
if (!value.is_set)
if (!value)
statement.bind_int64(index, 0);
else if (value.value)
else if (*value)
statement.bind_int64(index, 1);
else
statement.bind_int64(index, -1);
@@ -26,11 +26,11 @@ void actual_add_param(Query& query, const std::string& val)
query.params.push_back(val);
}
void actual_add_param(Query& query, const OptionalBool& val)
void actual_add_param(Query& query, const std::optional<bool>& val)
{
if (!val.is_set)
if (!val)
query.params.push_back("0");
else if (val.value)
else if (*val)
query.params.push_back("1");
else
query.params.push_back("-1");
+2 -2
View File
@@ -18,7 +18,7 @@ void actual_bind(Statement& statement, const T& value, int index)
{
actual_bind(statement, static_cast<std::int64_t>(value), index);
}
void actual_bind(Statement& statement, const OptionalBool& value, int index);
void actual_bind(Statement& statement, const std::optional<bool>& value, int index);
#ifdef DEBUG_SQL_QUERIES
#include <utils/scopetimer.hpp>
@@ -71,7 +71,6 @@ void actual_add_param(Query& query, const T& val)
}
void actual_add_param(Query& query, const std::string& val);
void actual_add_param(Query& query, const OptionalBool& val);
template <typename T>
typename std::enable_if<!std::is_integral<T>::value, Query&>::type
@@ -80,6 +79,7 @@ operator<<(Query& query, const T&)
query.body += T::name;
return query;
}
void actual_add_param(Query& query, const std::optional<bool>& val);
Query& operator<<(Query& query, const char* str);
Query& operator<<(Query& query, const std::string& str);
+4 -5
View File
@@ -29,16 +29,15 @@ extract_row_value(Statement& statement, const int i)
}
template <typename T>
typename std::enable_if<std::is_same<OptionalBool, T>::value, T>::type
typename std::enable_if<std::is_same<std::optional<bool>, T>::value, T>::type
extract_row_value(Statement& statement, const int i)
{
const auto integer = statement.get_column_int(i);
OptionalBool result;
if (integer > 0)
result.set_value(true);
return true;
else if (integer < 0)
result.set_value(false);
return result;
return false;
return std::nullopt;
}
template <std::size_t N=0, typename... T>