[go: up one dir, main page]

File: bind-values.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 (216 lines) | stat: -rw-r--r-- 6,383 bytes parent folder | download | duplicates (3)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#ifndef SOCI_BIND_VALUES_H_INCLUDED
#define SOCI_BIND_VALUES_H_INCLUDED

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


#ifdef SOCI_HAVE_BOOST
#       include <boost/fusion/algorithm/iteration/for_each.hpp>
#       include <boost/mpl/bool.hpp>
#       include <boost/version.hpp>

#       if BOOST_VERSION >= 106800
#       define SOCI_BOOST_FUSION_FOREACH_REFERENCE &
#       else
#       define SOCI_BOOST_FUSION_FOREACH_REFERENCE
#       endif
#endif // SOCI_HAVE_BOOST
#include <vector>

namespace soci
{
namespace details
{

class use_type_vector: public std::vector<use_type_base *>
{
public:
    ~use_type_vector()
    {
        for(iterator iter = begin(), _end = end();
            iter != _end; iter++)
            delete *iter;
    }

    void exchange(use_type_ptr const& u) { push_back(u.get()); u.release(); }

    template <typename T, typename Indicator>
    void exchange(use_container<T, Indicator> const &uc)
    {
#ifdef SOCI_HAVE_BOOST
        exchange_(uc, (typename boost::fusion::traits::is_sequence<T>::type *)NULL);
#else
        exchange_(uc, NULL);
#endif // SOCI_HAVE_BOOST
    }

private:
#ifdef SOCI_HAVE_BOOST
    template <typename T, typename Indicator>
    struct use_sequence
    {
        use_sequence(use_type_vector &_p, Indicator &_ind)
            :p(_p), ind(_ind) {}

        template <typename T2>
        void operator()(T2 &t2) const
        {
            p.exchange(use(t2, ind));
        }

        use_type_vector &p;
        Indicator &ind;
    private:
        SOCI_NOT_COPYABLE(use_sequence)
    };

    template <typename T>
    struct use_sequence<T, details::no_indicator>
    {
        use_sequence(use_type_vector &_p)
            :p(_p) {}

        template <typename T2>
        void operator()(T2 &t2) const
        {
            p.exchange(use(t2));
        }

        use_type_vector &p;
    private:
        SOCI_NOT_COPYABLE(use_sequence)
    };

    template <typename T, typename Indicator>
    void exchange_(use_container<T, Indicator> const &uc, boost::mpl::true_ * /* fusion sequence */)
    {
        use_sequence<T, Indicator> f(*this, uc.ind);
        boost::fusion::for_each<T,
                                use_sequence<T, Indicator>
                                    SOCI_BOOST_FUSION_FOREACH_REFERENCE>(uc.t, f);
    }

    template <typename T>
    void exchange_(use_container<T, details::no_indicator> const &uc, boost::mpl::true_ * /* fusion sequence */)
    {
        use_sequence<T, details::no_indicator> f(*this);
        boost::fusion::for_each<T,
                                use_sequence<T, details::no_indicator>
                                    SOCI_BOOST_FUSION_FOREACH_REFERENCE>(uc.t, f);
    }

#endif // SOCI_HAVE_BOOST

    template <typename T, typename Indicator>
    void exchange_(use_container<T, Indicator> const &uc, ...)
    { exchange(do_use(uc.t, uc.ind, uc.name, typename details::exchange_traits<T>::type_family())); }

    template <typename T>
    void exchange_(use_container<T, details::no_indicator> const &uc, ...)
    { exchange(do_use(uc.t, uc.name, typename details::exchange_traits<T>::type_family())); }

    template <typename T, typename Indicator>
    void exchange_(use_container<const T, Indicator> const &uc, ...)
    { exchange(do_use(uc.t, uc.ind, uc.name, typename details::exchange_traits<T>::type_family())); }

    template <typename T>
    void exchange_(use_container<const T, details::no_indicator> const &uc, ...)
    { exchange(do_use(uc.t, uc.name, typename details::exchange_traits<T>::type_family())); }
};

class into_type_vector: public std::vector<details::into_type_base *>
{
public:
    ~into_type_vector()
    {
        for(iterator iter = begin(), _end = end();
            iter != _end; iter++)
            delete *iter;
    }

    void exchange(into_type_ptr const& i) { push_back(i.get()); i.release(); }

    template <typename T, typename Indicator>
    void exchange(into_container<T, Indicator> const &ic)
    {
#ifdef SOCI_HAVE_BOOST
        exchange_(ic, (typename boost::fusion::traits::is_sequence<T>::type *)NULL);
#else
        exchange_(ic, NULL);
#endif // SOCI_HAVE_BOOST
    }

private:
#ifdef SOCI_HAVE_BOOST
    template <typename T, typename Indicator>
    struct into_sequence
    {
        into_sequence(into_type_vector &_p, Indicator &_ind)
            :p(_p), ind(_ind) {}

        template <typename T2>
        void operator()(T2 &t2) const
        {
            p.exchange(into(t2, ind));
        }

        into_type_vector &p;
        Indicator &ind;
    private:
        SOCI_NOT_COPYABLE(into_sequence)
    };

    template <typename T>
    struct into_sequence<T, details::no_indicator>
    {
        into_sequence(into_type_vector &_p)
            :p(_p) {}

        template <typename T2>
        void operator()(T2 &t2) const
        {
            p.exchange(into(t2));
        }

        into_type_vector &p;
    private:
        SOCI_NOT_COPYABLE(into_sequence)
    };

    template <typename T, typename Indicator>
    void exchange_(into_container<T, Indicator> const &ic, boost::mpl::true_ * /* fusion sequence */)
    {
        into_sequence<T, Indicator> f(*this, ic.ind);
        boost::fusion::for_each<T,
                                into_sequence<T, Indicator>
                                    SOCI_BOOST_FUSION_FOREACH_REFERENCE>(ic.t, f);
    }

    template <typename T>
    void exchange_(into_container<T, details::no_indicator> const &ic, boost::mpl::true_ * /* fusion sequence */)
    {
        into_sequence<T, details::no_indicator> f(*this);
        boost::fusion::for_each<T,
                                into_sequence<T, details::no_indicator>
                                    SOCI_BOOST_FUSION_FOREACH_REFERENCE>(ic.t, f);
    }
#endif // SOCI_HAVE_BOOST

    template <typename T, typename Indicator>
    void exchange_(into_container<T, Indicator> const &ic, ...)
    { exchange(do_into(ic.t, ic.ind, typename details::exchange_traits<T>::type_family())); }

    template <typename T>
    void exchange_(into_container<T, details::no_indicator> const &ic, ...)
    { exchange(do_into(ic.t, typename details::exchange_traits<T>::type_family())); }
};

} // namespace details
}// namespace soci
#endif // SOCI_BIND_VALUES_H_INCLUDED