SOCI Logo Get SOCI at SourceForge.net. Fast, secure and Free Open Source software downloads

row.cpp

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
00003 // Distributed under the Boost Software License, Version 1.0.
00004 // (See accompanying file LICENSE_1_0.txt or copy at
00005 // http://www.boost.org/LICENSE_1_0.txt)
00006 //
00007 
00008 #define SOCI_SOURCE
00009 #include "row.h"
00010 
00011 #include <cstddef>
00012 #include <cctype>
00013 #include <sstream>
00014 #include <string>
00015 
00016 using namespace soci;
00017 using namespace details;
00018 
00019 void row::add_properties(column_properties const &cp)
00020 {
00021     columns_.push_back(cp);
00022 
00023     std::string columnName;
00024     std::string const & originalName = cp.get_name();
00025     if (uppercaseColumnNames_)
00026     {
00027         for (std::size_t i = 0; i != originalName.size(); ++i)
00028         {
00029             columnName.push_back(std::toupper(originalName[i]));
00030         }
00031 
00032         // rewrite the column name in the column_properties object
00033         // as well to retain consistent views
00034 
00035         columns_[columns_.size() - 1].set_name(columnName);
00036     }
00037     else
00038     {
00039         columnName = originalName;
00040     }
00041 
00042     index_[columnName] = columns_.size() - 1;
00043 }
00044 
00045 std::size_t row::size() const
00046 {
00047     return holders_.size();
00048 }
00049 
00050 void row::clean_up()
00051 {
00052     std::size_t const hsize = holders_.size();
00053     for (std::size_t i = 0; i != hsize; ++i)
00054     {
00055         delete holders_[i];
00056         delete indicators_[i];
00057     }
00058 
00059     columns_.clear();
00060     holders_.clear();
00061     indicators_.clear();
00062     index_.clear();
00063 }
00064 
00065 indicator row::get_indicator(std::size_t pos) const
00066 {
00067     assert(indicators_.size() >= static_cast<std::size_t>(pos + 1));
00068     return *indicators_[pos];
00069 }
00070 
00071 indicator row::get_indicator(std::string const &name) const
00072 {
00073     return get_indicator(find_column(name));
00074 }
00075 
00076 column_properties const & row::get_properties(std::size_t pos) const
00077 {
00078     assert(columns_.size() >= pos + 1);
00079     return columns_[pos];
00080 }
00081 
00082 column_properties const & row::get_properties(std::string const &name) const
00083 {
00084     return get_properties(find_column(name));
00085 }
00086 
00087 std::size_t row::find_column(std::string const &name) const
00088 {
00089     std::map<std::string, std::size_t>::const_iterator it = index_.find(name);
00090     if (it == index_.end())
00091     {
00092         std::ostringstream msg;
00093         msg << "Column '" << name << "' not found";
00094         throw soci_error(msg.str());
00095     }
00096 
00097     return it->second;
00098 }
00099 
00100 row::~row()
00101 {
00102     clean_up();
00103 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
SourceForge Logo

Generated on Sun Oct 3 2010 17:42:17 for EXTRAS-SOCI by Doxygen 1.7.1