Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members

# resiter.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004
    00005
    00006
    00007
    00008
    00009 /***********************************************************************
    00010  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
    00011  MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
    00012  Others may also hold copyrights on code in this file.  See the CREDITS
    00013  file in the top directory of the distribution for details.
    00014
    00015  This file is part of MySQL++.
    00016
    00017  MySQL++ is free software; you can redistribute it and/or modify it
    00018  under the terms of the GNU Lesser General Public License as published
    00019  by the Free Software Foundation; either version 2.1 of the License, or
    00020  (at your option) any later version.
    00021
    00022  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00023  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00024  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00025  License for more details.
    00026
    00027  You should have received a copy of the GNU Lesser General Public
    00028  License along with MySQL++; if not, write to the Free Software
    00029  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00030  USA
    00031 ***********************************************************************/
    00032
    00033 #ifndef MYSQLPP_RESITER_H
    00034 #define MYSQLPP_RESITER_H
    00035
    00036 #include "defs.h"
    00037
    00038 #include <iterator>
    00039
    00040 namespace mysqlpp {
    00041
    00042 template <class OnType, class ReturnType, class SizeType,
    00043         class DiffType> class subscript_iterator;
    00044
    00049 // \c size() defined for it.
    00050
    00051 template <class OnType,
    00052                 class ValueType,
    00053                 class ReturnType = const ValueType&,
    00054                 class SizeType = unsigned int,
    00055                 class DiffType = int>
    00056 class const_subscript_container
    00057 {
    00058 public:
    00059         typedef const_subscript_container<OnType, ValueType, ReturnType,
    00060                         SizeType, DiffType> this_type;
    00061         typedef subscript_iterator<const this_type, ReturnType, SizeType,
    00062                         DiffType> iterator;
    00063         typedef iterator const_iterator;
    00064         typedef const std::reverse_iterator<iterator>
    00065                         reverse_iterator;
    00066         typedef const std::reverse_iterator<const_iterator>
    00067                         const_reverse_iterator;
    00068
    00069         typedef ValueType value_type;
    00070         typedef value_type& reference;
    00071         typedef value_type& const_reference;
    00072         typedef value_type* pointer;
    00073         typedef value_type* const_pointer;
    00074
    00075         typedef DiffType difference_type;
    00076         typedef SizeType size_type;
    00077
    00079         virtual size_type size() const = 0;
    00080
    00082         virtual ReturnType operator [](SizeType i) const = 0;
    00083
    00086         size_type max_size() const { return size(); }
    00087
    00089         bool empty() const { return size() == 0; }
    00090
    00093         iterator begin() const { return iterator(this, 0); }
    00094
    00097         iterator end() const { return iterator(this, size()); }
    00098
    00101         reverse_iterator rbegin() const { return reverse_iterator(end()); }
    00102
    00105         reverse_iterator rend() const { return reverse_iterator(begin()); }
    00106 };
    00107
    00108
    00113
    00114 template <class OnType, class ReturnType, class SizeType,
    00115                 class DiffType>
    00116 class subscript_iterator : public std::iterator<ReturnType, SizeType>
    00117 {
    00118 private:
    00119         SizeType i;
    00120         OnType* d;
    00121
    00122 public:
    00124         subscript_iterator() { }
    00125
    00128         subscript_iterator(OnType* what, SizeType pos)
    00129         {
    00130                 d = what;
    00131                 i = pos;
    00132         }
    00133
    00136         bool operator ==(const subscript_iterator& j) const
    00137         {
    00138                 return (d == j.d && i == j.i);
    00139         }
    00140
    00143         bool operator !=(const subscript_iterator& j) const
    00144         {
    00145                 return (d == j.d && i != j.i);
    00146         }
    00147
    00151         bool operator <(const subscript_iterator& j) const
    00152         {
    00153                 return (d == j.d && i < j.i);
    00154         }
    00155
    00159         bool operator >(const subscript_iterator & j) const
    00160         {
    00161                 return (d == j.d && i > j.i);
    00162         }
    00163
    00167         bool operator <=(const subscript_iterator & j) const
    00168         {
    00169                 return (d == j.d && i <= j.i);
    00170         }
    00171
    00175         bool operator >=(const subscript_iterator & j) const
    00176         {
    00177                 return (d == j.d && i >= j.i);
    00178         }
    00179
    00182         ReturnType* operator ->() const { return &((*d)[i]); }
    00183
    00186         ReturnType operator *() const { return (*d)[i]; }
    00187
    00189         ReturnType operator [](SizeType n) const { return (*d)[n]; }
    00190
    00193         subscript_iterator& operator ++() { ++i; return *this; }
    00194
    00197         subscript_iterator operator ++(int)
    00198         {
    00199                 subscript_iterator tmp = *this;
    00200                 ++i;
    00201                 return tmp;
    00202         }
    00203
    00206         subscript_iterator& operator --()
    00207         {
    00208                 --i;
    00209                 return *this;
    00210         }
    00211
    00214         subscript_iterator operator --(int)
    00215         {
    00216                 subscript_iterator tmp = *this;
    00217                 --i;
    00218                 return tmp;
    00219         }
    00220
    00222         subscript_iterator& operator +=(SizeType n)
    00223         {
    00224                 i += n;
    00225                 return *this;
    00226         }
    00227
    00229         subscript_iterator operator +(SizeType n) const
    00230         {
    00231                 subscript_iterator tmp = *this;
    00232                 tmp.i += n;
    00233                 return tmp;
    00234         }
    00235
    00237         subscript_iterator& operator -=(SizeType n)
    00238         {
    00239                 i -= n;
    00240                 return *this;
    00241         }
    00242
    00244         subscript_iterator operator -(SizeType n) const
    00245         {
    00246                 subscript_iterator tmp = *this;
    00247                 tmp.i -= n;
    00248                 return tmp;
    00249         }
    00250
    00252         DiffType operator -(const subscript_iterator& j) const
    00253         {
    00254                 if (d == j.d) {
    00255                         return static_cast<SizeType>(i) - j.i;
    00256                 }
    00257                 return 0;
    00258         }
    00259 };
    00260
    00261
    00262 #if !defined(DOXYGEN_IGNORE)
    00263 // Doxygen will not generate documentation for this section.
    00264
    00265 template <class OnType, class ReturnType, class SizeType,
    00266                 class DiffType>
    00267 inline subscript_iterator<OnType, ReturnType, SizeType, DiffType>
    00268 operator +(SizeType x,
    00269                 const subscript_iterator <OnType, ReturnType, SizeType, DiffType>& y)
    00270 {
    00271         return y + x;
    00272 }
    00273
    00274 #endif // !defined(DOXYGEN_IGNORE)
    00275
    00276 } // end namespace mysqlpp
    00277
    00278 #endif