use-type.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #ifndef SOCI_USE_TYPE_H_INCLUDED
9 #define SOCI_USE_TYPE_H_INCLUDED
10 
11 #include "soci-backend.h"
12 #include "type-ptr.h"
13 #include "exchange-traits.h"
14 // std
15 #include <cstddef>
16 #include <string>
17 #include <vector>
18 
19 namespace soci { namespace details {
20 
21 class statement_impl;
22 
23 // this is intended to be a base class for all classes that deal with
24 // binding input data (and OUT PL/SQL variables)
26 {
27 public:
28  virtual ~use_type_base() {}
29 
30  virtual void bind(statement_impl & st, int & position) = 0;
31  virtual void pre_use() = 0;
32  virtual void post_use(bool gotData) = 0;
33  virtual void clean_up() = 0;
34 
35  virtual std::size_t size() const = 0; // returns the number of elements
36 };
37 
39 
41 {
42 public:
43  standard_use_type(void* data, exchange_type type,
44  bool readOnly, std::string const& name = std::string())
45  : data_(data)
46  , type_(type)
47  , ind_(NULL)
48  , readOnly_(readOnly)
49  , name_(name)
50  , backEnd_(NULL)
51  {
52  // FIXME: This was added with Ilia's patch
53  // https://github.com/SOCI/soci/commit/c166625a28f7c907318134f625ff5acea7d9a1f8
54  // but it seems to be a troublemaker, causing duplicated conversions
55  //convert_to_base();
56  }
57 
58  standard_use_type(void* data, exchange_type type, indicator& ind,
59  bool readOnly, std::string const& name = std::string())
60  : data_(data)
61  , type_(type)
62  , ind_(&ind)
63  , readOnly_(readOnly)
64  , name_(name)
65  , backEnd_(NULL)
66  {
67  // FIXME
68  //convert_to_base();
69  }
70 
71  virtual ~standard_use_type();
72  virtual void bind(statement_impl & st, int & position);
73  std::string get_name() const { return name_; }
74  virtual void * get_data() { return data_; }
75 
76  // conversion hook (from arbitrary user type to base type)
77  virtual void convert_to_base() {}
78  virtual void convert_from_base() {}
79 
80 protected:
81  virtual void pre_use();
82 
83 private:
84  virtual void post_use(bool gotData);
85  virtual void clean_up();
86  virtual std::size_t size() const { return 1; }
87 
88  void* data_;
91  bool readOnly_;
92  std::string name_;
93 
95 };
96 
98 {
99 public:
100  vector_use_type(void* data, exchange_type type,
101  std::string const& name = std::string())
102  : data_(data)
103  , type_(type)
104  , ind_(NULL)
105  , name_(name)
106  , backEnd_(NULL)
107  {}
108 
109  vector_use_type(void* data, exchange_type type,
110  std::vector<indicator> const& ind,
111  std::string const& name = std::string())
112  : data_(data)
113  , type_(type)
114  , ind_(&ind)
115  , name_(name)
116  , backEnd_(NULL)
117  {}
118 
119  ~vector_use_type();
120 
121 private:
122  virtual void bind(statement_impl& st, int & position);
123  virtual void pre_use();
124  virtual void post_use(bool) { /* nothing to do */ }
125  virtual void clean_up();
126  virtual std::size_t size() const;
127 
128  void* data_;
130  std::vector<indicator> const* ind_;
131  std::string name_;
132 
134 
135  virtual void convert_to_base() {}
136 };
137 
138 // implementation for the basic types (those which are supported by the library
139 // out of the box without user-provided conversions)
140 
141 template <typename T>
143 {
144 public:
145  use_type(T& t, std::string const& name = std::string())
146  : standard_use_type(&t,
147  static_cast<exchange_type>(exchange_traits<T>::x_type), false, name)
148  {}
149 
150  use_type(T const& t, std::string const& name = std::string())
151  : standard_use_type(const_cast<T*>(&t),
152  static_cast<exchange_type>(exchange_traits<T>::x_type), true, name)
153  {}
154 
155  use_type(T& t, indicator& ind, std::string const& name = std::string())
156  : standard_use_type(&t,
157  static_cast<exchange_type>(exchange_traits<T>::x_type), ind, false, name)
158  {}
159 
160  use_type(T const& t, indicator& ind, std::string const& name = std::string())
161  : standard_use_type(const_cast<T*>(&t),
162  static_cast<exchange_type>(exchange_traits<T>::x_type), ind, false, name)
163  {}
164 };
165 
166 template <typename T>
167 class use_type<std::vector<T> > : public vector_use_type
168 {
169 public:
170  use_type(std::vector<T>& v, std::string const& name = std::string())
171  : vector_use_type(&v,
172  static_cast<exchange_type>(exchange_traits<T>::x_type), name)
173  {}
174 
175  use_type(std::vector<T> const& v, std::string const& name = std::string())
176  : vector_use_type(const_cast<std::vector<T>*>(&v),
177  static_cast<exchange_type>(exchange_traits<T>::x_type), name)
178  {}
179 
180  use_type(std::vector<T>& v, std::vector<indicator> const& ind,
181  std::string const& name = std::string())
182  : vector_use_type(&v,
183  static_cast<exchange_type>(exchange_traits<T>::x_type), ind, name)
184  {}
185 
186  use_type(std::vector<T> const& v, std::vector<indicator> const& ind,
187  std::string const& name = std::string())
188  : vector_use_type(const_cast<std::vector<T> *>(&v),
189  static_cast<exchange_type>(exchange_traits<T>::x_type), ind, name)
190  {}
191 };
192 
193 // helper dispatchers for basic types
194 
195 template <typename T>
196 use_type_ptr do_use(T & t, std::string const & name, basic_type_tag)
197 {
198  return use_type_ptr(new use_type<T>(t, name));
199 }
200 
201 template <typename T>
202 use_type_ptr do_use(T const & t, std::string const & name, basic_type_tag)
203 {
204  return use_type_ptr(new use_type<T>(t, name));
205 }
206 
207 template <typename T>
208 use_type_ptr do_use(T & t, indicator & ind,
209  std::string const & name, basic_type_tag)
210 {
211  return use_type_ptr(new use_type<T>(t, ind, name));
212 }
213 
214 template <typename T>
215 use_type_ptr do_use(T const & t, indicator & ind,
216  std::string const & name, basic_type_tag)
217 {
218  return use_type_ptr(new use_type<T>(t, ind, name));
219 }
220 
221 template <typename T>
222 use_type_ptr do_use(T & t, std::vector<indicator> & ind,
223  std::string const & name, basic_type_tag)
224 {
225  return use_type_ptr(new use_type<T>(t, ind, name));
226 }
227 
228 template <typename T>
229 use_type_ptr do_use(T const & t, std::vector<indicator> & ind,
230  std::string const & name, basic_type_tag)
231 {
232  return use_type_ptr(new use_type<T>(t, ind, name));
233 }
234 
235 } // namespace details
236 
237 } // namesapce soci
238 
239 #endif // SOCI_USE_TYPE_H_INCLUDED
use_type(std::vector< T > &v, std::string const &name=std::string())
Definition: use-type.h:170
use_type(T &t, std::string const &name=std::string())
Definition: use-type.h:145
std::string get_name() const
Definition: use-type.h:73
standard_use_type(void *data, exchange_type type, bool readOnly, std::string const &name=std::string())
Definition: use-type.h:43
use_type(T const &t, indicator &ind, std::string const &name=std::string())
Definition: use-type.h:160
virtual void post_use(bool)
Definition: use-type.h:124
#define SOCI_DECL
Definition: soci-config.h:31
use_type(std::vector< T > &v, std::vector< indicator > const &ind, std::string const &name=std::string())
Definition: use-type.h:180
use_type(std::vector< T > const &v, std::string const &name=std::string())
Definition: use-type.h:175
vector_use_type(void *data, exchange_type type, std::string const &name=std::string())
Definition: use-type.h:100
vector_use_type_backend * backEnd_
Definition: use-type.h:133
virtual std::size_t size() const
Definition: use-type.h:86
use_type(T const &t, std::string const &name=std::string())
Definition: use-type.h:150
type_ptr< use_type_base > use_type_ptr
Definition: use-type.h:38
use_type(std::vector< T > const &v, std::vector< indicator > const &ind, std::string const &name=std::string())
Definition: use-type.h:186
standard_use_type_backend * backEnd_
Definition: use-type.h:94
virtual void convert_to_base()
Definition: use-type.h:135
use_type_ptr do_use(T &t, std::string const &name, user_type_tag)
virtual void convert_to_base()
Definition: use-type.h:77
virtual void * get_data()
Definition: use-type.h:74
use_type(T &t, indicator &ind, std::string const &name=std::string())
Definition: use-type.h:155
virtual void convert_from_base()
Definition: use-type.h:78
vector_use_type(void *data, exchange_type type, std::vector< indicator > const &ind, std::string const &name=std::string())
Definition: use-type.h:109
standard_use_type(void *data, exchange_type type, indicator &ind, bool readOnly, std::string const &name=std::string())
Definition: use-type.h:58
std::vector< indicator > const * ind_
Definition: use-type.h:130


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:41