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 #ifndef MYSQLPP_RESITER_H
00002 #define MYSQLPP_RESITER_H
00003 
00011 
00012 #include "defs.h"
00013 
00014 #include <iterator>
00015 
00016 namespace mysqlpp {
00017 
00018 template <class OnType, class ReturnType, class SizeType, class DiffType>
00019 class subscript_iterator;
00020 
00025 // \c size() defined for it.
00026 
00027 template <class OnType, class ValueType, class ReturnType = const ValueType&, class SizeType = unsigned int, class DiffType = int>
00028 class const_subscript_container {
00029 public:
00030   typedef const_subscript_container<OnType,ValueType,ReturnType,SizeType,DiffType>
00031                 this_type;
00032 
00033   typedef subscript_iterator<const this_type, ReturnType, SizeType, DiffType> 
00034                 iterator;
00035   typedef iterator const_iterator;
00036   typedef const std::reverse_iterator<iterator> reverse_iterator;
00037   typedef const std::reverse_iterator<const_iterator> const_reverse_iterator;
00038   
00039   typedef ValueType value_type;
00040   typedef value_type& reference;
00041   typedef value_type& const_reference;
00042   typedef value_type* pointer;
00043   typedef value_type* const_pointer;
00044   
00045   typedef DiffType difference_type;
00046   typedef SizeType size_type;
00047  
00048   virtual size_type  size() const = 0;
00049   virtual ReturnType operator[] (SizeType i) const = 0;
00050 
00051   size_type max_size() const { return size(); }
00052   bool empty() const { return size()==0; }
00053   
00054   iterator begin() const { return iterator(this, 0); }
00055   iterator end() const { return iterator(this, size()); }
00056   
00057   reverse_iterator rbegin() const { return reverse_iterator(end()); }
00058   reverse_iterator rend() const { return reverse_iterator(begin()); }
00059 };
00060 
00061 
00066 
00067 template <class OnType, class ReturnType, class SizeType, class DiffType>
00068 class subscript_iterator : public std::iterator<ReturnType, SizeType>
00069 {
00070 private:
00071   SizeType    i;
00072   OnType     *d;
00073 public:
00074   subscript_iterator() {}; 
00075   subscript_iterator(OnType *what, SizeType pos) {d=what; i=pos;}
00076  
00077   bool operator == (const subscript_iterator &j) const
00078     {if (d == j.d && i==j.i) return true; return false;}
00079   bool operator != (const subscript_iterator &j) const
00080     {if (d == j.d && i!=j.i) return true; return false;}
00081   bool operator < (const subscript_iterator &j) const
00082     {if (d == j.d && i < j.i) return true; return false;}
00083   bool operator > (const subscript_iterator &j) const
00084     {if (d == j.d && i > j.i) return true; return false;}
00085   bool operator <= (const subscript_iterator &j) const
00086     {if (d == j.d && i<=j.i) return true; return false;}
00087   bool operator >= (const subscript_iterator &j) const
00088     {if (d == j.d && i>=j.i) return true; return false;}
00089 
00090   ReturnType* operator -> () const {return &((*d)[i]);}
00091   ReturnType operator *  () const {return (*d)[i];}
00092   ReturnType operator [] (SizeType n) const {return (*d)[n];}
00093 
00094   subscript_iterator& operator ++ () {i++; return *this;}
00095   subscript_iterator  operator ++ (int) 
00096     {subscript_iterator tmp = *this; i++; return tmp;}
00097   subscript_iterator& operator -- () {i--; return *this;}
00098   subscript_iterator  operator -- (int) 
00099     {subscript_iterator tmp = *this; i--; return tmp;}
00100   subscript_iterator& operator += (SizeType n) {i=i+n; return *this;}
00101   subscript_iterator  operator + (SizeType n) const
00102     {subscript_iterator tmp = *this; tmp.i+=n; return tmp;}
00103   subscript_iterator& operator -= (SizeType n) {i=i-n; return *this;}
00104   subscript_iterator  operator - (SizeType n) const
00105     {subscript_iterator tmp = *this; tmp.i-=n; return tmp;}
00106   DiffType operator - (const subscript_iterator &j) const
00107     {if (d == j.d) return static_cast<SizeType>(i) - j.i; return 0;}
00108 };
00109 
00110 template <class OnType, class ReturnType, class SizeType, class DiffType>
00111 inline subscript_iterator<OnType,ReturnType,SizeType,DiffType>
00112 operator +(SizeType x,
00113                 const subscript_iterator<OnType, ReturnType, SizeType, DiffType>& y) 
00114 {
00115   return y + x;
00116 }
00117 
00118 } // end namespace mysqlpp
00119 
00120 #endif
00121 

Generated on Thu May 5 05:30:43 2005 for MySQL++ by doxygen1.2.18