row.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005 Tommi Maekitalo
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 #ifndef TNTDB_BITS_ROW_H
30 #define TNTDB_BITS_ROW_H
31 
32 #include <tntdb/iface/irow.h>
33 #include <tntdb/bits/value.h>
34 #include <tntdb/blob.h>
35 #include <tntdb/config.h>
36 #include <cxxtools/smartptr.h>
37 
38 namespace tntdb
39 {
40  class RowReader;
41 
45  class Row
46  {
47  public:
50  typedef unsigned size_type;
51  typedef Value value_type;
52 
53  private:
55 
56  public:
57  Row() { }
58  Row(IRow* row_)
59  : row(row_)
60  { }
61 
63  unsigned size() const { return row->size(); }
65  bool empty() const { return !row || size() == 0; }
66 
68  Value getValue(size_type field_num) const
69  { return row->getValueByNumber(field_num); }
71  Value getValue(const std::string& field_name) const
72  { return row->getValueByName(field_name); }
74  Value operator[] (size_type field_num) const
75  { return row->getValueByNumber(field_num); }
77  Value operator[] (const std::string& field_name) const
78  { return row->getValueByName(field_name); }
80  std::string getName(size_type field_num) const
81  { return row->getColumnName(field_num); }
82 
84  bool isNull(size_type field_num) const
85  { return getValue(field_num).isNull(); }
87  bool isNull(const std::string& field_name) const
88  { return getValue(field_name).isNull(); }
89 
91 
96  bool getBool(size_type field_num) const
97  { return getValue(field_num).getBool(); }
98  short getShort(size_type field_num) const
99  { return getValue(field_num).getShort(); }
100  int getInt(size_type field_num) const
101  { return getValue(field_num).getInt(); }
102  long getLong(size_type field_num) const
103  { return getValue(field_num).getLong(); }
104  unsigned short getUnsignedShort(size_type field_num) const
105  { return getValue(field_num).getUnsignedShort(); }
106  unsigned getUnsigned(size_type field_num) const
107  { return getValue(field_num).getUnsigned(); }
108  unsigned long getUnsignedLong(size_type field_num) const
109  { return getValue(field_num).getUnsignedLong(); }
110  int32_t getInt32(size_type field_num) const
111  { return getValue(field_num).getInt32(); }
112  uint32_t getUnsigned32(size_type field_num) const
113  { return getValue(field_num).getUnsigned32(); }
114  int64_t getInt64(size_type field_num) const
115  { return getValue(field_num).getInt64(); }
116  uint64_t getUnsigned64(size_type field_num) const
117  { return getValue(field_num).getUnsigned64(); }
118  Decimal getDecimal(size_type field_num) const
119  { return getValue(field_num).getDecimal(); }
120  float getFloat(size_type field_num) const
121  { return getValue(field_num).getFloat(); }
122  double getDouble(size_type field_num) const
123  { return getValue(field_num).getDouble(); }
124  char getChar(size_type field_num) const
125  { return getValue(field_num).getChar(); }
126  std::string getString(size_type field_num) const
127  { return getValue(field_num).getString(); }
128  void getString(size_type field_num, std::string& ret) const
129  { return getValue(field_num).getString(ret); }
130  Blob getBlob(size_type field_num) const
131  { return getValue(field_num).getBlob(); }
132  void getBlob(size_type field_num, Blob& ret) const
133  { return getValue(field_num).getBlob(ret); }
134  Date getDate(size_type field_num) const
135  { return getValue(field_num).getDate(); }
136  Time getTime(size_type field_num) const
137  { return getValue(field_num).getTime(); }
138  Datetime getDatetime(size_type field_num) const
139  { return getValue(field_num).getDatetime(); }
140 
141  bool getBool(const std::string& field_name) const
142  { return getValue(field_name).getBool(); }
143  short getShort(const std::string& field_name) const
144  { return getValue(field_name).getShort(); }
145  int getInt(const std::string& field_name) const
146  { return getValue(field_name).getInt(); }
147  long getLong(const std::string& field_name) const
148  { return getValue(field_name).getLong(); }
149  unsigned getUnsigned(const std::string& field_name) const
150  { return getValue(field_name).getUnsigned(); }
151  unsigned long getUnsignedLong(const std::string& field_name) const
152  { return getValue(field_name).getUnsignedLong(); }
153  int32_t getInt32(const std::string& field_name) const
154  { return getValue(field_name).getInt32(); }
155  uint32_t getUnsigned32(const std::string& field_name) const
156  { return getValue(field_name).getUnsigned32(); }
157  int64_t getInt64(const std::string& field_name) const
158  { return getValue(field_name).getInt64(); }
159  uint64_t getUnsigned64(const std::string& field_name) const
160  { return getValue(field_name).getUnsigned64(); }
161  Decimal getDecimal(const std::string& field_name) const
162  { return getValue(field_name).getDecimal(); }
163  float getFloat(const std::string& field_name) const
164  { return getValue(field_name).getFloat(); }
165  double getDouble(const std::string& field_name) const
166  { return getValue(field_name).getDouble(); }
167  char getChar(const std::string& field_name) const
168  { return getValue(field_name).getChar(); }
169  std::string getString(const std::string& field_name) const
170  { return getValue(field_name).getString(); }
171  void getString(const std::string& field_name, std::string& ret) const
172  { return getValue(field_name).getString(ret); }
173  Blob getBlob(const std::string& field_name) const
174  { return getValue(field_name).getBlob(); }
175  void getBlob(const std::string& field_name, Blob& ret) const
176  { return getValue(field_name).getBlob(ret); }
177  Date getDate(const std::string& field_name) const
178  { return getValue(field_name).getDate(); }
179  Time getTime(const std::string& field_name) const
180  { return getValue(field_name).getTime(); }
181  Datetime getDatetime(const std::string& field_name) const
182  { return getValue(field_name).getDatetime(); }
184 
185  template <typename T>
186  bool getValue(size_type field_num, T& ret) const
187  { return getValue(field_num).getValue(ret); }
188 
190  const_iterator begin() const;
192  const_iterator end() const;
193 
195  bool operator!() const { return !row; }
197  const IRow* getImpl() const { return &*row; }
198 
200  RowReader reader(size_type n = 0) const;
201 
203  template <typename T>
204  RowReader get(T& ret) const;
205 
207  template <typename T>
208  RowReader get(T& ret, bool& nullInd) const;
209 
210  };
211 }
212 
213 #endif // TNTDB_BITS_ROW_H
214