Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNRopeIterator.h

Go to the documentation of this file.
00001 /* 00002 * Copyright (c) 1997 00003 * Silicon Graphics Computer Systems, Inc. 00004 * 00005 * Permission to use, copy, modify, distribute and sell this software 00006 * and its documentation for any purpose is hereby granted without fee, 00007 * provided that the above copyright notice appear in all copies and 00008 * that both that copyright notice and this permission notice appear 00009 * in supporting documentation. Silicon Graphics makes no 00010 * representations about the suitability of this software for any 00011 * purpose. It is provided "as is" without express or implied warranty. 00012 * 00013 * Heavily modified by KOM/Darmstadt University of Technology, 2000 00014 */ 00015 #ifndef _R_ITERATOR_H 00016 #define _R_ITERATOR_H 00017 00018 #include <stddef.h> 00019 00020 #include "MNRopeIteratorBase.h" 00021 #include "MNRopeRep.h" 00022 #include "MNRefProxy.h" 00023 00028 class MNRope; 00029 00030 inline void pft( MNRopeIteratorBase& dest, const MNRopeIteratorBase& src ) 00031 { 00032 dest = src; 00033 } 00034 00035 class MNRopeIterator 00036 : public MNRopeIteratorBase 00037 { 00038 friend class MNRope; 00039 00040 protected: 00041 MNRope* _M_root_rope; 00042 00043 // root is treated as a cached version of this, 00044 // and is used to detect changes to the underlying 00045 // rope. 00046 // Root is included in the reference count. 00047 // This is necessary so that we can detect changes reliably. 00048 // Unfortunately, it requires careful bookkeeping for the 00049 // nonGC case. 00050 MNRopeIterator(MNRope* __r, size_t __pos); 00051 00052 void _M_check(); 00053 00054 public: 00055 typedef MNRefProxy reference; 00056 typedef MNRefProxy* pointer; 00057 00058 public: 00059 MNRope& container() 00060 { 00061 return *_M_root_rope; 00062 } 00063 00064 MNRopeIterator() 00065 { 00066 _M_root = 0; // Needed for reference counting. 00067 }; 00068 00069 MNRopeIterator(const MNRopeIterator& __x) 00070 : MNRopeIteratorBase(__x) 00071 { 00072 _M_root_rope = __x._M_root_rope; 00073 MNRopeRep::_S_ref(_M_root); 00074 } 00075 00076 MNRopeIterator(MNRope& __r, size_t __pos); 00077 00078 ~MNRopeIterator() 00079 { 00080 MNRopeRep::_S_unref(_M_root); 00081 } 00082 00083 MNRopeIterator& operator= (const MNRopeIterator& __x) 00084 { 00085 MNRopeRep* __old = _M_root; 00086 00087 MNRopeRep::_S_ref(__x._M_root); 00088 if (0 != __x._M_buf_ptr) { 00089 _M_root_rope = __x._M_root_rope; 00090 // *(static_cast<MNRopeIteratorBase*>(this)) = __x; 00091 // xlC 3.1.4 is too old for true ANSI 00092 pft(*this,__x); 00093 } else { 00094 _M_current_pos = __x._M_current_pos; 00095 _M_root = __x._M_root; 00096 _M_root_rope = __x._M_root_rope; 00097 _M_buf_ptr = 0; 00098 } 00099 MNRopeRep::_S_unref(__old); 00100 return(*this); 00101 } 00102 00103 reference operator*() 00104 { 00105 _M_check(); 00106 if (0 == _M_buf_ptr) { 00107 return MNRefProxy( 00108 _M_root_rope, _M_current_pos); 00109 } else { 00110 return MNRefProxy( 00111 _M_root_rope, _M_current_pos, *_M_buf_ptr); 00112 } 00113 } 00114 MNRopeIterator& operator++() { 00115 _M_incr(1); 00116 return *this; 00117 } 00118 00119 MNRopeIterator& operator+=(ptrdiff_t __n) 00120 { 00121 if (__n >= 0) { 00122 _M_incr(__n); 00123 } else { 00124 _M_decr(-__n); 00125 } 00126 return *this; 00127 } 00128 00129 MNRopeIterator& operator--() 00130 { 00131 _M_decr(1); 00132 return *this; 00133 } 00134 00135 MNRopeIterator& operator-=(ptrdiff_t __n) 00136 { 00137 if (__n >= 0) { 00138 _M_decr(__n); 00139 } else { 00140 _M_incr(-__n); 00141 } 00142 return *this; 00143 } 00144 00145 MNRopeIterator operator++(int) 00146 { 00147 size_t __old_pos = _M_current_pos; 00148 _M_incr(1); 00149 return MNRopeIterator(_M_root_rope, __old_pos); 00150 } 00151 00152 MNRopeIterator operator--(int) 00153 { 00154 size_t __old_pos = _M_current_pos; 00155 _M_decr(1); 00156 return MNRopeIterator(_M_root_rope, __old_pos); 00157 } 00158 00159 reference operator[](ptrdiff_t __n) 00160 { 00161 return MNRefProxy( 00162 _M_root_rope, _M_current_pos + __n); 00163 } 00164 00165 friend bool operator== 00166 (const MNRopeIterator& __x, 00167 const MNRopeIterator& __y); 00168 00169 friend bool operator< 00170 (const MNRopeIterator& __x, 00171 const MNRopeIterator& __y); 00172 00173 friend ptrdiff_t operator- 00174 (const MNRopeIterator& __x, 00175 const MNRopeIterator& __y); 00176 00177 friend MNRopeIterator operator- 00178 (const MNRopeIterator& __x, ptrdiff_t __n); 00179 00180 friend MNRopeIterator operator+ 00181 (const MNRopeIterator& __x, ptrdiff_t __n); 00182 00183 friend MNRopeIterator operator+ 00184 (ptrdiff_t __n, const MNRopeIterator& __x); 00185 }; 00186 00187 MNRopeIterator operator- (const MNRopeIterator& __x, ptrdiff_t __n); 00188 MNRopeIterator operator+ (const MNRopeIterator& __x, ptrdiff_t __n); 00189 MNRopeIterator operator+ (ptrdiff_t __n, const MNRopeIterator& __x); 00190 00191 bool operator== (const MNRopeIterator& __x, const MNRopeIterator& __y); 00192 bool operator< (const MNRopeIterator& __x, const MNRopeIterator& __y); 00193 ptrdiff_t operator- (const MNRopeIterator& __x, const MNRopeIterator& __y); 00194 00195 inline bool operator== (const MNRopeIterator& __x, const MNRopeIterator& __y) 00196 { 00197 return (__x._M_current_pos == __y._M_current_pos && 00198 __x._M_root_rope == __y._M_root_rope); 00199 } 00200 00201 inline bool operator< (const MNRopeIterator& __x, const MNRopeIterator& __y) 00202 { 00203 return (__x._M_current_pos < __y._M_current_pos); 00204 } 00205 00206 inline bool operator!= (const MNRopeIterator& __x, const MNRopeIterator& __y) 00207 { 00208 return !(__x == __y); 00209 } 00210 00211 inline bool operator> (const MNRopeIterator& __x, const MNRopeIterator& __y) 00212 { 00213 return __y < __x; 00214 } 00215 00216 inline bool operator<= (const MNRopeIterator& __x, const MNRopeIterator& __y) 00217 { 00218 return !(__y < __x); 00219 } 00220 00221 inline bool operator>= (const MNRopeIterator& __x, const MNRopeIterator& __y) 00222 { 00223 return !(__x < __y); 00224 } 00225 00226 inline ptrdiff_t operator-(const MNRopeIterator& __x, const MNRopeIterator& __y) 00227 { 00228 return (ptrdiff_t)__x._M_current_pos - (ptrdiff_t)__y._M_current_pos; 00229 } 00230 00231 inline MNRopeIterator operator-(const MNRopeIterator& __x, ptrdiff_t __n) 00232 { 00233 return MNRopeIterator( __x._M_root_rope, __x._M_current_pos - __n); 00234 } 00235 00236 inline MNRopeIterator operator+(const MNRopeIterator& __x, ptrdiff_t __n) 00237 { 00238 return MNRopeIterator( __x._M_root_rope, __x._M_current_pos + __n); 00239 } 00240 00241 inline MNRopeIterator operator+(ptrdiff_t __n, const MNRopeIterator& __x) 00242 { 00243 return MNRopeIterator( __x._M_root_rope, __x._M_current_pos + __n); 00244 } 00245 00247 00248 #endif /* _R_ITERATOR_H */ 00249

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8