Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

HrefIdMap.cpp

Go to the documentation of this file.
00001 // /******************************************************************************\
00002 // *
00003 // * File:          HrefIdMap.cpp
00004 // * Creation date: June 11, 2001 11:05
00005 // * Author:        ClassBuilder
00006 // *                XXXX
00007 // * Purpose:       Method implementations of class 'HrefIdMap'
00008 // *
00009 // * Modifications: @INSERT_MODIFICATIONS(* )
00010 // * June 12, 2001 09:25 WERS
00011 // *     Updated code of method 'RealNode'
00012 // *     Updated code of method 'RealNode'
00013 // * June 12, 2001 09:22 WERS
00014 // *     Added method 'RealNode'
00015 // * June 11, 2001 11:41 WERS
00016 // *     Added method 'RealNode'
00017 // * June 11, 2001 11:09 WERS
00018 // *     Added method 'Build'
00019 // * June 11, 2001 11:05 WERS
00020 // *     Added method 'FindReverseHrefId'
00021 // *     Added method 'FindHrefId'
00022 // *     Added method 'FindEqualOrSmallerHrefId'
00023 // *     Added method 'FindEqualOrBiggerHrefId'
00024 // *     Added method 'DestructorInclude'
00025 // *     Added method 'ConstructorInclude'
00026 // *     Added method '~HrefIdMap'
00027 // *     Added method 'HrefIdMap'
00028 // *     Added relation 'HrefIdMap <>-->> HrefId'
00029 // *
00030 // *
00031 // \******************************************************************************/
00032 //@START_USER1
00037 /* --------------------------------------------------------------
00038 Copyright (C) 2001 LifeLine Networks BV <soap2corba@lifeline.nl>
00039 
00040 This program is free software; you can redistribute it and/or
00041 modify it under the terms of the GNU General Public License
00042 as published by the Free Software Foundation; either
00043 version 2 of the License, or (at your option) any later
00044 version.
00045 
00046 This program is distributed in the hope that it will be useful,
00047 but WITHOUT ANY WARRANTY; without even the implied warranty of
00048 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00049 GNU General Public License for more details.
00050 
00051 You should have received a copy of the GNU General Public License
00052 along with this program; if not, write to the Free Software
00053 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00054 -------------------------------------------------------------- */
00055 //@END_USER1
00056 
00057 
00058 // Master include file
00059 #include "StdAfx.h"
00060 
00061 
00062 //@START_USER2
00063 
00070 static void RecurseDOM (DOM_Node &node, HrefIdMap *pMap)
00071 {
00072     if (node == NULL) return;
00073     DOMTRACE(node.getNodeName ());
00074     switch (node.getNodeType())
00075     {
00076     case DOM_Node::TEXT_NODE:
00077         {
00078         }
00079         break;
00080     case DOM_Node::PROCESSING_INSTRUCTION_NODE :
00081         {
00082         }
00083         break;
00084     case DOM_Node::DOCUMENT_NODE :
00085         {
00086             DOM_Node child = node.getFirstChild();
00087             while (child != 0) {
00088                 RecurseDOM (child, pMap);
00089                 child = child.getNextSibling();
00090             }
00091         }
00092         break;
00093     case DOM_Node::ELEMENT_NODE :
00094         {
00095             DOM_NamedNodeMap attributes = node.getAttributes();
00096             int attrCount = attributes.getLength();
00097             DOMString isId ("id");
00098             for (int i = 0; i < attrCount; i++) {
00099                 DOM_Node attribute = attributes.item (i);
00100                 DOMTRACE(attribute.getNodeName ());
00101                 if (attribute.getNodeName ().equals (isId)) {
00102                     DOMString nval (attribute.getNodeValue ());
00103                     (void) new HrefId (pMap, nval, node);
00104                 }
00105             }
00106             DOM_Node child = node.getFirstChild();
00107             while (child != 0) {
00108                 RecurseDOM (child, pMap);
00109                 child = child.getNextSibling();
00110             }
00111         }
00112         break;
00113     default: break;
00114     }
00115 }
00116 //@END_USER2
00117 
00118 
00119 // Static members
00120 
00121 
00125 HrefIdMap::HrefIdMap() //@INIT_116
00126 {//@CODE_116
00127     ConstructorInclude();
00128 
00129     // Put in your own code
00130 }//@CODE_116
00131 
00132 
00136 HrefIdMap::~HrefIdMap()
00137 {//@CODE_34
00138     DestructorInclude();
00139 
00140     // Put in your own code
00141 }//@CODE_34
00142 
00143 
00144 void HrefIdMap::Build(DOM_Node& rNode)
00145 {//@CODE_125
00146     RecurseDOM (rNode, this);
00147 }//@CODE_125
00148 
00149 
00156 void HrefIdMap::RealNode(DOM_Node& rRealNode, DOM_Node& rFakeNode)
00157 {//@CODE_127
00158     if (rFakeNode != 0 && rFakeNode.getNodeType() == DOM_Node::ELEMENT_NODE) {
00159         DOM_NamedNodeMap attributes = rFakeNode.getAttributes();
00160         int attrCount = attributes.getLength();
00161         DOMString isHref ("href");
00162         for (int i = 0; i < attrCount; i++) {
00163             DOM_Node attribute = attributes.item (i);
00164             DOMTRACE(attribute.getNodeName ());
00165             if (attribute.getNodeName ().equals (isHref)) {
00166                 DOMTRACE(attribute.getNodeValue ());
00167                 char *href = attribute.getNodeValue ().transcode ();
00168                 HrefId *pId = (href [0] != '#') ? NULL : FindHrefId (href + 1);
00169                 rRealNode = (pId == NULL) ? rFakeNode : pId->m_node;
00170                 return;
00171             }
00172         }
00173     }
00174     rRealNode = rFakeNode;
00175 }//@CODE_127
00176 
00177 
00185 void HrefIdMap::RealNode(DOM_Element& rElement, DOM_Node& rFakeNode)
00186 {//@CODE_130
00187     rElement = NULL;
00188     DOM_Node realNode;
00189     RealNode (realNode, rFakeNode);
00190     if (realNode != NULL && realNode.getNodeType () == DOM_Node::ELEMENT_NODE) {
00191         rElement = *((DOM_Element *) &realNode);
00192     }
00193 }//@CODE_130
00194 
00195 
00196 //{{AFX DO NOT EDIT CODE BELOW THIS LINE !!!
00197 
00201 void HrefIdMap::ConstructorInclude()
00202 {
00203     // INIT_AVLTREE_OWNED_ACTIVE(HrefIdMap, HrefIdMap, HrefId, HrefId)
00204    
00205     _topHrefId = (HrefId*)0;
00206     _countHrefId = 0;
00207 }
00208 
00209 
00213 void HrefIdMap::DestructorInclude()
00214 {
00215     // EXIT_AVLTREE_OWNED_ACTIVE(HrefIdMap, HrefIdMap, HrefId, HrefId)
00216     while (_topHrefId)
00217     {
00218         delete _topHrefId;
00219     }
00220 }
00221 
00222 
00223 HrefId* HrefIdMap::FindEqualOrBiggerHrefId(const CString& id)
00224 {
00225     // BODY_AVLTREE_FINDEQUALORBIGGER(m_id, id, HrefIdMap, HrefIdMap, HrefId, HrefId)
00226     HrefId* result = 0;
00227     if (_topHrefId)
00228     {
00229         HrefId* item = _topHrefId;
00230         while (1)
00231         {
00232             if (item->m_id == id)
00233             {
00234                 result = item;
00235                 HrefId* prevHrefId = GetPrevHrefId(result);
00236                 while (prevHrefId && prevHrefId->m_id == id)
00237                 {
00238                     result = prevHrefId;
00239                     prevHrefId = GetPrevHrefId(result);
00240                 }
00241                 break;
00242             }
00243 
00244             if (id <= item->m_id)
00245             {
00246                 if (item->_leftHrefIdMap)
00247                 {
00248                     item = item->_leftHrefIdMap;
00249                 }
00250                 else
00251                 {
00252                     result = item;
00253                     break;
00254                 }
00255             }
00256             else
00257             {
00258                 if (item->_rightHrefIdMap)
00259                 {
00260                     item = item->_rightHrefIdMap;
00261                 }
00262                 else
00263                 {
00264                     result = GetNextHrefId(item);
00265                     break;
00266                 }
00267             }
00268         }
00269     }
00270 
00271     return result;
00272 }
00273 
00274 
00275 HrefId* HrefIdMap::FindEqualOrSmallerHrefId(const CString& id)
00276 {
00277     // BODY_AVLTREE_FINDEQUALORSMALLER(m_id, id, HrefIdMap, HrefIdMap, HrefId, HrefId)
00278     HrefId* result = 0;
00279     if (_topHrefId)
00280     {
00281         HrefId* item = _topHrefId;
00282         while (1)
00283         {
00284             if (item->m_id == id)
00285             {
00286                 result = item;
00287                 HrefId* nextHrefId = GetNextHrefId(result);
00288                 while (nextHrefId && nextHrefId->m_id == id)
00289                 {
00290                     result = nextHrefId;
00291                     nextHrefId = GetNextHrefId(result);
00292                 }
00293                 break;
00294             }
00295 
00296             if (id <= item->m_id)
00297             {
00298                 if (item->_leftHrefIdMap)
00299                 {
00300                     item = item->_leftHrefIdMap;
00301                 }
00302                 else
00303                 {
00304                     result = GetPrevHrefId(item);
00305                     break;
00306                 }
00307             }
00308             else
00309             {
00310                 if (item->_rightHrefIdMap)
00311                 {
00312                     item = item->_rightHrefIdMap;
00313                 }
00314                 else
00315                 {
00316                     result = item;
00317                     break;
00318                 }
00319             }
00320         }
00321     }
00322 
00323     return result;
00324 }
00325 
00326 
00327 HrefId* HrefIdMap::FindHrefId(const CString& id)
00328 {
00329     // BODY_AVLTREE_FIND(m_id, id, HrefIdMap, HrefIdMap, HrefId, HrefId)
00330     
00331     HrefId* result = 0;
00332     if (_topHrefId)
00333     {
00334         HrefId* item = _topHrefId;
00335         while (1)
00336         {
00337             if (item->m_id == id)
00338             {
00339                 result = item;
00340                 break;
00341             }
00342 
00343             if (id <= item->m_id)
00344             {
00345                 if (item->_leftHrefIdMap)
00346                 {
00347                     item = item->_leftHrefIdMap;
00348                 }
00349                 else
00350                 {
00351                     break;
00352                 }
00353             }
00354             else
00355             {
00356                 if (item->_rightHrefIdMap)
00357                 {
00358                     item = item->_rightHrefIdMap;
00359                 }
00360                 else
00361                 {
00362                     break;
00363                 }
00364             }
00365         }
00366     } 
00367     if (result)
00368     {
00369         HrefId* prevHrefId = GetPrevHrefId(result);
00370         while (prevHrefId && prevHrefId->m_id == id)
00371         {
00372             result = prevHrefId;
00373             prevHrefId = GetPrevHrefId(result);
00374         }
00375     }
00376     return result;
00377 }
00378 
00379 
00380 HrefId* HrefIdMap::FindReverseHrefId(const CString& id)
00381 {
00382     // BODY_AVLTREE_FINDREVERSE(m_id, id, HrefIdMap, HrefIdMap, HrefId, HrefId)
00383     
00384     HrefId* result = 0;
00385     if (_topHrefId)
00386     {
00387         HrefId* item = _topHrefId;
00388         while (1)
00389         {
00390             if (item->m_id == id)
00391             {
00392                 result = item;
00393                 break;
00394             }
00395 
00396             if (id <= item->m_id)
00397             {
00398                 if (item->_leftHrefIdMap)
00399                 {
00400                     item = item->_leftHrefIdMap;
00401                 }
00402                 else
00403                 {
00404                     break;
00405                 }
00406             }
00407             else
00408             {
00409                 if (item->_rightHrefIdMap)
00410                 {
00411                     item = item->_rightHrefIdMap;
00412                 }
00413                 else
00414                 {
00415                     break;
00416                 }
00417             }
00418         }
00419     } 
00420     if (result)
00421     {
00422         HrefId* nextHrefId = GetNextHrefId(result);
00423         while (nextHrefId && nextHrefId->m_id == id)
00424         {
00425             result = nextHrefId;
00426             nextHrefId = GetNextHrefId(result);
00427         }
00428     }
00429     return result;
00430 }
00431 
00432 
00433 // Methods for the relation(s) of the class
00434 // METHODS_AVLTREE_OWNED_ACTIVE(m_id, HrefIdMap, HrefIdMap, HrefId, HrefId)
00435 void HrefIdMap::AddHrefId(HrefId* item)
00436 {
00437     
00438     assert(this);
00439 
00440     assert(item);
00441     assert(item->_refHrefIdMap == (HrefIdMap*)0);
00442 
00443     _countHrefId++;
00444 
00445     item->_refHrefIdMap = this;
00446 
00447     if (_topHrefId)
00448     {
00449         HrefId* current = _topHrefId;
00450         while (1)
00451         {
00452             if (item->m_id < current->m_id)
00453             {
00454                 if (current->_leftHrefIdMap)
00455                 {
00456                     current = current->_leftHrefIdMap;
00457                 }
00458                 else
00459                 {
00460                     current->_leftHrefIdMap = item;
00461                     item->_parentHrefIdMap = current;
00462                     current->_balHrefIdMap--;
00463                     break;
00464                 }
00465             }
00466             else
00467             {
00468                 if (current->_rightHrefIdMap)
00469                 {
00470                     current = current->_rightHrefIdMap;
00471                 }
00472                 else
00473                 {
00474                     current->_rightHrefIdMap = item;
00475                     item->_parentHrefIdMap = current;
00476                     current->_balHrefIdMap++;
00477                     break;
00478                 }
00479             }
00480         }
00481 
00482         HrefId* parent;
00483         while (current && current->_balHrefIdMap)
00484         {
00485             parent = current->_parentHrefIdMap;
00486             if (parent)
00487             {
00488                 if (parent->_leftHrefIdMap == current)
00489                 {
00490                     parent->_balHrefIdMap--;
00491                 }
00492                 else
00493                 {
00494                     parent->_balHrefIdMap++;
00495                 }
00496 
00497                 if (parent->_balHrefIdMap == 2)
00498                 {
00499                     if (current->_balHrefIdMap == -1)
00500                     {
00501                         HrefId* sub = current->_leftHrefIdMap;
00502                         parent->_rightHrefIdMap = sub->_leftHrefIdMap;
00503                         if (sub->_leftHrefIdMap)
00504                         {
00505                             sub->_leftHrefIdMap->_parentHrefIdMap = parent;
00506                         }
00507                         current->_leftHrefIdMap = sub->_rightHrefIdMap;
00508                         if (sub->_rightHrefIdMap)
00509                         {
00510                             sub->_rightHrefIdMap->_parentHrefIdMap = current;
00511                         }
00512                         sub->_parentHrefIdMap = parent->_parentHrefIdMap;
00513                         sub->_leftHrefIdMap = parent;
00514                         parent->_parentHrefIdMap = sub;
00515                         sub->_rightHrefIdMap = current;
00516                         current->_parentHrefIdMap = sub;
00517                         if (sub->_parentHrefIdMap)
00518                         {
00519                             if (sub->_parentHrefIdMap->_leftHrefIdMap == parent)
00520                             {
00521                                 sub->_parentHrefIdMap->_leftHrefIdMap = sub;
00522                             }
00523                             else
00524                             {
00525                                 sub->_parentHrefIdMap->_rightHrefIdMap = sub;
00526                             }
00527                         }
00528                         else
00529                         {
00530                             _topHrefId = sub;
00531                         }
00532                         parent->_balHrefIdMap = (sub->_balHrefIdMap == 1? -1: 0);
00533                         current->_balHrefIdMap = (sub->_balHrefIdMap == -1? 1: 0);
00534                         sub->_balHrefIdMap = 0;
00535                         current = sub;
00536                     }
00537                     else
00538                     {
00539                         parent->_rightHrefIdMap = current->_leftHrefIdMap;
00540                         if (current->_leftHrefIdMap)
00541                         {
00542                             current->_leftHrefIdMap->_parentHrefIdMap = parent;
00543                         }
00544                         current->_leftHrefIdMap = parent;
00545                         current->_parentHrefIdMap = parent->_parentHrefIdMap;
00546                         parent->_parentHrefIdMap = current;
00547                         if (current->_parentHrefIdMap)
00548                         {
00549                             if (current->_parentHrefIdMap->_leftHrefIdMap == parent)
00550                             {
00551                                 current->_parentHrefIdMap->_leftHrefIdMap = current;
00552                             }
00553                             else
00554                             {
00555                                 current->_parentHrefIdMap->_rightHrefIdMap = current;
00556                             }
00557                         }
00558                         else
00559                         {
00560                             _topHrefId = current;
00561                         }
00562                         parent->_balHrefIdMap = 0;
00563                         current->_balHrefIdMap = 0;
00564                     }
00565                 }
00566                 else if (parent->_balHrefIdMap == -2)
00567                 {
00568                     if (current->_balHrefIdMap == 1)
00569                     {
00570                         HrefId* sub = current->_rightHrefIdMap;
00571                         parent->_leftHrefIdMap = sub->_rightHrefIdMap;
00572                         if (sub->_rightHrefIdMap)
00573                         {
00574                             sub->_rightHrefIdMap->_parentHrefIdMap = parent;
00575                         }
00576                         current->_rightHrefIdMap = sub->_leftHrefIdMap;
00577                         if (sub->_leftHrefIdMap)
00578                         {
00579                             sub->_leftHrefIdMap->_parentHrefIdMap = current;
00580                         }
00581                         sub->_parentHrefIdMap = parent->_parentHrefIdMap;
00582                         sub->_rightHrefIdMap = parent;
00583                         parent->_parentHrefIdMap = sub;
00584                         sub->_leftHrefIdMap = current;
00585                         current->_parentHrefIdMap = sub;
00586                         if (sub->_parentHrefIdMap)
00587                         {
00588                             if (sub->_parentHrefIdMap->_rightHrefIdMap == parent)
00589                             {
00590                                 sub->_parentHrefIdMap->_rightHrefIdMap = sub;
00591                             }
00592                             else
00593                             {
00594                                 sub->_parentHrefIdMap->_leftHrefIdMap = sub;
00595                             }
00596                         }
00597                         else
00598                         {
00599                             _topHrefId = sub;
00600                         }
00601                         parent->_balHrefIdMap = (sub->_balHrefIdMap == -1? 1: 0);
00602                         current->_balHrefIdMap = (sub->_balHrefIdMap == 1? -1: 0);
00603                         sub->_balHrefIdMap = 0;
00604                         current = sub;
00605                     }
00606                     else
00607                     {
00608                         parent->_leftHrefIdMap = current->_rightHrefIdMap;
00609                         if (current->_rightHrefIdMap)
00610                         {
00611                             current->_rightHrefIdMap->_parentHrefIdMap = parent;
00612                         }
00613                         current->_rightHrefIdMap = parent;
00614                         current->_parentHrefIdMap = parent->_parentHrefIdMap;
00615                         parent->_parentHrefIdMap = current;
00616                         if (current->_parentHrefIdMap)
00617                         {
00618                             if (current->_parentHrefIdMap->_rightHrefIdMap == parent)
00619                             {
00620                                 current->_parentHrefIdMap->_rightHrefIdMap = current;
00621                             }
00622                             else
00623                             {
00624                                 current->_parentHrefIdMap->_leftHrefIdMap = current;
00625                             }
00626                         }
00627                         else
00628                         {
00629                             _topHrefId = current;
00630                         }
00631                         parent->_balHrefIdMap = 0;
00632                         current->_balHrefIdMap = 0;
00633                     }
00634                 }
00635                 else
00636                 {
00637                     current = parent;
00638                 }
00639             }
00640             else
00641             {
00642                 current = parent;
00643             }
00644         }
00645     }
00646     else
00647     {
00648         _topHrefId = item;
00649     } 
00650 }
00651 
00652 void HrefIdMap::RemoveHrefId(HrefId* item)
00653 {
00654     
00655     assert(this);
00656 
00657     assert(item);
00658     assert(item->_refHrefIdMap == this);
00659 
00660     HrefIdMap::HrefIdIterator::Check(item);
00661 
00662     _countHrefId--;
00663 
00664     HrefId* subParent = item->_parentHrefIdMap;
00665     HrefId* sub = item;
00666     /*     item               -                                   */
00667     /*      ^        ==>                                          */
00668     /*     - -                                                    */
00669     if (!item->_leftHrefIdMap && !item->_rightHrefIdMap)
00670     {
00671         if (subParent)
00672         {
00673             if (subParent->_leftHrefIdMap == item)
00674             {
00675                 subParent->_leftHrefIdMap = (HrefId*)0;
00676                 subParent->_balHrefIdMap++;
00677             }
00678             else
00679             {
00680                 subParent->_rightHrefIdMap = (HrefId*)0;
00681                 subParent->_balHrefIdMap--;
00682             }
00683         }
00684         else
00685         {
00686             _topHrefId = (HrefId*)0;
00687         }
00688     }
00689     else
00690     {
00691         if (item->_balHrefIdMap > 0)
00692         {
00693             sub = item->_rightHrefIdMap;
00694             while (sub->_leftHrefIdMap)
00695             {
00696                 sub = sub->_leftHrefIdMap;
00697             }
00698             subParent = sub->_parentHrefIdMap;
00699             if (subParent != item)
00700             {
00701                 subParent->_leftHrefIdMap = sub->_rightHrefIdMap;
00702                 if (subParent->_leftHrefIdMap)
00703                 {
00704                     subParent->_leftHrefIdMap->_parentHrefIdMap = subParent;
00705                 }
00706                 subParent->_balHrefIdMap++;
00707             }
00708             else
00709             {
00710                 item->_balHrefIdMap--;
00711             }
00712         }
00713         else
00714         {
00715             sub = item->_leftHrefIdMap;
00716             while (sub->_rightHrefIdMap)
00717             {
00718                 sub = sub->_rightHrefIdMap;
00719             }
00720             subParent = sub->_parentHrefIdMap;
00721             if (subParent != item)
00722             {
00723                 subParent->_rightHrefIdMap = sub->_leftHrefIdMap;
00724                 if (subParent->_rightHrefIdMap)
00725                 {
00726                     subParent->_rightHrefIdMap->_parentHrefIdMap = subParent;
00727                 }
00728                 subParent->_balHrefIdMap--;
00729             }
00730             else
00731             {
00732                 item->_balHrefIdMap++;
00733             }
00734         }
00735         sub->_parentHrefIdMap = item->_parentHrefIdMap;
00736         if (item->_parentHrefIdMap)
00737         {
00738             if (item->_parentHrefIdMap->_leftHrefIdMap == item)
00739             {
00740                 item->_parentHrefIdMap->_leftHrefIdMap = sub;
00741             }
00742             else
00743             {
00744                 item->_parentHrefIdMap->_rightHrefIdMap = sub;
00745             }
00746         }
00747         else
00748         {
00749             _topHrefId = sub;
00750         }
00751         if (item->_leftHrefIdMap != sub)
00752         {
00753             sub->_leftHrefIdMap = item->_leftHrefIdMap;
00754             if (item->_leftHrefIdMap)
00755             {
00756                 item->_leftHrefIdMap->_parentHrefIdMap = sub;
00757             }
00758         }
00759         if (item->_rightHrefIdMap != sub)
00760         {
00761             sub->_rightHrefIdMap = item->_rightHrefIdMap;
00762             if (item->_rightHrefIdMap)
00763             {
00764                 item->_rightHrefIdMap->_parentHrefIdMap = sub;
00765             }
00766         }
00767         sub->_balHrefIdMap = item->_balHrefIdMap;
00768 
00769         if (subParent == item)
00770         {
00771             subParent = sub;
00772         }
00773     }
00774 
00775     item->_refHrefIdMap = (HrefIdMap*)0;
00776     item->_parentHrefIdMap = (HrefId*)0;
00777     item->_leftHrefIdMap = (HrefId*)0;
00778     item->_rightHrefIdMap = (HrefId*)0;
00779     item->_balHrefIdMap = 0;
00780 
00781     HrefId* parent = subParent;
00782     while (parent && parent->_balHrefIdMap != -1 && parent->_balHrefIdMap != 1)
00783     {
00784         if (parent->_balHrefIdMap == 2)
00785         {
00786             HrefId* current = parent->_rightHrefIdMap;
00787             if (current->_balHrefIdMap == -1)
00788             {
00789                 HrefId* sub = current->_leftHrefIdMap;
00790                 parent->_rightHrefIdMap = sub->_leftHrefIdMap;
00791                 if (sub->_leftHrefIdMap)
00792                 {
00793                     sub->_leftHrefIdMap->_parentHrefIdMap = parent;
00794                 }
00795                 current->_leftHrefIdMap = sub->_rightHrefIdMap;
00796                 if (sub->_rightHrefIdMap)
00797                 {
00798                     sub->_rightHrefIdMap->_parentHrefIdMap = current;
00799                 }
00800                 sub->_parentHrefIdMap = parent->_parentHrefIdMap;
00801                 sub->_leftHrefIdMap = parent;
00802                 parent->_parentHrefIdMap = sub;
00803                 sub->_rightHrefIdMap = current;
00804                 current->_parentHrefIdMap = sub;
00805                 if (sub->_parentHrefIdMap)
00806                 {
00807                     if (sub->_parentHrefIdMap->_leftHrefIdMap == parent)
00808                     {
00809                         sub->_parentHrefIdMap->_leftHrefIdMap = sub;
00810                     }
00811                     else
00812                     {
00813                         sub->_parentHrefIdMap->_rightHrefIdMap = sub;
00814                     }
00815                 }
00816                 else
00817                 {
00818                     _topHrefId = sub;
00819                 }
00820                 parent->_balHrefIdMap = (sub->_balHrefIdMap == 1? -1: 0);
00821                 current->_balHrefIdMap = (sub->_balHrefIdMap == -1? 1: 0);
00822                 sub->_balHrefIdMap = 0;
00823                 parent = sub;
00824             }
00825             else if (current->_balHrefIdMap == 1)
00826             {
00827                 parent->_rightHrefIdMap = current->_leftHrefIdMap;
00828                 if (current->_leftHrefIdMap)
00829                 {
00830                     current->_leftHrefIdMap->_parentHrefIdMap = parent;
00831                 }
00832                 current->_leftHrefIdMap = parent;
00833                 current->_parentHrefIdMap = parent->_parentHrefIdMap;
00834                 parent->_parentHrefIdMap = current;
00835                 if (current->_parentHrefIdMap)
00836                 {
00837                     if (current->_parentHrefIdMap->_leftHrefIdMap == parent)
00838                     {
00839                         current->_parentHrefIdMap->_leftHrefIdMap = current;
00840                     }
00841                     else
00842                     {
00843                         current->_parentHrefIdMap->_rightHrefIdMap = current;
00844                     }
00845                 }
00846                 else
00847                 {
00848                     _topHrefId = current;
00849                 }
00850                 parent->_balHrefIdMap = 0;
00851                 current->_balHrefIdMap = 0;
00852                 parent = current;
00853             }
00854             else
00855             {
00856                 parent->_rightHrefIdMap = current->_leftHrefIdMap;
00857                 if (current->_leftHrefIdMap)
00858                 {
00859                     current->_leftHrefIdMap->_parentHrefIdMap = parent;
00860                 }
00861                 current->_leftHrefIdMap = parent;
00862                 current->_parentHrefIdMap = parent->_parentHrefIdMap;
00863                 parent->_parentHrefIdMap = current;
00864                 if (current->_parentHrefIdMap)
00865                 {
00866                     if (current->_parentHrefIdMap->_leftHrefIdMap == parent)
00867                     {
00868                         current->_parentHrefIdMap->_leftHrefIdMap = current;
00869                     }
00870                     else
00871                     {
00872                         current->_parentHrefIdMap->_rightHrefIdMap = current;
00873                     }
00874                 }
00875                 else
00876                 {
00877                     _topHrefId = current;
00878                 }
00879                 parent->_balHrefIdMap = 1;
00880                 current->_balHrefIdMap = -1;
00881                 break;
00882             }
00883         }
00884         else if (parent->_balHrefIdMap == -2)
00885         {
00886             HrefId* current = parent->_leftHrefIdMap;
00887             if (current->_balHrefIdMap == 1)
00888             {
00889                 HrefId* sub = current->_rightHrefIdMap;
00890                 parent->_leftHrefIdMap = sub->_rightHrefIdMap;
00891                 if (sub->_rightHrefIdMap)
00892                 {
00893                     sub->_rightHrefIdMap->_parentHrefIdMap = parent;
00894                 }
00895                 current->_rightHrefIdMap = sub->_leftHrefIdMap;
00896                 if (sub->_leftHrefIdMap)
00897                 {
00898                     sub->_leftHrefIdMap->_parentHrefIdMap = current;
00899                 }
00900                 sub->_parentHrefIdMap = parent->_parentHrefIdMap;
00901                 sub->_rightHrefIdMap = parent;
00902                 parent->_parentHrefIdMap = sub;
00903                 sub->_leftHrefIdMap = current;
00904                 current->_parentHrefIdMap = sub;
00905                 if (sub->_parentHrefIdMap)
00906                 {
00907                     if (sub->_parentHrefIdMap->_rightHrefIdMap == parent)
00908                     {
00909                         sub->_parentHrefIdMap->_rightHrefIdMap = sub;
00910                     }
00911                     else
00912                     {
00913                         sub->_parentHrefIdMap->_leftHrefIdMap = sub;
00914                     }
00915                 }
00916                 else
00917                 {
00918                     _topHrefId = sub;
00919                 }
00920                 parent->_balHrefIdMap = (sub->_balHrefIdMap == -1? 1: 0);
00921                 current->_balHrefIdMap = (sub->_balHrefIdMap == 1? -1: 0);
00922                 sub->_balHrefIdMap = 0;
00923                 parent = sub;
00924             }
00925             else if (current->_balHrefIdMap == -1)
00926             {
00927                 parent->_leftHrefIdMap = current->_rightHrefIdMap;
00928                 if (current->_rightHrefIdMap)
00929                 {
00930                     current->_rightHrefIdMap->_parentHrefIdMap = parent;
00931                 }
00932                 current->_rightHrefIdMap = parent;
00933                 current->_parentHrefIdMap = parent->_parentHrefIdMap;
00934                 parent->_parentHrefIdMap = current;
00935                 if (current->_parentHrefIdMap)
00936                 {
00937                     if (current->_parentHrefIdMap->_rightHrefIdMap == parent)
00938                     {
00939                         current->_parentHrefIdMap->_rightHrefIdMap = current;
00940                     }
00941                     else
00942                     {
00943                         current->_parentHrefIdMap->_leftHrefIdMap = current;
00944                     }
00945                 }
00946                 else
00947                 {
00948                     _topHrefId = current;
00949                 }
00950                 parent->_balHrefIdMap = 0;
00951                 current->_balHrefIdMap = 0;
00952                 parent = current;
00953             }
00954             else
00955             {
00956                 parent->_leftHrefIdMap = current->_rightHrefIdMap;
00957                 if (current->_rightHrefIdMap)
00958                 {
00959                     current->_rightHrefIdMap->_parentHrefIdMap = parent;
00960                 }
00961                 current->_rightHrefIdMap = parent;
00962                 current->_parentHrefIdMap = parent->_parentHrefIdMap;
00963                 parent->_parentHrefIdMap = current;
00964                 if (current->_parentHrefIdMap)
00965                 {
00966                     if (current->_parentHrefIdMap->_rightHrefIdMap == parent)
00967                     {
00968                         current->_parentHrefIdMap->_rightHrefIdMap = current;
00969                     }
00970                     else
00971                     {
00972                         current->_parentHrefIdMap->_leftHrefIdMap = current;
00973                     }
00974                 }
00975                 else
00976                 {
00977                     _topHrefId = current;
00978                 }
00979                 parent->_balHrefIdMap = -1;
00980                 current->_balHrefIdMap = 1;
00981                 break;
00982             }
00983         }
00984 
00985         if (parent->_parentHrefIdMap)
00986         {
00987             if (parent->_parentHrefIdMap->_leftHrefIdMap == parent)
00988             {
00989                 parent->_parentHrefIdMap->_balHrefIdMap++;
00990             }
00991             else
00992             {
00993                 parent->_parentHrefIdMap->_balHrefIdMap--;
00994             }
00995         }
00996 
00997         parent = parent->_parentHrefIdMap;
00998     }
00999  
01000 }
01001 
01002 void HrefIdMap::DeleteAllHrefId()
01003 {
01004     
01005     assert(this);
01006 
01007     while (_topHrefId)
01008     {
01009         delete _topHrefId;
01010     } 
01011 }
01012 
01013 void HrefIdMap::ReplaceHrefId(HrefId* item, HrefId* newItem)
01014 {
01015     
01016     assert(this);
01017 
01018     assert(item);
01019     assert(item->_refHrefIdMap == this);
01020 
01021     assert(newItem);
01022     assert(newItem->_refHrefIdMap == (HrefIdMap*)0);
01023 
01024     if (item->m_id == newItem->m_id)
01025     {
01026         HrefIdMap::HrefIdIterator::Check(item, newItem);
01027         if (_topHrefId == item)
01028         {
01029             _topHrefId = newItem;
01030         }
01031         if (item->_parentHrefIdMap)
01032         {
01033             if (item->_parentHrefIdMap->_leftHrefIdMap == item)
01034             {
01035                 item->_parentHrefIdMap->_leftHrefIdMap = newItem;
01036             }
01037             else if (item->_parentHrefIdMap->_rightHrefIdMap == item)
01038             {
01039                 item->_parentHrefIdMap->_rightHrefIdMap = newItem;
01040             }
01041         }
01042         newItem->_refHrefIdMap = this;
01043         newItem->_parentHrefIdMap = item->_parentHrefIdMap;
01044         newItem->_leftHrefIdMap = item->_leftHrefIdMap;
01045         newItem->_rightHrefIdMap = item->_rightHrefIdMap;
01046         newItem->_balHrefIdMap = item->_balHrefIdMap;
01047         item->_refHrefIdMap = (HrefIdMap*)0;
01048         item->_parentHrefIdMap = (HrefId*)0;
01049         item->_leftHrefIdMap = (HrefId*)0;
01050         item->_rightHrefIdMap = (HrefId*)0;
01051         item->_balHrefIdMap = 0;
01052     }
01053     else
01054     {
01055         HrefIdMap::HrefIdIterator::Check(item);
01056         RemoveHrefId(item);
01057         AddHrefId(newItem);
01058     } 
01059 }
01060 
01061 HrefId* HrefIdMap::GetFirstHrefId() const
01062 {
01063     
01064     assert(this);
01065 
01066     HrefId* result = _topHrefId;
01067     if (result)
01068     {
01069         while (result->_leftHrefIdMap)
01070         {
01071             result = result->_leftHrefIdMap;
01072         }
01073     }
01074 
01075     return result; 
01076 }
01077 
01078 HrefId* HrefIdMap::GetLastHrefId() const
01079 {
01080     
01081     assert(this);
01082 
01083     HrefId* result = _topHrefId;
01084     if (result)
01085     {
01086         while (result->_rightHrefIdMap)
01087         {
01088             result = result->_rightHrefIdMap;
01089         }
01090     }
01091 
01092     return result; 
01093 }
01094 
01095 HrefId* HrefIdMap::GetNextHrefId(HrefId* pos) const
01096 {
01097     
01098     assert(this);
01099 
01100     HrefId* result = 0;
01101     if (pos == (HrefId*)0)
01102     {
01103         result = _topHrefId;
01104         if (result)
01105         {
01106             while (result->_leftHrefIdMap)
01107             {
01108                 result = result->_leftHrefIdMap;
01109             }
01110         }
01111     }
01112     else
01113     {
01114         assert(pos->_refHrefIdMap == this);
01115 
01116         if (pos->_rightHrefIdMap)
01117         {
01118             result = pos->_rightHrefIdMap;
01119             while (result->_leftHrefIdMap)
01120             {
01121                 result = result->_leftHrefIdMap;
01122             }
01123         }
01124         else
01125         {
01126             result = pos->_parentHrefIdMap;
01127             while (result && result->_rightHrefIdMap == pos)
01128             {
01129                 pos = result;
01130                 result = pos->_parentHrefIdMap;
01131             }
01132         }
01133     }
01134 
01135     return result; 
01136 }
01137 
01138 HrefId* HrefIdMap::GetPrevHrefId(HrefId* pos) const
01139 {
01140     
01141     assert(this);
01142 
01143     HrefId* result = 0;
01144     if (pos == (HrefId*)0)
01145     {
01146         result = _topHrefId;
01147         if (result)
01148         {
01149             while (result->_rightHrefIdMap)
01150             {
01151                 result = result->_rightHrefIdMap;
01152             }
01153         }
01154     }
01155     else
01156     {
01157         assert(pos->_refHrefIdMap == this);
01158 
01159         if (pos->_leftHrefIdMap)
01160         {
01161             result = pos->_leftHrefIdMap;
01162             while (result->_rightHrefIdMap)
01163             {
01164                 result = result->_rightHrefIdMap;
01165             }
01166         }
01167         else
01168         {
01169             result = pos->_parentHrefIdMap;
01170             while (result && result->_leftHrefIdMap == pos)
01171             {
01172                 pos = result;
01173                 result = pos->_parentHrefIdMap;
01174             }
01175         }
01176     }
01177 
01178     return result; 
01179 }
01180 
01181 int HrefIdMap::GetHrefIdCount() const
01182 {
01183     
01184     assert(this);
01185     return _countHrefId; 
01186 }
01187 // METHODS_ITERATOR_MULTI_ACTIVE(HrefIdMap, HrefIdMap, HrefId, HrefId)
01188 HrefIdMap::HrefIdIterator* HrefIdMap::HrefIdIterator::_first = 0;
01189 HrefIdMap::HrefIdIterator* HrefIdMap::HrefIdIterator::_last = 0;
01190 
01191 HrefIdMap::HrefIdIterator::HrefIdIterator(
01192     const HrefIdMap* iterHrefIdMap,
01193     int (HrefId::*method)() const,
01194     HrefId* refHrefId)
01195 {
01196     assert(iterHrefIdMap);
01197 
01198     _iterHrefIdMap = iterHrefIdMap;
01199     _refHrefId = _prevHrefId = _nextHrefId = refHrefId;
01200     _prev = (HrefIdIterator*)0;
01201     _next = (HrefIdIterator*)0;
01202     _method = method;
01203     if (_last)
01204     {
01205         _last->_next = this;
01206         _prev = _last;
01207         _last = this;
01208     }
01209     else
01210         _first = _last = this;
01211 }
01212 
01213 HrefIdMap::HrefIdIterator::HrefIdIterator(
01214     const HrefIdMap& iterHrefIdMap,
01215     int (HrefId::*method)() const,
01216     HrefId* refHrefId)
01217 {
01218     assert(&iterHrefIdMap);
01219 
01220     _iterHrefIdMap = &iterHrefIdMap;
01221     _refHrefId = _prevHrefId = _nextHrefId = refHrefId;
01222     _prev = (HrefIdIterator*)0;
01223     _next = (HrefIdIterator*)0;
01224     _method = method;
01225     if (_last)
01226     {
01227         _last->_next = this;
01228         _prev = _last;
01229         _last = this;
01230     }
01231     else
01232         _first = _last = this;
01233 }
01234 
01235 HrefIdMap::HrefIdIterator::HrefIdIterator(
01236     const HrefIdIterator& iterator,
01237     int (HrefId::*method)() const)
01238 {
01239     _iterHrefIdMap = iterator._iterHrefIdMap;
01240     _refHrefId = iterator._refHrefId;
01241     _prevHrefId = iterator._prevHrefId;
01242     _nextHrefId = iterator._nextHrefId;
01243     _prev = (HrefIdIterator*)0;
01244     _next = (HrefIdIterator*)0;
01245     _method = method;
01246     if (_last)
01247     {
01248         _last->_next = this;
01249         _prev = _last;
01250         _last = this;
01251     }
01252     else
01253         _first = _last = this;
01254 }
01255 
01256 HrefIdMap::HrefIdIterator::~HrefIdIterator()
01257 {
01258     if (_next)
01259         _next->_prev = _prev;
01260     else
01261         _last = _prev;
01262 
01263     if (_prev)
01264         _prev->_next = _next;
01265     else
01266         _first = _next;
01267 }
01268 
01269 void HrefIdMap::HrefIdIterator::Check(HrefId* itemHrefId)
01270 {
01271     for (HrefIdIterator* item = _first; item; item = item->_next)
01272     {
01273         if (item->_prevHrefId == itemHrefId)
01274         {
01275             item->_prevHrefId = item->_iterHrefIdMap->GetNextHrefId(item->_prevHrefId);
01276             item->_refHrefId = 0;
01277         }
01278         if (item->_nextHrefId == itemHrefId)
01279         {
01280             item->_nextHrefId = item->_iterHrefIdMap->GetPrevHrefId(item->_nextHrefId);
01281             item->_refHrefId = 0;
01282         }
01283     }
01284 }
01285 
01286 void HrefIdMap::HrefIdIterator::Check(HrefId* itemHrefId, HrefId* newItemHrefId)
01287 {
01288     for (HrefIdIterator* item = _first; item; item = item->_next)
01289     {
01290         if (item->_refHrefId == itemHrefId)
01291         {
01292             item->_refHrefId = item->_prevHrefId = item->_nextHrefId = newItemHrefId;
01293         }
01294         if (item->_prevHrefId == itemHrefId)
01295         {
01296             item->_prevHrefId = newItemHrefId;
01297             item->_refHrefId = 0;
01298         }
01299         if (item->_nextHrefId == itemHrefId)
01300         {
01301             item->_nextHrefId = newItemHrefId;
01302             item->_refHrefId = 0;
01303         }
01304     }
01305 }
01306 
01307 //}}AFX DO NOT EDIT CODE ABOVE THIS LINE !!!
01308 
01309 //@START_USER3
01310 

This documentation is part of the "SOAP to CORBA bridge" project
Copyright © 2000 by Lifeline Networks bv.
All rights are reserved.