into-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_INTO_TYPE_H_INCLUDED
9 #define SOCI_INTO_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 <vector>
17 
18 namespace soci
19 {
20 
21 class session;
22 
23 namespace details
24 {
25 
26 class prepare_temp_type;
27 class standard_into_type_backend;
28 class vector_into_type_backend;
29 class statement_impl;
30 
31 // this is intended to be a base class for all classes that deal with
32 // defining output data
34 {
35 public:
36  virtual ~into_type_base() {}
37 
38  virtual void define(statement_impl & st, int & position) = 0;
39  virtual void pre_fetch() = 0;
40  virtual void post_fetch(bool gotData, bool calledFromFetch) = 0;
41  virtual void clean_up() = 0;
42 
43  virtual std::size_t size() const = 0; // returns the number of elements
44  virtual void resize(std::size_t /* sz */) {} // used for vectors only
45 };
46 
48 
49 // standard types
50 
52 {
53 public:
54  standard_into_type(void * data, exchange_type type)
55  : data_(data), type_(type), ind_(NULL), backEnd_(NULL) {}
56  standard_into_type(void * data, exchange_type type, indicator & ind)
57  : data_(data), type_(type), ind_(&ind), backEnd_(NULL) {}
58 
59  virtual ~standard_into_type();
60 
61 protected:
62  virtual void post_fetch(bool gotData, bool calledFromFetch);
63 
64 private:
65  virtual void define(statement_impl & st, int & position);
66  virtual void pre_fetch();
67  virtual void clean_up();
68 
69  virtual std::size_t size() const { return 1; }
70 
71  // conversion hook (from base type to arbitrary user type)
72  virtual void convert_from_base() {}
73 
74  void * data_;
77 
79 };
80 
81 // into type base class for vectors
83 {
84 public:
85  vector_into_type(void * data, exchange_type type)
86  : data_(data), type_(type), indVec_(NULL), backEnd_(NULL) {}
87 
88  vector_into_type(void * data, exchange_type type,
89  std::vector<indicator> & ind)
90  : data_(data), type_(type), indVec_(&ind), backEnd_(NULL) {}
91 
93 
94 protected:
95  virtual void post_fetch(bool gotData, bool calledFromFetch);
96 
97 private:
98  virtual void define(statement_impl & st, int & position);
99  virtual void pre_fetch();
100  virtual void clean_up();
101  virtual void resize(std::size_t sz);
102  virtual std::size_t size() const;
103 
104  void * data_;
106  std::vector<indicator> * indVec_;
107 
109 
110  virtual void convert_from_base() {}
111 };
112 
113 // implementation for the basic types (those which are supported by the library
114 // out of the box without user-provided conversions)
115 
116 template <typename T>
118 {
119 public:
120  into_type(T & t)
121  : standard_into_type(&t,
122  static_cast<exchange_type>(exchange_traits<T>::x_type)) {}
123  into_type(T & t, indicator & ind)
124  : standard_into_type(&t,
125  static_cast<exchange_type>(exchange_traits<T>::x_type), ind) {}
126 };
127 
128 template <typename T>
129 class into_type<std::vector<T> > : public vector_into_type
130 {
131 public:
132  into_type(std::vector<T> & v)
133  : vector_into_type(&v,
134  static_cast<exchange_type>(exchange_traits<T>::x_type)) {}
135  into_type(std::vector<T> & v, std::vector<indicator> & ind)
136  : vector_into_type(&v,
137  static_cast<exchange_type>(exchange_traits<T>::x_type), ind) {}
138 };
139 
140 // helper dispatchers for basic types
141 
142 template <typename T>
143 into_type_ptr do_into(T & t, basic_type_tag)
144 {
145  return into_type_ptr(new into_type<T>(t));
146 }
147 
148 template <typename T>
149 into_type_ptr do_into(T & t, indicator & ind, basic_type_tag)
150 {
151  return into_type_ptr(new into_type<T>(t, ind));
152 }
153 
154 template <typename T>
155 into_type_ptr do_into(T & t, std::vector<indicator> & ind, basic_type_tag)
156 {
157  return into_type_ptr(new into_type<T>(t, ind));
158 }
159 
160 } // namespace details
161 
162 } // namespace soci
163 
164 #endif // SOCI_INTO_TYPE_H_INCLUDED
into_type_ptr do_into(T &t, basic_type_tag)
Definition: into-type.h:143
virtual void post_fetch(bool gotData, bool calledFromFetch)=0
virtual void define(statement_impl &st, int &position)=0
vector_into_type_backend * backEnd_
Definition: into-type.h:108
#define SOCI_DECL
Definition: soci-config.h:31
type_ptr< into_type_base > into_type_ptr
Definition: into-type.h:47
virtual void convert_from_base()
Definition: into-type.h:110
virtual void convert_from_base()
Definition: into-type.h:72
standard_into_type(void *data, exchange_type type)
Definition: into-type.h:54
vector_into_type(void *data, exchange_type type, std::vector< indicator > &ind)
Definition: into-type.h:88
standard_into_type(void *data, exchange_type type, indicator &ind)
Definition: into-type.h:56
std::vector< indicator > * indVec_
Definition: into-type.h:106
into_type(std::vector< T > &v, std::vector< indicator > &ind)
Definition: into-type.h:135
standard_into_type_backend * backEnd_
Definition: into-type.h:78
virtual void resize(std::size_t)
Definition: into-type.h:44
virtual std::size_t size() const
Definition: into-type.h:69
vector_into_type(void *data, exchange_type type)
Definition: into-type.h:85
virtual std::size_t size() const =0
into_type(T &t, indicator &ind)
Definition: into-type.h:123


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