1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
//
// Copyright (C) 2004-2016 Maciej Sobczak, Stephen Hutton
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_INTO_H_INCLUDED
#define SOCI_INTO_H_INCLUDED
#include "soci/into-type.h"
#include "soci/exchange-traits.h"
#include "soci/type-conversion.h"
// std
#include <cstddef>
#include <vector>
namespace soci
{
// the into function is a helper for defining output variables
// these helpers work with both basic and user-defined types thanks to
// the tag-dispatching, as defined in exchange_traits template
namespace details
{
template <typename T, typename Indicator>
struct into_container
{
into_container(T &_t, Indicator &_ind)
: t(_t), ind(_ind) {}
T &t;
Indicator &ind;
private:
SOCI_NOT_ASSIGNABLE(into_container)
};
typedef void no_indicator;
template <typename T>
struct into_container<T, no_indicator>
{
into_container(T &_t)
: t(_t) {}
T &t;
private:
SOCI_NOT_ASSIGNABLE(into_container)
};
} // namespace details
template <typename T>
details::into_container<T, details::no_indicator>
into(T &t)
{ return details::into_container<T, details::no_indicator>(t); }
template <typename T, typename Indicator>
details::into_container<T, Indicator>
into(T &t, Indicator &ind)
{ return details::into_container<T, Indicator>(t, ind); }
// for char buffer with run-time size information
template <typename T>
details::into_type_ptr into(T & t, std::size_t bufSize)
{
return details::into_type_ptr(new details::into_type<T>(t, bufSize));
}
// vectors with index ranges
template <typename T>
details::into_type_ptr into(std::vector<T> & t,
std::size_t begin, std::size_t & end)
{
return details::do_into(t, begin, &end,
typename details::exchange_traits<std::vector<T> >::type_family());
}
template <typename T>
details::into_type_ptr into(std::vector<T> & t, std::vector<indicator> & ind)
{
return details::do_into(t, ind,
typename details::exchange_traits<std::vector<T> >::type_family());
}
template <typename T>
details::into_type_ptr into(std::vector<T> & t, std::vector<indicator> & ind,
std::size_t begin, std::size_t & end)
{
return details::do_into(t, ind, begin, &end,
typename details::exchange_traits<std::vector<T> >::type_family());
}
} // namespace soci
#endif // SOCI_INTO_H_INCLUDED
|