row.cpp
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 #define SOCI_SOURCE
9 #include "row.h"
10 
11 #include <cstddef>
12 #include <cctype>
13 #include <sstream>
14 #include <string>
15 
16 using namespace soci;
17 using namespace details;
18 
20  : uppercaseColumnNames_(false)
21  , currentPos_(0)
22 {}
23 
25 {
26  clean_up();
27 }
28 
29 void row::uppercase_column_names(bool forceToUpper)
30 {
31  uppercaseColumnNames_ = forceToUpper;
32 }
33 
35 {
36  columns_.push_back(cp);
37 
38  std::string columnName;
39  std::string const & originalName = cp.get_name();
41  {
42  for (std::size_t i = 0; i != originalName.size(); ++i)
43  {
44  columnName.push_back(static_cast<char>(std::toupper(originalName[i])));
45  }
46 
47  // rewrite the column name in the column_properties object
48  // as well to retain consistent views
49 
50  columns_[columns_.size() - 1].set_name(columnName);
51  }
52  else
53  {
54  columnName = originalName;
55  }
56 
57  index_[columnName] = columns_.size() - 1;
58 }
59 
60 std::size_t row::size() const
61 {
62  return holders_.size();
63 }
64 
66 {
67  std::size_t const hsize = holders_.size();
68  for (std::size_t i = 0; i != hsize; ++i)
69  {
70  delete holders_[i];
71  delete indicators_[i];
72  }
73 
74  columns_.clear();
75  holders_.clear();
76  indicators_.clear();
77  index_.clear();
78 }
79 
80 indicator row::get_indicator(std::size_t pos) const
81 {
82  assert(indicators_.size() >= static_cast<std::size_t>(pos + 1));
83  return *indicators_[pos];
84 }
85 
86 indicator row::get_indicator(std::string const &name) const
87 {
88  return get_indicator(find_column(name));
89 }
90 
91 column_properties const & row::get_properties(std::size_t pos) const
92 {
93  assert(columns_.size() >= pos + 1);
94  return columns_[pos];
95 }
96 
97 column_properties const & row::get_properties(std::string const &name) const
98 {
99  return get_properties(find_column(name));
100 }
101 
102 std::size_t row::find_column(std::string const &name) const
103 {
104  std::map<std::string, std::size_t>::const_iterator it = index_.find(name);
105  if (it == index_.end())
106  {
107  std::ostringstream msg;
108  msg << "Column '" << name << "' not found";
109  throw soci_error(msg.str());
110  }
111 
112  return it->second;
113 }
column_properties const & get_properties(std::size_t pos) const
Definition: row.cpp:91
std::size_t find_column(std::string const &name) const
Definition: row.cpp:102
std::string get_name() const
Definition: row.h:30
std::size_t size() const
Definition: row.cpp:60
bool uppercaseColumnNames_
Definition: row.h:141
std::map< std::string, std::size_t > index_
Definition: row.h:139
indicator get_indicator(std::size_t pos) const
Definition: row.cpp:80
std::vector< details::holder * > holders_
Definition: row.h:137
~row()
Definition: row.cpp:24
void uppercase_column_names(bool forceToUpper)
Definition: row.cpp:29
row()
Definition: row.cpp:19
void clean_up()
Definition: row.cpp:65
std::vector< column_properties > columns_
Definition: row.h:136
void add_properties(column_properties const &cp)
Definition: row.cpp:34
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