bind-values.h
Go to the documentation of this file.
1 #ifndef SOCI_BIND_VALUES_H_INCLUDED
2 #define SOCI_BIND_VALUES_H_INCLUDED
3 
4 #include "exchange-traits.h"
5 #include "into-type.h"
6 #include "into.h"
7 #include "soci-backend.h"
8 #include "use-type.h"
9 #include "use.h"
10 
11 
12 #ifdef HAVE_BOOST
13 # include <boost/fusion/algorithm/iteration/for_each.hpp>
14 # include <boost/mpl/bool.hpp>
15 #endif // HAVE_BOOST
16 #include <vector>
17 
18 namespace soci
19 {
20 namespace details
21 {
22 
23 class use_type_vector: public std::vector<use_type_base *>
24 {
25 public:
27  {
28  for(iterator iter = begin(), _end = end();
29  iter != _end; iter++)
30  delete *iter;
31  }
32 
33  void exchange(use_type_ptr const& u) { push_back(u.get()); u.release(); }
34 
35  template <typename T, typename Indicator>
37  {
38 #ifdef HAVE_BOOST
39  exchange_(uc, (typename boost::fusion::traits::is_sequence<T>::type *)NULL);
40 #else
41  exchange_(uc, NULL);
42 #endif // HAVE_BOOST
43  }
44 
45 private:
46 #ifdef HAVE_BOOST
47  template <typename T, typename Indicator>
48  struct use_sequence
49  {
50  use_sequence(use_type_vector &_p, Indicator &_ind)
51  :p(_p), ind(_ind) {}
52 
53  template <typename T2>
54  void operator()(T2 &t2) const
55  {
56  p.exchange(use(t2, ind));
57  }
58 
59  use_type_vector &p;
60  Indicator &ind;
61  };
62 
63  template <typename T>
64  struct use_sequence<T, details::no_indicator>
65  {
66  use_sequence(use_type_vector &_p)
67  :p(_p) {}
68 
69  template <typename T2>
70  void operator()(T2 &t2) const
71  {
72  p.exchange(use(t2));
73  }
74 
75  use_type_vector &p;
76  };
77 
78  template <typename T, typename Indicator>
79  void exchange_(use_container<T, Indicator> const &uc, boost::mpl::true_ * /* fusion sequence */)
80  {
81  boost::fusion::for_each(uc.t, use_sequence<T, Indicator>(*this, uc.ind));
82  }
83 
84  template <typename T>
85  void exchange_(use_container<T, details::no_indicator> const &uc, boost::mpl::true_ * /* fusion sequence */)
86  {
87  boost::fusion::for_each(uc.t, use_sequence<T, details::no_indicator>(*this));
88  }
89 
90 #endif // HAVE_BOOST
91 
92  template <typename T, typename Indicator>
95 
96  template <typename T>
99 
100  template <typename T, typename Indicator>
102  { exchange(do_use(uc.t, uc.ind, uc.name, typename details::exchange_traits<T>::type_family())); }
103 
104  template <typename T>
107 };
108 
109 class into_type_vector: public std::vector<details::into_type_base *>
110 {
111 public:
113  {
114  for(iterator iter = begin(), _end = end();
115  iter != _end; iter++)
116  delete *iter;
117  }
118 
119  void exchange(into_type_ptr const& i) { push_back(i.get()); i.release(); }
120 
121  template <typename T, typename Indicator>
123  {
124 #ifdef HAVE_BOOST
125  exchange_(ic, (typename boost::fusion::traits::is_sequence<T>::type *)NULL);
126 #else
127  exchange_(ic, NULL);
128 #endif // HAVE_BOOST
129  }
130 
131 private:
132 #ifdef HAVE_BOOST
133  template <typename T, typename Indicator>
134  struct into_sequence
135  {
136  into_sequence(into_type_vector &_p, Indicator &_ind)
137  :p(_p), ind(_ind) {}
138 
139  template <typename T2>
140  void operator()(T2 &t2) const
141  {
142  p.exchange(into(t2, ind));
143  }
144 
145  into_type_vector &p;
146  Indicator &ind;
147  };
148 
149  template <typename T>
150  struct into_sequence<T, details::no_indicator>
151  {
152  into_sequence(into_type_vector &_p)
153  :p(_p) {}
154 
155  template <typename T2>
156  void operator()(T2 &t2) const
157  {
158  p.exchange(into(t2));
159  }
160 
161  into_type_vector &p;
162  };
163 
164  template <typename T, typename Indicator>
165  void exchange_(into_container<T, Indicator> const &ic, boost::mpl::true_ * /* fusion sequence */)
166  {
167  boost::fusion::for_each(ic.t, into_sequence<T, Indicator>(*this, ic.ind));
168  }
169 
170  template <typename T>
171  void exchange_(into_container<T, details::no_indicator> const &ic, boost::mpl::true_ * /* fusion sequence */)
172  {
173  boost::fusion::for_each(ic.t, into_sequence<T, details::no_indicator>(*this));
174  }
175 #endif // HAVE_BOOST
176 
177  template <typename T, typename Indicator>
180 
181  template <typename T>
184 };
185 
186 } // namespace details
187 }// namespace soci
188 #endif // SOCI_BIND_VALUES_H_INCLUDED
void release() const
Definition: type-ptr.h:21
details::into_container< T, details::no_indicator > into(T &t)
Definition: into.h:51
into_type_ptr do_into(T &t, basic_type_tag)
Definition: into-type.h:143
void exchange(use_type_ptr const &u)
Definition: bind-values.h:33
void exchange_(into_container< T, details::no_indicator > const &ic,...)
Definition: bind-values.h:182
void exchange(use_container< T, Indicator > const &uc)
Definition: bind-values.h:36
void exchange_(use_container< T, Indicator > const &uc,...)
Definition: bind-values.h:93
void exchange_(use_container< const T, details::no_indicator > const &uc,...)
Definition: bind-values.h:105
void no_indicator
Definition: into.h:37
const std::string & name
Definition: use.h:26
T * get() const
Definition: type-ptr.h:20
use_type_ptr do_use(T &t, std::string const &name, user_type_tag)
void exchange_(use_container< T, details::no_indicator > const &uc,...)
Definition: bind-values.h:97
void exchange_(use_container< const T, Indicator > const &uc,...)
Definition: bind-values.h:101
void exchange(into_container< T, Indicator > const &ic)
Definition: bind-values.h:122
void exchange_(into_container< T, Indicator > const &ic,...)
Definition: bind-values.h:178
void exchange(into_type_ptr const &i)
Definition: bind-values.h:119
details::use_container< T, details::no_indicator > use(T &t, const std::string &name=std::string())
Definition: use.h:43


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:40