00001 #ifndef _STR_ChunkIterator_H_ // -*-c++-*-
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef __GNUG__
00022 # pragma interface
00023 #endif
00024
00025
00026
00027
00028
00029 #include <StrMod/StrChunk.h>
00030 #include <LCore/GenTypes.h>
00031 #include <iterator>
00032
00033 #define _STR_ChunkIterator_H_
00034
00035 namespace strmod {
00036 namespace strmod {
00037
00038
00039
00040
00041 class StrChunk::__iterator
00042 {
00043 private:
00044 class shared;
00045 friend class shared;
00046 typedef lcore::U1Byte U1Byte;
00047
00048 public:
00049 typedef ::std::bidirectional_iterator_tag iterator_category;
00050 typedef U1Byte value_type;
00051 typedef int difference_type;
00052 typedef const U1Byte *pointer;
00053 typedef const U1Byte &reference;
00054
00055
00056 __iterator();
00057
00058 __iterator(const StrChunkPtr &chnk);
00059
00060 __iterator(shared *sh);
00061
00062 __iterator(const __iterator &other);
00063
00064 ~__iterator();
00065
00066
00067 bool isFor(const StrChunkPtr &chnk) const;
00068
00069
00070
00071 bool isEqual(const __iterator &other) const;
00072
00073 bool isLessThan(const __iterator &other) const;
00074
00075
00076 difference_type distance(const __iterator &other) const;
00077
00078
00079 const __iterator &operator =(const __iterator &other);
00080
00081
00082 inline pointer operator->() const;
00083
00084 inline reference operator *() const;
00085
00086
00087 inline const __iterator &operator ++();
00088
00089 inline const __iterator operator ++(int);
00090
00091 void moveToEnd();
00092
00093 inline const __iterator &operator --();
00094
00095 inline const __iterator operator --(int);
00096
00097
00098 void moveToBegin();
00099
00100 protected:
00101
00102 inline static void setStorage(StrChunk &chnk, void *val);
00103
00104 inline static void *getStorage(StrChunk &chnk);
00105
00106 private:
00107 class ExtVisitor;
00108 friend class ExtVisitor;
00109 shared *shared_;
00110 unsigned int abspos_;
00111 unsigned int extpos_;
00112 unsigned int extlast_;
00113 unsigned int curext_;
00114 const unsigned char *extbase_;
00115
00116 inline void move_forward();
00117 void move_forward_complex();
00118 inline void move_backward();
00119 void move_backward_complex();
00120 };
00121
00122
00123
00124 inline StrChunk::__iterator::pointer
00125 StrChunk::__iterator::operator->() const
00126 {
00127 return(&(extbase_[extpos_]));
00128 }
00129
00130 inline StrChunk::__iterator::reference
00131 StrChunk::__iterator::operator *() const
00132 {
00133 return(extbase_[extpos_]);
00134 }
00135
00136 inline const StrChunk::__iterator &StrChunk::__iterator::operator ++()
00137 {
00138 move_forward();
00139 return(*this);
00140 }
00141
00142 inline const StrChunk::__iterator StrChunk::__iterator::operator ++(int)
00143 {
00144 __iterator tmp(*this);
00145 move_forward();
00146 return(tmp);
00147 }
00148
00149 inline const StrChunk::__iterator &StrChunk::__iterator::operator --()
00150 {
00151 move_backward();
00152 return(*this);
00153 }
00154
00155 inline const StrChunk::__iterator StrChunk::__iterator::operator --(int)
00156 {
00157 __iterator tmp(*this);
00158 move_backward();
00159 return(tmp);
00160 }
00161
00162 inline void StrChunk::__iterator::move_forward()
00163 {
00164 if (extpos_ < extlast_)
00165 {
00166 ++extpos_;
00167 ++abspos_;
00168 }
00169 else
00170 {
00171 move_forward_complex();
00172 }
00173 }
00174
00175 inline void StrChunk::__iterator::move_backward()
00176 {
00177 if (extpos_ > 0)
00178 {
00179 --extpos_;
00180 --abspos_;
00181 }
00182 else
00183 {
00184 move_backward_complex();
00185 }
00186 }
00187
00188 inline void StrChunk::__iterator::setStorage(StrChunk &chnk, void *val)
00189 {
00190 chnk.iter_storage = val;
00191 }
00192
00193 inline void *StrChunk::__iterator::getStorage(StrChunk &chnk)
00194 {
00195 return(chnk.iter_storage);
00196 }
00197
00198
00199
00200 inline bool
00201 operator ==(const StrChunk::__iterator &a, const StrChunk::__iterator &b)
00202 {
00203 return(a.isEqual(b));
00204 }
00205
00206 inline bool
00207 operator !=(const StrChunk::__iterator &a, const StrChunk::__iterator &b)
00208 {
00209 return(! a.isEqual(b));
00210 }
00211
00212 inline bool
00213 operator <(const StrChunk::__iterator &a, const StrChunk::__iterator &b)
00214 {
00215 return(a.isLessThan(b));
00216 }
00217
00218 inline bool
00219 operator >(const StrChunk::__iterator &a, const StrChunk::__iterator &b)
00220 {
00221 return(b.isLessThan(a));
00222 }
00223
00224 inline bool
00225 operator <=(const StrChunk::__iterator &a, const StrChunk::__iterator &b)
00226 {
00227 return(! b.isLessThan(a));
00228 }
00229
00230 inline bool
00231 operator >=(const StrChunk::__iterator &a, const StrChunk::__iterator &b)
00232 {
00233 return(! a.isLessThan(b));
00234 }
00235
00236 inline StrChunk::__iterator::difference_type
00237 operator -(const StrChunk::__iterator &a, const StrChunk::__iterator &b)
00238 {
00239 return(a.distance(b));
00240 }
00241
00242 };
00243 };
00244
00245 #endif