1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 33 #include "errhdl.hxx" // fuers ASSERT 34 #include "error.h" // fuers ASSERT 35 #include "ndindex.hxx" 36 37 #ifdef DBG_UTIL 38 int SwNodeIndex::nSerial = 0; 39 #endif 40 41 42 SwNodeRange::SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE ) 43 : aStart( rS ), aEnd( rE ) 44 {} 45 46 SwNodeRange::SwNodeRange( const SwNodeRange &rRange ) 47 : aStart( rRange.aStart ), aEnd( rRange.aEnd ) 48 {} 49 50 SwNodeRange::SwNodeRange( SwNodes& rNds, sal_uLong nSttIdx, sal_uLong nEndIdx ) 51 : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx ) 52 {} 53 54 55 SwNodeRange::SwNodeRange( const SwNodeIndex& rS, long nSttDiff, 56 const SwNodeIndex& rE, long nEndDiff ) 57 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) 58 {} 59 60 SwNodeRange::SwNodeRange( const SwNode& rS, long nSttDiff, 61 const SwNode& rE, long nEndDiff ) 62 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) 63 {} 64 65 66 SwNodeIndex::SwNodeIndex( SwNodes& rNds, sal_uLong nIdx ) 67 : pNd( rNds[ nIdx ] ), pNext( 0 ), pPrev( 0 ) 68 { 69 rNds.RegisterIndex( *this ); 70 71 #ifdef DBG_UTIL 72 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version 73 #endif 74 } 75 76 77 SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff ) 78 : pNext( 0 ), pPrev( 0 ) 79 { 80 if( nDiff ) 81 pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ]; 82 else 83 pNd = rIdx.pNd; 84 85 pNd->GetNodes().RegisterIndex( *this ); 86 #ifdef DBG_UTIL 87 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version 88 #endif 89 } 90 91 92 SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff ) 93 : pNext( 0 ), pPrev( 0 ) 94 { 95 if( nDiff ) 96 pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ]; 97 else 98 pNd = (SwNode*)&rNd; 99 100 pNd->GetNodes().RegisterIndex( *this ); 101 #ifdef DBG_UTIL 102 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version 103 #endif 104 } 105 106 107 void SwNodeIndex::Remove() 108 { 109 pNd->GetNodes().DeRegisterIndex( *this ); 110 } 111 112 SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx ) 113 { 114 if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() ) 115 { 116 pNd->GetNodes().DeRegisterIndex( *this ); 117 pNd = rIdx.pNd; 118 pNd->GetNodes().RegisterIndex( *this ); 119 } 120 else 121 pNd = rIdx.pNd; 122 return *this; 123 } 124 125 SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd ) 126 { 127 if( &pNd->GetNodes() != &rNd.GetNodes() ) 128 { 129 pNd->GetNodes().DeRegisterIndex( *this ); 130 pNd = (SwNode*)&rNd; 131 pNd->GetNodes().RegisterIndex( *this ); 132 } 133 else 134 pNd = (SwNode*)&rNd; 135 return *this; 136 } 137 138 SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, sal_uLong nIdx ) 139 { 140 if( &pNd->GetNodes() != &rNds ) 141 { 142 pNd->GetNodes().DeRegisterIndex( *this ); 143 pNd = rNds[ nIdx ]; 144 pNd->GetNodes().RegisterIndex( *this ); 145 } 146 else 147 pNd = rNds[ nIdx ]; 148 return *this; 149 } 150 151 SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset ) 152 { 153 if( &pNd->GetNodes() != &rNd.GetNodes() ) 154 { 155 pNd->GetNodes().DeRegisterIndex( *this ); 156 pNd = (SwNode*)&rNd; 157 pNd->GetNodes().RegisterIndex( *this ); 158 } 159 else 160 pNd = (SwNode*)&rNd; 161 162 if( nOffset ) 163 pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ]; 164 165 return *this; 166 } 167 168 169