/usr/include/soci/rowset.h is in libsoci-dev 3.2.3-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | //
// Copyright (C) 2006-2008 Mateusz Loskot
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef SOCI_ROWSET_H_INCLUDED
#define SOCI_ROWSET_H_INCLUDED
#include "statement.h"
// std
#include <iterator>
#include <memory>
namespace soci
{
//
// rowset iterator of input category.
//
template <typename T>
class rowset_iterator
{
public:
// Standard iterator traits
typedef std::input_iterator_tag iterator_category;
typedef T value_type;
typedef T * pointer;
typedef T & reference;
typedef ptrdiff_t difference_type;
// Constructors
rowset_iterator()
: st_(0), define_(0)
{}
rowset_iterator(statement & st, T & define)
: st_(&st), define_(&define)
{
assert(0 != st_);
assert(0 != define_);
assert(0 != st_->get_backend());
// Fetch first row to properly initialize iterator
++(*this);
}
// Access operators
reference operator*() const
{
return (*define_);
}
pointer operator->() const
{
return &(operator*());
}
// Iteration operators
rowset_iterator & operator++()
{
// Fetch next row from dataset
if (st_->fetch() == false)
{
// Set iterator to non-derefencable state (pass-the-end)
st_ = 0;
define_ = 0;
}
return (*this);
}
rowset_iterator operator++(int)
{
rowset_iterator tmp(*this);
++(*this);
return tmp;
}
// Comparison operators
bool operator==(rowset_iterator const & rhs) const
{
return (st_== rhs.st_ && define_ == rhs.define_);
}
bool operator!=(rowset_iterator const & rhs) const
{
return ((*this == rhs) == false);
}
private:
statement * st_;
T * define_;
}; // class rowset_iterator
namespace details
{
//
// Implementation of rowset
//
template <typename T>
class rowset_impl
{
public:
typedef rowset_iterator<T> iterator;
rowset_impl(details::prepare_temp_type const & prep)
: refs_(1), st_(new statement(prep)), define_(new T())
{
assert(0 != st_.get());
assert(0 != define_.get());
st_->exchange_for_rowset(into(*define_));
st_->execute();
}
void incRef()
{
++refs_;
}
void decRef()
{
if (--refs_ == 0)
{
delete this;
}
}
iterator begin() const
{
// No ownership transfer occurs here
return iterator(*st_, *define_);
}
iterator end() const
{
return iterator();
}
private:
unsigned int refs_;
const std::auto_ptr<statement> st_;
const std::auto_ptr<T> define_;
// Non-copyable
rowset_impl(rowset_impl const &);
rowset_impl & operator=(rowset_impl const &);
}; // class rowset_impl
} // namespace details
//
// rowset is a thin wrapper on statement and provides access to STL-like input iterator.
// The rowset_iterator can be used to easily loop through statement results and
// use STL algorithms accepting input iterators.
//
template <typename T = soci::row>
class rowset
{
public:
typedef T value_type;
typedef rowset_iterator<T> iterator;
typedef rowset_iterator<T> const_iterator;
// this is a conversion constructor
rowset(details::prepare_temp_type const& prep)
: pimpl_(new details::rowset_impl<T>(prep))
{
assert(0 != pimpl_);
}
rowset(rowset const & other)
: pimpl_(other.pimpl_)
{
assert(0 != pimpl_);
pimpl_->incRef();
}
~rowset()
{
assert(0 != pimpl_);
pimpl_->decRef();
}
rowset& operator=(rowset const& rhs)
{
assert(0 != pimpl_);
assert(0 != rhs.pimpl_);
if (&rhs != this)
{
rhs.pimpl_->incRef();
pimpl_->decRef();
pimpl_ = rhs.pimpl_;
}
return *this;
}
const_iterator begin() const
{
assert(0 != pimpl_);
return pimpl_->begin();
}
const_iterator end() const
{
assert(0 != pimpl_);
return pimpl_->end();
}
private:
// Pointer to implementation - the body
details::rowset_impl<T>* pimpl_;
}; // class rowset
} // namespace soci
#endif // SOCI_ROWSET_H_INCLUDED
|