[go: up one dir, main page]

File: use.h

package info (click to toggle)
soci 4.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,944 kB
  • sloc: ansic: 169,887; cpp: 54,198; javascript: 12,258; ada: 1,973; sh: 36; makefile: 12; xml: 2
file content (123 lines) | stat: -rw-r--r-- 4,002 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// 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_USE_H_INCLUDED
#define SOCI_USE_H_INCLUDED

#include "soci/use-type.h"
#include "soci/exchange-traits.h"
#include "soci/type-conversion.h"
#include "soci/soci-backend.h"

namespace soci
{

namespace details
{
template <typename T, typename Indicator>
struct use_container
{
    use_container(T &_t, Indicator &_ind, const std::string &_name)
        : t(_t), ind(_ind), name(_name) {}

    T &t;
    Indicator &ind;
    const std::string &name;
private:
    SOCI_NOT_ASSIGNABLE(use_container)
};

typedef void no_indicator;
template <typename T>
struct use_container<T, no_indicator>
{
    use_container(T &_t, const std::string &_name)
        : t(_t), name(_name) {}

    T &t;
    const std::string &name;
private:
    SOCI_NOT_ASSIGNABLE(use_container)
};

} // namespace details

// soci::use is deleted for rvalues because it will likely lead to subtle stack-use-after-scope bugs.
template <typename T>
details::use_container<T, details::no_indicator> use(T &&t, const std::string &name = std::string()) = delete;

template <typename T>
details::use_container<const T, indicator> use(T &&t, indicator & ind, std::string const &name = std::string()) = delete;

template <typename T>
details::use_container<T, details::no_indicator> use(T &t, const std::string &name = std::string())
{ return details::use_container<T, details::no_indicator>(t, name); }

template <typename T>
details::use_container<const T, details::no_indicator> use(T const &t, const std::string &name = std::string())
{ return details::use_container<const T, details::no_indicator>(t, name); }

template <typename T>
details::use_container<T, indicator> use(T &t, indicator & ind, std::string const &name = std::string())
{ return details::use_container<T, indicator>(t, ind, name); }

template <typename T>
details::use_container<const T, indicator> use(T const &t, indicator & ind, std::string const &name = std::string())
{ return details::use_container<const T, indicator>(t, ind, name); }

// vector containers
template <typename T>
details::use_container<T, std::vector<indicator> >
    use(T &t, std::vector<indicator> & ind, const std::string &name = std::string())
{ return details::use_container<T, std::vector<indicator> >(t, ind, name); }

template <typename T>
details::use_container<std::vector<T>, details::no_indicator >
    use(std::vector<T> &t, const std::string &name = std::string())
{ return details::use_container<std::vector<T>, details::no_indicator>(t, name); }

// vectors with index ranges

template <typename T>
details::use_type_ptr use(std::vector<T> & t,
    std::size_t begin, std::size_t & end,
    const std::string &name = std::string())
{
    return details::do_use(t, begin, &end, name,
        typename details::exchange_traits<std::vector<T> >::type_family());
}

template <typename T>
details::use_type_ptr use(const std::vector<T> & t,
    std::size_t begin, std::size_t & end,
    const std::string &name = std::string())
{
    return details::do_use(t, begin, &end, name,
        typename details::exchange_traits<std::vector<T> >::type_family());
}

template <typename T>
details::use_type_ptr use(std::vector<T> & t, std::vector<indicator> & ind,
    std::size_t begin, std::size_t & end,
    const std::string &name = std::string())
{
    return details::do_use(t, ind, begin, &end, name,
        typename details::exchange_traits<std::vector<T> >::type_family());
}

template <typename T>
details::use_type_ptr use(const std::vector<T> & t, std::vector<indicator> & ind,
    std::size_t begin, std::size_t & end,
    const std::string &name = std::string())
{
    return details::do_use(t, ind, begin, &end, name,
        typename details::exchange_traits<std::vector<T> >::type_family());
}

} // namespace soci

#endif // SOCI_USE_H_INCLUDED