00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #if !defined(OO_DDL_TRANSLATION)
00012 #include "CdbBdbShared/CdbBdbSAbsBtreeItr.hh"
00013 #endif // OO_DDL_TRANSLATION
00014
00015 #include "CdbBdbShared/CdbBdbSAbsBtree.hh"
00016
00017 #include <assert.h>
00018
00019 template< class K,
00020 class FCP,
00021 class ORDER >
00022 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::CdbBdbSAbsBtreeItr( const CdbBdbSAbsBtree<K,FCP,ORDER>* theTreePtr ) :
00023 _myTreePtr(theTreePtr),
00024 _isValid(false),
00025 _hasEverBeenAdvanced(false)
00026 {
00027 assert( 0 != theTreePtr );
00028 }
00029
00030 template< class K,
00031 class FCP,
00032 class ORDER >
00033 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::CdbBdbSAbsBtreeItr( const CdbBdbSAbsBtreeItr<K,FCP,ORDER>& theItr ) :
00034 _myTreePtr(theItr._myTreePtr),
00035 _isValid(theItr._isValid),
00036 _hasEverBeenAdvanced(theItr._hasEverBeenAdvanced),
00037 _node(theItr._node),
00038 _nodeValue(theItr._nodeValue),
00039 _currentElement(theItr._currentElement)
00040 { }
00041
00042 template< class K,
00043 class FCP,
00044 class ORDER >
00045 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::~CdbBdbSAbsBtreeItr( )
00046 { }
00047
00048 template< class K,
00049 class FCP,
00050 class ORDER >
00051 CdbStatus
00052 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::reset( )
00053 {
00054 _isValid = false;
00055 _hasEverBeenAdvanced = false;
00056
00057 return CdbStatus::Success;
00058 }
00059
00060 template< class K,
00061 class FCP,
00062 class ORDER >
00063 bool
00064 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::backToParent( )
00065 {
00066 bool result = false;
00067 do {
00068
00069
00070
00071 if( 0 == _nodeValue.parent ) break;
00072
00073 d_ULong subjectNode = _node;
00074
00075 _node = _nodeValue.parent;
00076 _nodeValue = _myTreePtr->readNode( _node );
00077
00078 for( int i = 0; i <= _nodeValue.n; ++i ) {
00079 if( subjectNode == _nodeValue.child[i] ) {
00080
00081 if( i == _nodeValue.n ) {
00082
00083
00084
00085
00086
00087 result = backToParent( );
00088
00089 } else {
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 _currentElement = i;
00104
00105 result = true;
00106 }
00107 break;
00108 }
00109 }
00110
00111 } while( false );
00112
00113 return result;
00114 }
00115
00116 template< class K,
00117 class FCP,
00118 class ORDER >
00119 bool
00120 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::next( )
00121 {
00122 if( _hasEverBeenAdvanced ) {
00123
00124 ++_currentElement;
00125
00126 if( _nodeValue.isLeaf ) {
00127
00128
00129
00130
00131
00132
00133
00134 if( _currentElement >= _nodeValue.n ) {
00135
00136 if( ! backToParent( )) {
00137
00138
00139
00140
00141 _isValid = false;
00142 _hasEverBeenAdvanced = false;
00143 }
00144 }
00145
00146 } else {
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 _node = _nodeValue.child[_currentElement];
00157 _nodeValue = _myTreePtr->readNode( _node );
00158
00159
00160
00161
00162
00163
00164
00165
00166 while( ! _nodeValue.isLeaf ) {
00167 _node = _nodeValue.child[0];
00168 _nodeValue = _myTreePtr->readNode( _node );
00169 }
00170 _currentElement = 0;
00171 }
00172
00173 } else {
00174
00175
00176
00177
00178
00179
00180 _node = _myTreePtr->root( );
00181 _nodeValue = _myTreePtr->readNode( _node );
00182
00183 while( ! _nodeValue.isLeaf ) {
00184 _node = _nodeValue.child[0];
00185 _nodeValue = _myTreePtr->readNode( _node );
00186 }
00187
00188
00189
00190
00191
00192 if( _nodeValue.n > 0 ) {
00193
00194 _isValid = true;
00195 _hasEverBeenAdvanced = true;
00196
00197 _currentElement = 0;
00198 }
00199 }
00200 return _isValid;
00201 }
00202
00203 template< class K,
00204 class FCP,
00205 class ORDER >
00206 typename CdbBdbSAbsBtreeItr<K,FCP,ORDER>::ValueType
00207 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::value( )
00208 {
00209 assert( _isValid );
00210
00211 return _nodeValue.key[_currentElement];
00212 }
00213
00214 template< class K,
00215 class FCP,
00216 class ORDER >
00217 bool
00218 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::isValid( )
00219 {
00220 return _isValid;
00221 }
00222
00223 template< class K,
00224 class FCP,
00225 class ORDER >
00226 typename CdbBdbSAbsBtreeItr<K,FCP,ORDER>::InterfaceType*
00227 CdbBdbSAbsBtreeItr<K,FCP,ORDER>::clone( ) const
00228 {
00229 return new CdbBdbSAbsBtreeItr<K,FCP,ORDER>( *this );
00230 }
00231
00232
00233
00234