1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rsctree.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
35 // C and C++ Includes.
40 // Programmabh�ngige Includes.
41 #include <tools/link.hxx>
42 #include <rsctree.hxx>
44 /****************** C O D E **********************************************/
46 /****************** B i N o d e ******************************************/
47 /*************************************************************************
51 |* Beschreibung NAME.DOC
52 |* Ersterstellung MM 07.02.91
53 |* Letzte Aenderung MM 07.02.91
55 *************************************************************************/
57 pLeft
= pRight
= NULL
;
60 /*************************************************************************
65 |* Ersterstellung MM 07.02.91
66 |* Letzte Aenderung MM 07.02.91
68 *************************************************************************/
72 /*************************************************************************
74 |* BiNode::EnumNodes()
77 |* Ersterstellung MM 07.02.91
78 |* Letzte Aenderung MM 07.02.91
80 *************************************************************************/
81 void BiNode::EnumNodes( Link aLink
) const{
83 Left()->EnumNodes( aLink
);
84 aLink
.Call( (BiNode
*)this );
86 Right()->EnumNodes( aLink
);
89 /*************************************************************************
91 |* BiNode::ChangeDLListBTree()
94 |* Ersterstellung MM 11.01.91
95 |* Letzte Aenderung MM 11.01.91
97 *************************************************************************/
98 BiNode
* BiNode::ChangeDLListBTree( BiNode
* pList
){
105 while( pList
->Left() )
106 pList
= pList
->Left();
108 for( nEle
= 0; pTmp
->Right(); nEle
++ )
109 pTmp
= pTmp
->Right();
112 for( i
= 0; i
< (nEle
/ 2); i
++ )
113 pMiddle
= pMiddle
->Right();
117 if( NULL
!= (pTmp
= pMiddle
->Left()) ) // rechten Zeiger auf Null
118 pTmp
->pRight
= (BiNode
*)0;
120 // linken Zeiger auf Null
121 if( NULL
!= (pRightNode
= pMiddle
->Right()) )
122 pRightNode
->pLeft
= (BiNode
*)0;
124 pMiddle
->pLeft
= ChangeDLListBTree( pList
);
125 pMiddle
->pRight
= ChangeDLListBTree( pRightNode
);
132 /*************************************************************************
134 |* BiNode::ChangeBTreeDLList()
137 |* Ersterstellung MM 11.01.91
138 |* Letzte Aenderung MM 11.01.91
140 *************************************************************************/
141 BiNode
* BiNode::ChangeBTreeDLList(){
143 BiNode
* pLL_RN
; // linke Liste rechter Knoten
146 pList
= Right()->ChangeBTreeDLList();
152 pLL_RN
= pList
= Left()->ChangeBTreeDLList();
153 while( pLL_RN
->Right() )
154 pLL_RN
= pLL_RN
->Right();
156 pLL_RN
->pRight
= this;
161 /****************** N a m e N o d e **************************************/
162 /*************************************************************************
164 |* NameNode::Remove()
167 |* Ersterstellung MM 10.07.91
168 |* Letzte Aenderung MM 10.07.91
170 *************************************************************************/
171 NameNode
* NameNode::Remove( NameNode
* pRemove
){
172 NameNode
* pRoot
= this;
173 NameNode
* pParent
= SearchParent( pRemove
);
177 && (EQUAL
== pRemove
->Compare( pParent
->Left() ) ) ){
178 pParent
->pLeft
= pRemove
->Left();
179 if( pRemove
->Right() )
180 pParent
->Insert( pRemove
->Right() );
182 else if( pParent
->Right()
183 && (EQUAL
== pRemove
->Compare( pParent
->Right() ) ) ){
184 pParent
->pRight
= pRemove
->Right();
185 if( pRemove
->Left() )
186 pParent
->Insert( pRemove
->Left() );
189 else if( EQUAL
== this->Compare( pRemove
) ){
193 Right()->Insert( Left() );
199 pRemove
->pLeft
= pRemove
->pRight
= NULL
;
205 /*************************************************************************
210 |* Ersterstellung MM 10.07.91
211 |* Letzte Aenderung MM 13.07.91
213 *************************************************************************/
214 COMPARE
NameNode::Compare( const NameNode
* pCompare
) const{
215 if( (long)this < (long)pCompare
)
217 else if( (long)this > (long)pCompare
)
223 COMPARE
NameNode::Compare( const void * pCompare
) const{
224 if( (long)this < (long)pCompare
)
226 else if( (long)this > (long)pCompare
)
232 /*************************************************************************
234 |* NameNode::SearchParent
237 |* Ersterstellung MM 10.07.91
238 |* Letzte Aenderung MM 10.07.91
240 *************************************************************************/
241 NameNode
* NameNode::SearchParent( const NameNode
* pSearch
) const{
242 // search for a parent node.
243 // return a pointer to the parent node if found.
244 // otherwise return 0.
245 int nCmp
= Compare( pSearch
);
247 if( nCmp
== GREATER
){
249 if( ((NameNode
*)Left())->Compare( pSearch
) == EQUAL
)
250 return (NameNode
*)this;
251 return ((NameNode
*)Left())->SearchParent( pSearch
);
254 else if( nCmp
== LESS
){
256 if( ((NameNode
*)Right())->Compare( pSearch
) == EQUAL
)
257 return (NameNode
*)this;
258 return ((NameNode
*)Right())->SearchParent( pSearch
);
261 return( (NameNode
*)NULL
);
264 /*************************************************************************
269 |* Ersterstellung MM 21.03.90
270 |* Letzte Aenderung MM 27.06.90
272 *************************************************************************/
273 NameNode
* NameNode::Search( const NameNode
* pSearch
) const{
274 // search for a node.
275 // return a pointer to the node if found.
276 // otherwise return 0.
277 int nCmp
= Compare( pSearch
);
279 if( nCmp
== GREATER
){
281 return ((NameNode
*)Left())->Search( pSearch
);
283 else if( nCmp
== LESS
){
285 return ((NameNode
*)Right())->Search( pSearch
);
288 return( (NameNode
*)this );
293 NameNode
* NameNode::Search( const void * pSearch
) const{
294 // search for a node.
295 // return a pointer to the node if found.
296 // otherwise return 0.
297 int nCmp
= Compare( pSearch
);
299 if( nCmp
== GREATER
){
301 return ((NameNode
*)Left())->Search( pSearch
);
303 else if( nCmp
== LESS
){
305 return ((NameNode
*)Right())->Search( pSearch
);
308 return( (NameNode
*)this );
313 /*************************************************************************
315 |* NameNode::Insert()
317 |* Beschreibung NAME.DOC
318 |* Ersterstellung MM 11.01.91
319 |* Letzte Aenderung MM 11.01.91
321 *************************************************************************/
322 BOOL
NameNode::Insert( NameNode
* pTN
, sal_uInt32
* pnDepth
){
323 // Ein Knoten wird in den Baum eingefuegt
324 // Gibt es einen Knoten mit dem gleichen Namen, dann return FALSE
325 // sonst return TRUE. Der Knoten wird auf jeden Fall eingefuegt.
328 int nCmp
= Compare( pTN
);
331 if( nCmp
== GREATER
){
333 bRet
= ((NameNode
*)Left())->Insert( pTN
, pnDepth
);
339 bRet
= ((NameNode
*)Right())->Insert( pTN
, pnDepth
);
348 /*************************************************************************
350 |* NameNode::Insert()
352 |* Beschreibung NAME.DOC
353 |* Ersterstellung MM 21.03.90
354 |* Letzte Aenderung MM 11.01.91
356 *************************************************************************/
357 BOOL
NameNode::Insert( NameNode
* pTN
){
358 // insert a node in the tree.
359 // if the node with the same name is in, return FALSE and no insert.
360 // if not return true.
361 sal_uInt32 nDepth
= 0;
364 bRet
= Insert( pTN
, &nDepth
);
368 pLeft
= ChangeDLListBTree( Left()->ChangeBTreeDLList() );
370 pRight
= ChangeDLListBTree( Right()->ChangeBTreeDLList() );
377 /*************************************************************************
379 |* NameNode::OrderTree()
382 |* Ersterstellung MM 23.09.91
383 |* Letzte Aenderung MM 23.09.91
385 *************************************************************************/
386 void NameNode::OrderTree(){
387 NameNode
* pTmpLeft
= (NameNode
*)Left();
388 NameNode
* pTmpRight
= (NameNode
*)Right();
392 SubOrderTree( pTmpLeft
);
393 SubOrderTree( pTmpRight
);
396 void NameNode::SubOrderTree( NameNode
* pOrderNode
){
398 NameNode
* pTmpLeft
= (NameNode
*)pOrderNode
->Left();
399 NameNode
* pTmpRight
= (NameNode
*)pOrderNode
->Right();
400 pOrderNode
->pLeft
= NULL
;
401 pOrderNode
->pRight
= NULL
;
402 Insert( pOrderNode
);
403 SubOrderTree( pTmpLeft
);
404 SubOrderTree( pTmpRight
);
408 /*************************************************************************
410 |* NameNode::IdOrderTree()
413 |* Ersterstellung MM 15.11.91
414 |* Letzte Aenderung MM 15.11.91
416 *************************************************************************/
420 DECL_LINK( CallBackFunc
, NameNode
* );
422 OrderCtrl() { bOrder
= FALSE
; pName
= NULL
; }
423 BOOL
IsOrder( const NameNode
* pRoot
)
427 pRoot
->EnumNodes( LINK( this, OrderCtrl
, CallBackFunc
) );
431 IMPL_LINK_INLINE_START( OrderCtrl
, CallBackFunc
, NameNode
*, pNext
)
433 if( pName
&& pName
->Compare( pNext
) != LESS
)
438 IMPL_LINK_INLINE_END( OrderCtrl
, CallBackFunc
, NameNode
*, pNext
)
440 BOOL
NameNode::IsOrderTree() const{
443 return aOrder
.IsOrder( this );
446 /****************** I d N o d e ******************************************/
447 /*************************************************************************
452 |* Ersterstellung MM 06.11.91
453 |* Letzte Aenderung MM 06.11.91
455 *************************************************************************/
456 IdNode
* IdNode::Search( sal_uInt32 nTypeName
) const{
457 return( (IdNode
*)NameNode::Search( (const void *)&nTypeName
) );
460 /*************************************************************************
465 |* Ersterstellung MM 06.11.91
466 |* Letzte Aenderung MM 06.11.91
468 *************************************************************************/
469 COMPARE
IdNode::Compare( const NameNode
* pSearch
) const
471 if( GetId() < (sal_uInt32
)(((const IdNode
*)pSearch
)->GetId()) )
473 else if( GetId() > (sal_uInt32
)(((const IdNode
*)pSearch
)->GetId()) )
479 COMPARE
IdNode::Compare( const void * pSearch
) const{
480 // pSearch ist ein Zeiger auf sal_uInt32
482 if( GetId() < *((const sal_uInt32
*)pSearch
) )
484 else if( GetId() > *((const sal_uInt32
*)pSearch
) )
490 /*************************************************************************
495 |* Ersterstellung MM 23.09.91
496 |* Letzte Aenderung MM 23.09.91
498 *************************************************************************/
499 sal_uInt32
IdNode::GetId() const
501 return( 0xFFFFFFFF );
504 /*************************************************************************
506 |* StringNode::Search()
509 |* Ersterstellung MM 06.11.91
510 |* Letzte Aenderung MM 06.11.91
512 *************************************************************************/
513 StringNode
* StringNode::Search( const char * pSearch
) const{
514 return (StringNode
*)NameNode::Search( (const void *)pSearch
);
517 /*************************************************************************
519 |* StringNode::Compare()
522 |* Ersterstellung MM 06.11.91
523 |* Letzte Aenderung MM 06.11.91
525 *************************************************************************/
526 COMPARE
StringNode::Compare( const NameNode
* pSearch
) const
528 int nCmp
= strcmp( aName
.GetBuffer(),
529 ((const StringNode
*)pSearch
)->aName
.GetBuffer() );
538 COMPARE
StringNode::Compare( const void * pSearch
) const
540 // pSearch ist ein Zeiger auf const char *
541 int nCmp
= strcmp( aName
.GetBuffer(), (const char *)pSearch
);