From d218bc49e69e7b5be9a1baa257225e8b21c8d1b7 Mon Sep 17 00:00:00 2001 From: Elyas El Idrissi Date: Thu, 6 Apr 2023 12:31:57 +0200 Subject: [PATCH] Add support for std::filesystem::path --- include/soci/std-path.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 include/soci/std-path.h diff --git a/include/soci/std-path.h b/include/soci/std-path.h new file mode 100644 index 000000000..7351e856d --- /dev/null +++ b/include/soci/std-path.h @@ -0,0 +1,39 @@ +// +// 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_STD_PATH_H_INCLUDED +#define SOCI_STD_PATH_H_INCLUDED + +#include "soci/type-conversion-traits.h" + +#include +#include + +namespace soci +{ + +// simple fall-back for std::filesystem::path +template <> +struct type_conversion +{ + typedef std::string base_type; + + static void from_base(base_type in, indicator ind, std::filesystem::path & out) + { + out = ind != i_null ? std::filesystem::path{in} : std::filesystem::path{}; + } + + static void to_base(std::filesystem::path in, base_type & out, indicator & ind) + { + out = in.string(); + ind = i_ok; + } +}; + +} // namespace soci + +#endif // SOCI_STD_PATH_H_INCLUDED