1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_rsc.hxx"
30 /****************** I N C L U D E S **************************************/
32 // C and C++ Includes.
37 // Programmabh�ngige Includes.
38 #include <tools/link.hxx>
39 #include <rsctree.hxx>
41 /****************** C O D E **********************************************/
43 /****************** B i N o d e ******************************************/
44 /*************************************************************************
48 |* Beschreibung NAME.DOC
49 |* Ersterstellung MM 07.02.91
50 |* Letzte Aenderung MM 07.02.91
52 *************************************************************************/
54 pLeft
= pRight
= NULL
;
57 /*************************************************************************
62 |* Ersterstellung MM 07.02.91
63 |* Letzte Aenderung MM 07.02.91
65 *************************************************************************/
69 /*************************************************************************
71 |* BiNode::EnumNodes()
74 |* Ersterstellung MM 07.02.91
75 |* Letzte Aenderung MM 07.02.91
77 *************************************************************************/
78 void BiNode::EnumNodes( Link aLink
) const{
80 Left()->EnumNodes( aLink
);
81 aLink
.Call( (BiNode
*)this );
83 Right()->EnumNodes( aLink
);
86 /*************************************************************************
88 |* BiNode::ChangeDLListBTree()
91 |* Ersterstellung MM 11.01.91
92 |* Letzte Aenderung MM 11.01.91
94 *************************************************************************/
95 BiNode
* BiNode::ChangeDLListBTree( BiNode
* pList
){
102 while( pList
->Left() )
103 pList
= pList
->Left();
105 for( nEle
= 0; pTmp
->Right(); nEle
++ )
106 pTmp
= pTmp
->Right();
109 for( i
= 0; i
< (nEle
/ 2); i
++ )
110 pMiddle
= pMiddle
->Right();
114 if( NULL
!= (pTmp
= pMiddle
->Left()) ) // rechten Zeiger auf Null
115 pTmp
->pRight
= (BiNode
*)0;
117 // linken Zeiger auf Null
118 if( NULL
!= (pRightNode
= pMiddle
->Right()) )
119 pRightNode
->pLeft
= (BiNode
*)0;
121 pMiddle
->pLeft
= ChangeDLListBTree( pList
);
122 pMiddle
->pRight
= ChangeDLListBTree( pRightNode
);
129 /*************************************************************************
131 |* BiNode::ChangeBTreeDLList()
134 |* Ersterstellung MM 11.01.91
135 |* Letzte Aenderung MM 11.01.91
137 *************************************************************************/
138 BiNode
* BiNode::ChangeBTreeDLList(){
140 BiNode
* pLL_RN
; // linke Liste rechter Knoten
143 pList
= Right()->ChangeBTreeDLList();
149 pLL_RN
= pList
= Left()->ChangeBTreeDLList();
150 while( pLL_RN
->Right() )
151 pLL_RN
= pLL_RN
->Right();
153 pLL_RN
->pRight
= this;
158 /****************** N a m e N o d e **************************************/
159 /*************************************************************************
161 |* NameNode::Remove()
164 |* Ersterstellung MM 10.07.91
165 |* Letzte Aenderung MM 10.07.91
167 *************************************************************************/
168 NameNode
* NameNode::Remove( NameNode
* pRemove
){
169 NameNode
* pRoot
= this;
170 NameNode
* pParent
= SearchParent( pRemove
);
174 && (EQUAL
== pRemove
->Compare( pParent
->Left() ) ) ){
175 pParent
->pLeft
= pRemove
->Left();
176 if( pRemove
->Right() )
177 pParent
->Insert( pRemove
->Right() );
179 else if( pParent
->Right()
180 && (EQUAL
== pRemove
->Compare( pParent
->Right() ) ) ){
181 pParent
->pRight
= pRemove
->Right();
182 if( pRemove
->Left() )
183 pParent
->Insert( pRemove
->Left() );
186 else if( EQUAL
== this->Compare( pRemove
) ){
190 Right()->Insert( Left() );
196 pRemove
->pLeft
= pRemove
->pRight
= NULL
;
202 /*************************************************************************
207 |* Ersterstellung MM 10.07.91
208 |* Letzte Aenderung MM 13.07.91
210 *************************************************************************/
211 COMPARE
NameNode::Compare( const NameNode
* pCompare
) const{
212 if( (long)this < (long)pCompare
)
214 else if( (long)this > (long)pCompare
)
220 COMPARE
NameNode::Compare( const void * pCompare
) const{
221 if( (long)this < (long)pCompare
)
223 else if( (long)this > (long)pCompare
)
229 /*************************************************************************
231 |* NameNode::SearchParent
234 |* Ersterstellung MM 10.07.91
235 |* Letzte Aenderung MM 10.07.91
237 *************************************************************************/
238 NameNode
* NameNode::SearchParent( const NameNode
* pSearch
) const{
239 // search for a parent node.
240 // return a pointer to the parent node if found.
241 // otherwise return 0.
242 int nCmp
= Compare( pSearch
);
244 if( nCmp
== GREATER
){
246 if( ((NameNode
*)Left())->Compare( pSearch
) == EQUAL
)
247 return (NameNode
*)this;
248 return ((NameNode
*)Left())->SearchParent( pSearch
);
251 else if( nCmp
== LESS
){
253 if( ((NameNode
*)Right())->Compare( pSearch
) == EQUAL
)
254 return (NameNode
*)this;
255 return ((NameNode
*)Right())->SearchParent( pSearch
);
258 return( (NameNode
*)NULL
);
261 /*************************************************************************
266 |* Ersterstellung MM 21.03.90
267 |* Letzte Aenderung MM 27.06.90
269 *************************************************************************/
270 NameNode
* NameNode::Search( const NameNode
* pSearch
) const{
271 // search for a node.
272 // return a pointer to the node if found.
273 // otherwise return 0.
274 int nCmp
= Compare( pSearch
);
276 if( nCmp
== GREATER
){
278 return ((NameNode
*)Left())->Search( pSearch
);
280 else if( nCmp
== LESS
){
282 return ((NameNode
*)Right())->Search( pSearch
);
285 return( (NameNode
*)this );
290 NameNode
* NameNode::Search( const void * pSearch
) const{
291 // search for a node.
292 // return a pointer to the node if found.
293 // otherwise return 0.
294 int nCmp
= Compare( pSearch
);
296 if( nCmp
== GREATER
){
298 return ((NameNode
*)Left())->Search( pSearch
);
300 else if( nCmp
== LESS
){
302 return ((NameNode
*)Right())->Search( pSearch
);
305 return( (NameNode
*)this );
310 /*************************************************************************
312 |* NameNode::Insert()
314 |* Beschreibung NAME.DOC
315 |* Ersterstellung MM 11.01.91
316 |* Letzte Aenderung MM 11.01.91
318 *************************************************************************/
319 sal_Bool
NameNode::Insert( NameNode
* pTN
, sal_uInt32
* pnDepth
){
320 // Ein Knoten wird in den Baum eingefuegt
321 // Gibt es einen Knoten mit dem gleichen Namen, dann return sal_False
322 // sonst return sal_True. Der Knoten wird auf jeden Fall eingefuegt.
324 sal_Bool bRet
= sal_True
;
325 int nCmp
= Compare( pTN
);
328 if( nCmp
== GREATER
){
330 bRet
= ((NameNode
*)Left())->Insert( pTN
, pnDepth
);
336 bRet
= ((NameNode
*)Right())->Insert( pTN
, pnDepth
);
345 /*************************************************************************
347 |* NameNode::Insert()
349 |* Beschreibung NAME.DOC
350 |* Ersterstellung MM 21.03.90
351 |* Letzte Aenderung MM 11.01.91
353 *************************************************************************/
354 sal_Bool
NameNode::Insert( NameNode
* pTN
){
355 // insert a node in the tree.
356 // if the node with the same name is in, return sal_False and no insert.
357 // if not return true.
358 sal_uInt32 nDepth
= 0;
361 bRet
= Insert( pTN
, &nDepth
);
365 pLeft
= ChangeDLListBTree( Left()->ChangeBTreeDLList() );
367 pRight
= ChangeDLListBTree( Right()->ChangeBTreeDLList() );
374 /*************************************************************************
376 |* NameNode::OrderTree()
379 |* Ersterstellung MM 23.09.91
380 |* Letzte Aenderung MM 23.09.91
382 *************************************************************************/
383 void NameNode::OrderTree(){
384 NameNode
* pTmpLeft
= (NameNode
*)Left();
385 NameNode
* pTmpRight
= (NameNode
*)Right();
389 SubOrderTree( pTmpLeft
);
390 SubOrderTree( pTmpRight
);
393 void NameNode::SubOrderTree( NameNode
* pOrderNode
){
395 NameNode
* pTmpLeft
= (NameNode
*)pOrderNode
->Left();
396 NameNode
* pTmpRight
= (NameNode
*)pOrderNode
->Right();
397 pOrderNode
->pLeft
= NULL
;
398 pOrderNode
->pRight
= NULL
;
399 Insert( pOrderNode
);
400 SubOrderTree( pTmpLeft
);
401 SubOrderTree( pTmpRight
);
405 /*************************************************************************
407 |* NameNode::IdOrderTree()
410 |* Ersterstellung MM 15.11.91
411 |* Letzte Aenderung MM 15.11.91
413 *************************************************************************/
417 DECL_LINK( CallBackFunc
, NameNode
* );
419 OrderCtrl() { bOrder
= sal_False
; pName
= NULL
; }
420 sal_Bool
IsOrder( const NameNode
* pRoot
)
424 pRoot
->EnumNodes( LINK( this, OrderCtrl
, CallBackFunc
) );
428 IMPL_LINK_INLINE_START( OrderCtrl
, CallBackFunc
, NameNode
*, pNext
)
430 if( pName
&& pName
->Compare( pNext
) != LESS
)
435 IMPL_LINK_INLINE_END( OrderCtrl
, CallBackFunc
, NameNode
*, pNext
)
437 sal_Bool
NameNode::IsOrderTree() const{
440 return aOrder
.IsOrder( this );
443 /****************** I d N o d e ******************************************/
444 /*************************************************************************
449 |* Ersterstellung MM 06.11.91
450 |* Letzte Aenderung MM 06.11.91
452 *************************************************************************/
453 IdNode
* IdNode::Search( sal_uInt32 nTypeName
) const{
454 return( (IdNode
*)NameNode::Search( (const void *)&nTypeName
) );
457 /*************************************************************************
462 |* Ersterstellung MM 06.11.91
463 |* Letzte Aenderung MM 06.11.91
465 *************************************************************************/
466 COMPARE
IdNode::Compare( const NameNode
* pSearch
) const
468 if( GetId() < (sal_uInt32
)(((const IdNode
*)pSearch
)->GetId()) )
470 else if( GetId() > (sal_uInt32
)(((const IdNode
*)pSearch
)->GetId()) )
476 COMPARE
IdNode::Compare( const void * pSearch
) const{
477 // pSearch ist ein Zeiger auf sal_uInt32
479 if( GetId() < *((const sal_uInt32
*)pSearch
) )
481 else if( GetId() > *((const sal_uInt32
*)pSearch
) )
487 /*************************************************************************
492 |* Ersterstellung MM 23.09.91
493 |* Letzte Aenderung MM 23.09.91
495 *************************************************************************/
496 sal_uInt32
IdNode::GetId() const
498 return( 0xFFFFFFFF );
501 /*************************************************************************
503 |* StringNode::Search()
506 |* Ersterstellung MM 06.11.91
507 |* Letzte Aenderung MM 06.11.91
509 *************************************************************************/
510 StringNode
* StringNode::Search( const char * pSearch
) const{
511 return (StringNode
*)NameNode::Search( (const void *)pSearch
);
514 /*************************************************************************
516 |* StringNode::Compare()
519 |* Ersterstellung MM 06.11.91
520 |* Letzte Aenderung MM 06.11.91
522 *************************************************************************/
523 COMPARE
StringNode::Compare( const NameNode
* pSearch
) const
525 int nCmp
= strcmp( aName
.GetBuffer(),
526 ((const StringNode
*)pSearch
)->aName
.GetBuffer() );
535 COMPARE
StringNode::Compare( const void * pSearch
) const
537 // pSearch ist ein Zeiger auf const char *
538 int nCmp
= strcmp( aName
.GetBuffer(), (const char *)pSearch
);