From be9362ff9b172e91bc21cfb45b4c3816d9c685a5 Mon Sep 17 00:00:00 2001 From: Elyas El Idrissi Date: Thu, 6 Apr 2023 12:31:37 +0200 Subject: [PATCH] Add support for bool --- include/soci/bool.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 include/soci/bool.h diff --git a/include/soci/bool.h b/include/soci/bool.h new file mode 100644 index 000000000..fc501b318 --- /dev/null +++ b/include/soci/bool.h @@ -0,0 +1,36 @@ +// +// Copyright (C) 2023 Elyas El Idrissi +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef SOCI_BOOL_H_INCLUDED +#define SOCI_BOOL_H_INCLUDED + +#include "soci/type-conversion-traits.h" + +namespace soci +{ + +// simple fall-back for bool +template <> +struct type_conversion +{ + typedef short base_type; + + static void from_base(base_type in, indicator ind, bool & out) + { + out = ind != i_null ? static_cast(in) : false; + } + + static void to_base(bool in, base_type & out, indicator & ind) + { + out = static_cast(in); + ind = i_ok; + } +}; + +} // namespace soci + +#endif // SOCI_BOOL_H_INCLUDED