row.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_ROW_H_INCLUDED
9 #define SOCI_ROW_H_INCLUDED
10 
11 #include "type-holder.h"
12 #include "soci-backend.h"
13 #include "type-conversion.h"
14 // std
15 #include <cassert>
16 #include <cstddef>
17 #include <map>
18 #include <string>
19 #include <vector>
20 
21 namespace soci
22 {
23 
25 {
26  // use getters/setters in case we want to make some
27  // of the getters lazy in the future
28 public:
29 
30  std::string get_name() const { return name_; }
31  data_type get_data_type() const { return dataType_; }
32 
33  void set_name(std::string const& name) { name_ = name; }
34  void set_data_type(data_type dataType) { dataType_ = dataType; }
35 
36 private:
37  std::string name_;
39 };
40 
42 {
43 public:
44  row();
45  ~row();
46 
47  void uppercase_column_names(bool forceToUpper);
48  void add_properties(column_properties const& cp);
49  std::size_t size() const;
50  void clean_up();
51 
52  indicator get_indicator(std::size_t pos) const;
53  indicator get_indicator(std::string const& name) const;
54 
55  template <typename T>
56  inline void add_holder(T* t, indicator* ind)
57  {
58  holders_.push_back(new details::type_holder<T>(t));
59  indicators_.push_back(ind);
60  }
61 
62  column_properties const& get_properties(std::size_t pos) const;
63  column_properties const& get_properties(std::string const& name) const;
64 
65  template <typename T>
66  T get(std::size_t pos) const
67  {
68  assert(holders_.size() >= pos + 1);
69 
70  typedef typename type_conversion<T>::base_type base_type;
71  base_type const& baseVal = holders_[pos]->get<base_type>();
72 
73  T ret;
74  type_conversion<T>::from_base(baseVal, *indicators_[pos], ret);
75  return ret;
76  }
77 
78  template <typename T>
79  T get(std::size_t pos, T const &nullValue) const
80  {
81  assert(holders_.size() >= pos + 1);
82 
83  if (i_null == *indicators_[pos])
84  {
85  return nullValue;
86  }
87 
88  return get<T>(pos);
89  }
90 
91  template <typename T>
92  T get(std::string const &name) const
93  {
94  std::size_t const pos = find_column(name);
95  return get<T>(pos);
96  }
97 
98  template <typename T>
99  T get(std::string const &name, T const &nullValue) const
100  {
101  std::size_t const pos = find_column(name);
102 
103  if (i_null == *indicators_[pos])
104  {
105  return nullValue;
106  }
107 
108  return get<T>(pos);
109  }
110 
111  template <typename T>
112  row const& operator>>(T& value) const
113  {
114  value = get<T>(currentPos_);
115  ++currentPos_;
116  return *this;
117  }
118 
119  void skip(std::size_t num = 1) const
120  {
121  currentPos_ += num;
122  }
123 
124  void reset_get_counter() const
125  {
126  currentPos_ = 0;
127  }
128 
129 private:
130  // copy not supported
131  row(row const &);
132  void operator=(row const &);
133 
134  std::size_t find_column(std::string const& name) const;
135 
136  std::vector<column_properties> columns_;
137  std::vector<details::holder*> holders_;
138  std::vector<indicator*> indicators_;
139  std::map<std::string, std::size_t> index_;
140 
142  mutable std::size_t currentPos_;
143 };
144 
145 } // namespace soci
146 
147 #endif // SOCI_ROW_H_INCLUDED
row const & operator>>(T &value) const
Definition: row.h:112
data_type get_data_type() const
Definition: row.h:31
Definition: row.h:41
std::string get_name() const
Definition: row.h:30
bool uppercaseColumnNames_
Definition: row.h:141
data_type dataType_
Definition: row.h:38
void skip(std::size_t num=1) const
Definition: row.h:119
#define SOCI_DECL
Definition: soci-config.h:31
std::map< std::string, std::size_t > index_
Definition: row.h:139
std::vector< details::holder * > holders_
Definition: row.h:137
std::string name_
Definition: row.h:37
static void from_base(base_type const &in, indicator ind, T &out)
void add_holder(T *t, indicator *ind)
Definition: row.h:56
void reset_get_counter() const
Definition: row.h:124
void set_data_type(data_type dataType)
Definition: row.h:34
std::size_t currentPos_
Definition: row.h:142
void set_name(std::string const &name)
Definition: row.h:33
std::vector< column_properties > columns_
Definition: row.h:136
std::vector< indicator * > indicators_
Definition: row.h:138


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