/usr/include/tntdb/bits/rowreader.h is in libtntdb-dev 1.3-4.
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 | /*
* Copyright (C) 2011 Tommi Maekitalo
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* As a special exception, you may use this file as part of a free
* software library without restriction. Specifically, if other files
* instantiate templates or use macros or inline functions from this
* file, or you compile this file and link it with other files to
* produce an executable, this file does not by itself cause the
* resulting executable to be covered by the GNU General Public
* License. This exception does not however invalidate any other
* reasons why the executable file might be covered by the GNU Library
* General Public License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TNTDB_ROWREADER_H
#define TNTDB_ROWREADER_H
#include <tntdb/bits/row.h>
namespace tntdb
{
/**
* A RowReader is a class which helps reading multiple columns from a row.
*
* This class helds a field number counter, which is incremented each time
* a value is fetched from the underlying row using one of the get methods.
* This class is normally instantiated implicitly using the tntdb::Row::reader
* method.
*
* The get methods return a reference to the row reader to make chaining of
* calls easy.
*
* Example:
* \code
* tntdb::Statement s = conn.prepare("select col1, col2, col3 from table");
* for (tntdb::Statement::const_iterator cur = s.begin(); cur != s.end(); ++cur)
* {
* int col1;
* std::string col2;
* long col3;
* bool col3IsNotNull;
* // note that a dereferenced cursor returns a tntdb::Row:
* cur->reader().get(col1) // this fetches the first value and
* // increments the field counter
* .get(col2) // and the second
* .get(col3, col3IsNotNull); // and this reads the 3rd column
* // and a flag, if it is not null
* // ...
* // do whatever you need to do with the values here
* // ...
* }
* \endcode
*/
class RowReader
{
const Row& row;
Row::size_type field_num;
public:
/// instatiates a row reader with a row and a initial field counter
explicit RowReader(const Row& row_, Row::size_type field_num_ = 0)
: row(row_),
field_num(field_num_)
{ }
/// Reads the current column value and increments the field counter.
/// If the value is null, the passed variable is not changed.
/// There is no straight forward way to determine, whether the value was null.
/// You should use the get method with the null indicator, if the value
/// might be null or just initialize your value with a suitable default.
template <typename T>
RowReader& get(T& ret)
{ row[field_num++].get(ret); return *this; }
/// Reads the current column value and a null indicator and increments the
/// field counter. If the value is null, the null indicator is set to false
/// and the actual value of the passed variable is not changed.
template <typename T>
RowReader& get(T& ret, bool& nullInd)
{ nullInd = row[field_num++].get(ret); return *this; }
/// Reads the current value into a tntdb::Value and increments the field
/// counter.
RowReader& get(tntdb::Value& v)
{ v = row[field_num++]; return *this; }
/// Returns true, if the current value is null.
bool isNull() const
{ return row[field_num].isNull(); }
/// Resets the field counter to the passed value.
void rewind(Row::size_type n_ = 0)
{ field_num = n_; }
/// returns the underlying row.
const Row& currentRow() const
{ return row; }
/// returns the current column number.
Row::size_type currentCol() const
{ return field_num; }
/// increments the current column number and returns the incremented value (pre increment).
Row::size_type operator++ ()
{ return ++field_num; }
/// increments the current column number and returns the previous value (post increment).
Row::size_type operator++ (int)
{ return field_num++; }
/// decrements the current column number and returns the decremented value (pre decrement).
Row::size_type operator-- ()
{ return --field_num; }
/// decrements the current column number and returns the previous value (post decrement).
Row::size_type operator-- (int)
{ return field_num--; }
};
inline RowReader Row::reader(Row::size_type n) const
{ return RowReader(*this, n); }
}
#endif // TNTDB_ROWREADER_H
|