1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28
29 #include "errhdl.hxx" // fuers ASSERT
30 #include "error.h" // fuers ASSERT
31 #include "ndindex.hxx"
32
33 #ifdef DBG_UTIL
34 int SwNodeIndex::nSerial = 0;
35 #endif
36
37
SwNodeRange(const SwNodeIndex & rS,const SwNodeIndex & rE)38 SwNodeRange::SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
39 : aStart( rS ), aEnd( rE )
40 {}
41
SwNodeRange(const SwNodeRange & rRange)42 SwNodeRange::SwNodeRange( const SwNodeRange &rRange )
43 : aStart( rRange.aStart ), aEnd( rRange.aEnd )
44 {}
45
SwNodeRange(SwNodes & rNds,sal_uLong nSttIdx,sal_uLong nEndIdx)46 SwNodeRange::SwNodeRange( SwNodes& rNds, sal_uLong nSttIdx, sal_uLong nEndIdx )
47 : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx )
48 {}
49
50
SwNodeRange(const SwNodeIndex & rS,long nSttDiff,const SwNodeIndex & rE,long nEndDiff)51 SwNodeRange::SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
52 const SwNodeIndex& rE, long nEndDiff )
53 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff )
54 {}
55
SwNodeRange(const SwNode & rS,long nSttDiff,const SwNode & rE,long nEndDiff)56 SwNodeRange::SwNodeRange( const SwNode& rS, long nSttDiff,
57 const SwNode& rE, long nEndDiff )
58 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff )
59 {}
60
61
SwNodeIndex(SwNodes & rNds,sal_uLong nIdx)62 SwNodeIndex::SwNodeIndex( SwNodes& rNds, sal_uLong nIdx )
63 : pNd( rNds[ nIdx ] ), pNext( 0 ), pPrev( 0 )
64 {
65 rNds.RegisterIndex( *this );
66
67 #ifdef DBG_UTIL
68 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version
69 #endif
70 }
71
72
SwNodeIndex(const SwNodeIndex & rIdx,long nDiff)73 SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
74 : pNext( 0 ), pPrev( 0 )
75 {
76 if( nDiff )
77 pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
78 else
79 pNd = rIdx.pNd;
80
81 pNd->GetNodes().RegisterIndex( *this );
82 #ifdef DBG_UTIL
83 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version
84 #endif
85 }
86
87
SwNodeIndex(const SwNode & rNd,long nDiff)88 SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff )
89 : pNext( 0 ), pPrev( 0 )
90 {
91 if( nDiff )
92 pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
93 else
94 pNd = (SwNode*)&rNd;
95
96 pNd->GetNodes().RegisterIndex( *this );
97 #ifdef DBG_UTIL
98 MySerial = ++nSerial; // nur in der nicht PRODUCT-Version
99 #endif
100 }
101
102
Remove()103 void SwNodeIndex::Remove()
104 {
105 pNd->GetNodes().DeRegisterIndex( *this );
106 }
107
operator =(const SwNodeIndex & rIdx)108 SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
109 {
110 if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() )
111 {
112 pNd->GetNodes().DeRegisterIndex( *this );
113 pNd = rIdx.pNd;
114 pNd->GetNodes().RegisterIndex( *this );
115 }
116 else
117 pNd = rIdx.pNd;
118 return *this;
119 }
120
operator =(const SwNode & rNd)121 SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
122 {
123 if( &pNd->GetNodes() != &rNd.GetNodes() )
124 {
125 pNd->GetNodes().DeRegisterIndex( *this );
126 pNd = (SwNode*)&rNd;
127 pNd->GetNodes().RegisterIndex( *this );
128 }
129 else
130 pNd = (SwNode*)&rNd;
131 return *this;
132 }
133
Assign(SwNodes & rNds,sal_uLong nIdx)134 SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, sal_uLong nIdx )
135 {
136 if( &pNd->GetNodes() != &rNds )
137 {
138 pNd->GetNodes().DeRegisterIndex( *this );
139 pNd = rNds[ nIdx ];
140 pNd->GetNodes().RegisterIndex( *this );
141 }
142 else
143 pNd = rNds[ nIdx ];
144 return *this;
145 }
146
Assign(const SwNode & rNd,long nOffset)147 SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
148 {
149 if( &pNd->GetNodes() != &rNd.GetNodes() )
150 {
151 pNd->GetNodes().DeRegisterIndex( *this );
152 pNd = (SwNode*)&rNd;
153 pNd->GetNodes().RegisterIndex( *this );
154 }
155 else
156 pNd = (SwNode*)&rNd;
157
158 if( nOffset )
159 pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ];
160
161 return *this;
162 }
163
164
165