|
yast2-storage
|
00001 /* 00002 * Copyright (c) [2004-2009] Novell, Inc. 00003 * 00004 * All Rights Reserved. 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of version 2 of the GNU General Public License as published 00008 * by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 * more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, contact Novell, Inc. 00017 * 00018 * To contact Novell about this file by physical or electronic mail, you may 00019 * find current contact information at www.novell.com. 00020 */ 00021 00022 00023 #ifndef LIST_LIST_ITERATOR_H 00024 #define LIST_LIST_ITERATOR_H 00025 00026 #include "storage/AppUtil.h" 00027 #include "storage/IterPair.h" 00028 00029 namespace storage 00030 { 00031 00032 template< class PIter, class Iter > 00033 class ListListIterator : public PIter 00034 { 00035 public: 00036 typedef typename PIter::value_type value_type; 00037 typedef typename PIter::reference reference; 00038 typedef typename PIter::pointer pointer; 00039 typedef typename PIter::difference_type difference_type; 00040 typedef typename PIter::iterator_category iterator_category; 00041 00042 ListListIterator() { } 00043 00044 ListListIterator( const Iter& begin, const Iter& end, bool setend=false ) : 00045 m_lcur(begin) 00046 { 00047 initialize( begin, end, setend ); 00048 } 00049 00050 ListListIterator( const IterPair<Iter>& p, bool setend=false ) : 00051 m_lcur(p.begin()) 00052 { 00053 initialize( p.begin(), p.end(), setend ); 00054 } 00055 00056 template< class It > 00057 ListListIterator( const It& x ) 00058 { 00059 m_begin = x.begin(); 00060 m_end = x.end(); 00061 m_lcur = x.cur(); 00062 m_pcur = x.pcur(); 00063 } 00064 00065 ListListIterator& operator=(const ListListIterator& x) 00066 { 00067 copyMembers( x ); 00068 return *this; 00069 } 00070 00071 ListListIterator& operator++() 00072 { 00073 increment(); 00074 return *this; 00075 } 00076 ListListIterator operator++(int) 00077 { 00078 y2war( "Expensive ++ ListListIterator" ); 00079 ListListIterator tmp(*this); 00080 increment(); 00081 return tmp; 00082 } 00083 00084 ListListIterator& operator--() 00085 { 00086 decrement(); 00087 return *this; 00088 } 00089 ListListIterator operator--(int) 00090 { 00091 y2war( "Expensive -- ListListIterator" ); 00092 ListListIterator tmp(*this); 00093 decrement(); 00094 return tmp; 00095 } 00096 00097 reference operator*() const 00098 { 00099 return( *m_pcur ); 00100 } 00101 00102 pointer operator->() const 00103 { 00104 return( &(*m_pcur) ); 00105 } 00106 template< class It > 00107 bool operator==(const It& x) const 00108 { 00109 return( m_pcur == x.pcur() ); 00110 } 00111 template< class It > 00112 bool operator!=(const It& x) const 00113 { 00114 return( m_pcur != x.pcur() ); 00115 } 00116 00117 PIter end() const {return m_end;} 00118 PIter begin() const {return m_begin;} 00119 PIter pcur() const {return m_pcur;} 00120 Iter cur() const {return m_lcur;} 00121 00122 private: 00123 PIter m_begin; 00124 PIter m_end; 00125 Iter m_lcur; 00126 PIter m_pcur; 00127 static const PIter empty; 00128 00129 void copyMembers( const ListListIterator& x ) 00130 { 00131 m_begin = x.begin(); 00132 m_end = x.end(); 00133 m_lcur = x.cur(); 00134 m_pcur = x.pcur(); 00135 } 00136 00137 void increment() 00138 { 00139 if( m_pcur != m_end ) 00140 { 00141 ++m_pcur; 00142 while( m_pcur!=m_end && m_pcur == m_lcur->end() ) 00143 { 00144 ++m_lcur; 00145 m_pcur = m_lcur->begin(); 00146 } 00147 } 00148 }; 00149 00150 void decrement() 00151 { 00152 if( m_pcur != m_begin ) 00153 { 00154 if( m_pcur != m_lcur->begin() ) 00155 { 00156 --m_pcur; 00157 } 00158 else 00159 { 00160 do 00161 { 00162 --m_lcur; 00163 m_pcur = --(m_lcur->end()); 00164 } 00165 while( m_pcur!=m_begin && 00166 m_lcur->begin()==m_lcur->end() ); 00167 } 00168 } 00169 }; 00170 00171 void initialize( const Iter& begin, const Iter& end, bool setend ) 00172 { 00173 m_begin = m_end = m_pcur = empty; 00174 while( m_lcur != end && m_lcur->begin()==m_lcur->end() ) 00175 { 00176 ++m_lcur; 00177 } 00178 if( m_lcur != end ) 00179 m_begin = m_lcur->begin(); 00180 if( begin != end ) 00181 { 00182 Iter tmp = end; 00183 --tmp; 00184 while( tmp != begin && tmp->begin()==tmp->end() ) 00185 { 00186 --tmp; 00187 } 00188 if( tmp != begin || begin->begin()!=begin->end()) 00189 { 00190 m_end = tmp->end(); 00191 } 00192 if( setend ) 00193 { 00194 m_pcur = m_end; 00195 m_lcur = tmp; 00196 } 00197 else 00198 m_pcur = m_begin; 00199 } 00200 } 00201 00202 }; 00203 00204 template< typename PIter, typename Iter > const PIter ListListIterator<PIter,Iter>::empty = PIter(); 00205 00206 } 00207 00208 #endif
1.7.3