Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/tntdb/include/tntdb/bits/row.h

00001 /*
00002  * Copyright (C) 2005 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 #ifndef TNTDB_BITS_ROW_H
00030 #define TNTDB_BITS_ROW_H
00031 
00032 #include <tntdb/iface/irow.h>
00033 #include <tntdb/bits/value.h>
00034 #include <tntdb/blob.h>
00035 #include <cxxtools/smartptr.h>
00036 
00037 namespace tntdb
00038 {
00042   class Row
00043   {
00044     public:
00046       class const_iterator;
00047       typedef unsigned size_type;
00048       typedef Value value_type;
00049 
00050     private:
00051       cxxtools::SmartPtr<IRow> row;
00052 
00053     public:
00054       Row()  { }
00055       Row(IRow* row_)
00056         : row(row_)
00057         { }
00058 
00060       unsigned size() const   { return row->size(); }
00062       bool empty() const      { return !row || size() == 0; }
00063 
00065       Value getValue(size_type field_num) const
00066         { return row->getValueByNumber(field_num); }
00069       Value getValue(const std::string& field_name) const
00070         { return row->getValueByName(field_name); }
00072       Value operator[] (size_type field_num) const
00073         { return row->getValueByNumber(field_num); }
00076       Value operator[] (const std::string& field_name) const
00077         { return row->getValueByName(field_name); }
00078 
00080       bool isNull(size_type field_num) const
00081         { return getValue(field_num).isNull(); }
00083       bool isNull(const std::string& field_name) const
00084         { return getValue(field_name).isNull(); }
00085 
00087 
00092       bool getBool(size_type field_num) const
00093         { return getValue(field_num).getBool(); }
00094       int getInt(size_type field_num) const
00095         { return getValue(field_num).getInt(); }
00096       unsigned getUnsigned(size_type field_num) const
00097         { return getValue(field_num).getUnsigned(); }
00098       int32_t getInt32(size_type field_num) const
00099         { return getValue(field_num).getInt32(); }
00100       uint32_t getUnsigned32(size_type field_num) const
00101         { return getValue(field_num).getUnsigned32(); }
00102       int64_t getInt64(size_type field_num) const
00103         { return getValue(field_num).getInt64(); }
00104       uint64_t getUnsigned64(size_type field_num) const
00105         { return getValue(field_num).getUnsigned64(); }
00106       Decimal getDecimal(size_type field_num) const
00107         { return getValue(field_num).getDecimal(); }
00108       float getFloat(size_type field_num) const
00109         { return getValue(field_num).getFloat(); }
00110       double getDouble(size_type field_num) const
00111         { return getValue(field_num).getDouble(); }
00112       char getChar(size_type field_num) const
00113         { return getValue(field_num).getChar(); }
00114       std::string getString(size_type field_num) const
00115         { return getValue(field_num).getString(); }
00116       void getString(size_type field_num, std::string& ret) const
00117         { return getValue(field_num).getString(ret); }
00118       Blob getBlob(size_type field_num) const
00119         { return getValue(field_num).getBlob(); }
00120       void getBlob(size_type field_num, Blob& ret) const
00121         { return getValue(field_num).getBlob(ret); }
00122       Date getDate(size_type field_num) const
00123         { return getValue(field_num).getDate(); }
00124       Time getTime(size_type field_num) const
00125         { return getValue(field_num).getTime(); }
00126       Datetime getDatetime(size_type field_num) const
00127         { return getValue(field_num).getDatetime(); }
00128 
00129       bool getBool(const std::string& field_name) const
00130         { return getValue(field_name).getBool(); }
00131       int getInt(const std::string& field_name) const
00132         { return getValue(field_name).getInt(); }
00133       unsigned getUnsigned(const std::string& field_name) const
00134         { return getValue(field_name).getUnsigned(); }
00135       int32_t getInt32(const std::string& field_name) const
00136         { return getValue(field_name).getInt32(); }
00137       uint32_t getUnsigned32(const std::string& field_name) const
00138         { return getValue(field_name).getUnsigned32(); }
00139       int64_t getInt64(const std::string& field_name) const
00140         { return getValue(field_name).getInt64(); }
00141       uint64_t getUnsigned64(const std::string& field_name) const
00142         { return getValue(field_name).getUnsigned64(); }
00143       Decimal getDecimal(const std::string& field_name) const
00144         { return getValue(field_name).getDecimal(); }
00145       float getFloat(const std::string& field_name) const
00146         { return getValue(field_name).getFloat(); }
00147       double getDouble(const std::string& field_name) const
00148         { return getValue(field_name).getDouble(); }
00149       char getChar(const std::string& field_name) const
00150         { return getValue(field_name).getChar(); }
00151       std::string getString(const std::string& field_name) const
00152         { return getValue(field_name).getString(); }
00153       void getString(const std::string& field_name, std::string& ret) const
00154         { return getValue(field_name).getString(ret); }
00155       Blob getBlob(const std::string& field_name) const
00156         { return getValue(field_name).getBlob(); }
00157       void getBlob(const std::string& field_name, Blob& ret) const
00158         { return getValue(field_name).getBlob(ret); }
00159       Date getDate(const std::string& field_name) const
00160         { return getValue(field_name).getDate(); }
00161       Time getTime(const std::string& field_name) const
00162         { return getValue(field_name).getTime(); }
00163       Datetime getDatetime(const std::string& field_name) const
00164         { return getValue(field_name).getDatetime(); }
00166 
00168       const_iterator begin() const;
00170       const_iterator end() const;
00171 
00173       bool operator!() const         { return !row; }
00175       const IRow* getImpl() const    { return &*row; }
00176   };
00177 }
00178 
00179 #endif // TNTDB_BITS_ROW_H
00180 
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6