00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #if defined(AMBIGUOUS_STRING_FUNCTIONS_BUG)
00044 #include <string>
00045 #endif
00046
00047 #if defined(STL_TEMPLATE_DEFAULT_PARAMS_FIRST_BUG)
00048 #include <vector>
00049 #include <algorithm>
00050 #endif
00051
00052
00053
00054
00055 #include "Lattice/LatticeBase.h"
00056 #include "MessageService/MsgService.h"
00057 CVSID("$Id: LatticeBase.cxx,v 1.2 2000/05/10 10:07:04 west Exp $");
00058
00059
00060
00061
00062 #include <vector>
00063 #include <algorithm>
00064
00065
00066
00067
00068 const char* const kLLString = "Lattice.LatticeBase";
00069
00070
00071
00072
00073 LatticeBase::
00074 LatticeBase(LatticeTopology i,
00075 LatticeTopology j,
00076 LatticeTopology k,
00077 LatticeTopology l)
00078 : m_LeftNodes (*new LeftNodes),
00079 m_RightNodes(*new RightNodes),
00080 m_Links (*new Links),
00081 m_VLeftID (*new VectorLeftID),
00082 m_VRightID (*new VectorRightID)
00083 {
00084 MSG("Lat",Msg::kDebug) << "In ctor()." << endl;
00085
00086
00087
00088
00089
00090 for (int index=0; index < 5; m_Topology[index++] = false);
00091 m_Topology[i] = true;
00092 m_Topology[j] = true;
00093 m_Topology[k] = true;
00094 m_Topology[l] = true;
00095 MSG("Lat",Msg::kDebug) << "Topology is" << "Sorry, not available yet" << endl;
00096 }
00097
00098
00099
00100
00101
00102 LatticeBase::
00103 ~LatticeBase()
00104 {
00105 MSG("Lat",Msg::kDebug) << "in Lattice dtor()" << endl;
00106
00107 for (LeftNodes::iterator i = m_LeftNodes.begin();
00108 i != m_LeftNodes.end(); ++i)
00109 {
00110 delete *i;
00111 }
00112 delete &m_LeftNodes;
00113 delete &m_VLeftID;
00114
00115 for (RightNodes::iterator j = m_RightNodes.begin();
00116 j != m_RightNodes.end(); ++j)
00117 {
00118 delete *j;
00119 }
00120 delete &m_RightNodes;
00121 delete &m_VRightID;
00122
00123 for (LinkItr k = m_Links.begin(); k != m_Links.end(); ++k)
00124 {
00125 delete *k;
00126 }
00127 delete &m_Links;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 LatticeBase::Link*
00139 LatticeBase::
00140 connect(LeftID leftID, RightID rightID, const LinkData& LinkData)
00141 {
00142
00143
00144
00145 LeftNode* pLN = leftNode(leftID);
00146 LeftNode* lNode = (pLN)? pLN : newLeftNode(leftID);
00147
00148 RightNode* pRN = rightNode(rightID);
00149 RightNode* rNode = (pRN)? pRN : newRightNode(rightID);
00150
00151
00152 if (checkLNtopo(lNode) && checkRNtopo(rNode))
00153 {
00154 Link* link = new Link(lNode, rNode, LinkData);
00155 m_Links.push_back(link);
00156
00157
00158
00159 lNode->m_Links .push_back(link);
00160 rNode->m_Links .push_back(link);
00161 lNode->m_VRightID.push_back(rightID);
00162 rNode->m_VLeftID .push_back(leftID);
00163
00164 return link;
00165 }
00166
00167 MSG("Lat",Msg::kWarning)
00168 << " connect attempts to violate topology constraint." << endl;
00169 return 0;
00170 }
00171
00172
00173 LatticeBase::Link*
00174 LatticeBase::
00175 connect(LeftID leftID, RightID rightID)
00176 {
00177
00178
00179 LeftNode* pLN = leftNode(leftID);
00180 LeftNode* lNode = (pLN)? pLN : newLeftNode(leftID);
00181
00182 RightNode* pRN = rightNode(rightID);
00183 RightNode* rNode = (pRN)? pRN : newRightNode(rightID);
00184
00185
00186 if (checkLNtopo(lNode) && checkRNtopo(rNode))
00187 {
00188 Link* link = new Link(lNode, rNode);
00189 m_Links.push_back(link);
00190
00191
00192
00193 lNode->m_Links .push_back(link);
00194 rNode->m_Links .push_back(link);
00195 lNode->m_VRightID.push_back(rightID);
00196 rNode->m_VLeftID .push_back(leftID);
00197
00198 return link;
00199 }
00200
00201 MSG("Lat",Msg::kWarning)
00202 << " connect attempts to violate topology constraint." << endl;
00203 return 0;
00204 }
00205
00206
00207 LatticeBase::Link*
00208 LatticeBase::
00209 connect(LeftID lid, Link& link, RightID rid)
00210 {
00211 VectorLeftID& ld = link.m_VLeftID;
00212 VectorRightID& rd = link.m_VRightID;
00213 LeftNode* pLeft = leftNode (lid);
00214 RightNode* pRight = rightNode(rid);
00215
00216
00217 if ( ( find(ld.begin(),ld.end(),lid) != ld.end()
00218 || (checkLNtopo(pLeft) && checkLLtopo(link)) )
00219 && ( find(rd.begin(),rd.end(),rid) != rd.end()
00220 || (checkRNtopo(pRight)&& checkRLtopo(link)) ) )
00221 {
00222 addLeftNodeToLink (lid, link);
00223 addRightNodeToLink(rid, link);
00224 return &link;
00225 }
00226 else
00227 {
00228 MSG("Lat",Msg::kWarning)
00229 << " connect attempts to violate topology constraint." << endl;
00230 return 0;
00231 }
00232 }
00233
00234
00235 LatticeBase::Link*
00236 LatticeBase::
00237 connect(LeftID lid, Link* pLink, RightID rid)
00238 {
00239 return (0 == pLink) ? connect(lid, rid) : connect(lid, *pLink, rid);
00240 }
00241
00242
00243 LatticeBase::Link*
00244 LatticeBase::connect(LeftID lid, Link& link)
00245 {
00246 VectorLeftID& ld = link.m_VLeftID;
00247 LeftNode* pLeft = leftNode(lid);
00248
00249
00250 if ( find(ld.begin(),ld.end(),lid) != ld.end()
00251 || (checkLNtopo(pLeft) && checkLLtopo(link)) )
00252 {
00253 addLeftNodeToLink(lid, link);
00254 return &link;
00255 }
00256 else
00257 {
00258 MSG("Lat",Msg::kWarning)
00259 << " connect attempts to violate topology constraint." << endl;
00260 return 0;
00261 }
00262 }
00263
00264
00265 LatticeBase::Link*
00266 LatticeBase::connect(Link& link, RightID rid)
00267 {
00268 VectorRightID& rd = link.m_VRightID;
00269 RightNode* pRight = rightNode(rid);
00270
00271
00272
00273 if ( find(rd.begin(),rd.end(),rid) != rd.end()
00274 || (checkRNtopo(pRight) && checkRLtopo(link)) )
00275 {
00276 addRightNodeToLink(rid, link);
00277 return &link;
00278 }
00279 else
00280 {
00281 MSG("Lat",Msg::kWarning)
00282 << " connect attempts to violate topology constraint." << endl;
00283 return 0;
00284 }
00285 }
00286
00287
00288
00289
00290 void LatticeBase::removeLink(Link& link)
00291 {
00292 delete &link;
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 const LatticeBase::VectorLeftID&
00304 LatticeBase ::vLeftID() const
00305 {
00306 return m_VLeftID;
00307 }
00308
00309
00310 const LatticeBase::VectorRightID&
00311 LatticeBase ::vRightID() const
00312 {
00313 return m_VRightID;
00314 }
00315
00316
00317 const LatticeBase::Links&
00318 LatticeBase ::links() const
00319 {
00320 return m_Links;
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 const LatticeBase::Links*
00336 LatticeBase::
00337 linksGivenLeft(LeftID leftID) const
00338 {
00339 const LeftNode* pLN = leftNode(leftID);
00340 return (0==pLN) ? 0 : &(pLN->links());
00341 }
00342
00343 const LatticeBase::Links*
00344 LatticeBase::
00345 linksGivenLeft(LeftItr leftItr) const
00346 {
00347 return linksGivenLeft(*leftItr);
00348 }
00349
00350
00351 const LatticeBase::Links*
00352 LatticeBase::
00353 linksGivenRight(RightID rID) const
00354 {
00355 const RightNode* pRN = rightNode(rID);
00356 return (0==pRN) ? 0 : &(pRN->links());
00357 }
00358
00359 const LatticeBase::Links*
00360 LatticeBase::
00361 linksGivenRight(RightItr rightItr) const
00362 {
00363 return linksGivenRight(*rightItr);
00364 }
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 const LatticeBase::Link*
00375 LatticeBase ::
00376 linkGivenLeft(LeftID leftID) const
00377 {
00378 const LeftNode* pLN = leftNode(leftID);
00379 return ( (0==pLN) || (1 != pLN->links().size()) )?
00380 0 : pLN->links().front();
00381 }
00382
00383 LatticeBase::Link*
00384 LatticeBase::
00385 linkGivenLeft(LeftID leftID)
00386 {
00387 const LeftNode* pLN = leftNode(leftID);
00388 return ( (0==pLN) || (1 != pLN->links().size()) )?
00389 0 : pLN->links().front();
00390 }
00391
00392 const LatticeBase::Link*
00393 LatticeBase ::
00394 linkGivenLeft(LeftItr leftItr) const
00395 {
00396 return linkGivenLeft(*leftItr);
00397 }
00398
00399 LatticeBase::Link*
00400 LatticeBase::
00401 linkGivenLeft(LeftItr leftItr)
00402 {
00403 return linkGivenLeft(*leftItr);
00404 }
00405
00406
00407 const LatticeBase::Link*
00408 LatticeBase ::
00409 linkGivenRight(RightID rightID) const
00410 {
00411 const RightNode* pRN = rightNode(rightID);
00412 return ( (0==pRN) || (1 != pRN->links().size()) ) ? 0 : pRN->links().front();
00413 }
00414
00415 LatticeBase::Link*
00416 LatticeBase::
00417 linkGivenRight(RightID rightID)
00418 {
00419 const RightNode* pRN = rightNode(rightID);
00420 return ( (0==pRN) || (1 != pRN->links().size()) ) ? 0 : pRN->links().front();
00421 }
00422
00423 const LatticeBase::Link*
00424 LatticeBase ::
00425 linkGivenRight(RightItr rightItr) const
00426 {
00427 return linkGivenRight(*rightItr);
00428 }
00429
00430 LatticeBase::Link*
00431 LatticeBase::
00432 linkGivenRight(RightItr rightItr)
00433 {
00434 return linkGivenRight(*rightItr);
00435 }
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 const LatticeBase::VectorLeftID*
00449 LatticeBase ::
00450 vLeftGivenLeft(LeftID leftID) const
00451 {
00452 const LeftNode* pLN = leftNode(leftID);
00453 return (0==pLN) ? 0 : &(pLN->m_VLeftID);
00454 }
00455
00456 const LatticeBase::VectorLeftID*
00457 LatticeBase ::
00458 vLeftGivenLeft(LeftItr i) const
00459 {
00460 return vLeftGivenLeft(*i);;
00461 }
00462
00463
00464 const LatticeBase::VectorRightID*
00465 LatticeBase ::
00466 vRightGivenRight(RightID rightID) const
00467 {
00468 const RightNode* pRN = rightNode(rightID);
00469 return (0==pRN) ? 0 : &(pRN->m_VRightID);
00470 }
00471
00472 const LatticeBase::VectorRightID*
00473 LatticeBase ::
00474 vRightGivenRight(RightItr i) const
00475 {
00476 return vRightGivenRight(*i);
00477 }
00478
00479
00480 const LatticeBase::VectorRightID*
00481 LatticeBase ::
00482 vRightGivenLeft(LeftID leftID) const
00483 {
00484 const LeftNode* pLN = leftNode(leftID);
00485 return (0==pLN) ? 0 : &(pLN->m_VRightID);
00486 }
00487
00488 const LatticeBase::VectorRightID*
00489 LatticeBase ::
00490 vRightGivenLeft(LeftItr i) const
00491 {
00492 return vRightGivenLeft(*i);
00493 }
00494
00495
00496 const LatticeBase::VectorLeftID*
00497 LatticeBase ::
00498 vLeftGivenRight(RightID rightID) const
00499 {
00500 const RightNode* pRN = rightNode(rightID);
00501 return (0==pRN) ? 0 : &(pRN->m_VLeftID);
00502 }
00503
00504 const LatticeBase::VectorLeftID*
00505 LatticeBase ::
00506 vLeftGivenRight(RightItr i) const
00507 {
00508 return vLeftGivenRight(*i);
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 void
00520 LatticeBase::
00521 connectLinks(LeftID leftID, RightID rightID , Links& links) const
00522 {
00523
00524 const VectorRightID* rd = vRightGivenLeft(leftID);
00525 if(0 != rd)
00526 {
00527
00528 if (find(rd->begin(), rd->end(), rightID) != rd->end())
00529 {
00530
00531
00532 const Links* list = linksGivenLeft(leftID);
00533 for (LinkItr i = list->begin(); i != list->end(); ++i)
00534 { const VectorRightID& rd2 = (*i)->vRightID();
00535 if (find(rd2.begin(), rd2.end(), rightID) != rd2.end())
00536 {
00537 links.push_back(*i);
00538 }
00539 }
00540 }
00541 }
00542 }
00543
00544 void
00545 LatticeBase::
00546 connectLinks(LeftItr li, RightItr ri, Links& links) const
00547 {
00548 connectLinks(*li, *ri, links);
00549 }
00550
00551
00552 void
00553 LatticeBase::
00554 shareLinksLeft(LeftID leftID1, LeftID leftID2, Links& links) const
00555 {
00556
00557 const VectorLeftID* ld1 = vLeftGivenLeft(leftID1);
00558 if(0 != ld1)
00559 {
00560
00561 if (find(ld1->begin(), ld1->end(), leftID2) != ld1->end())
00562 {
00563
00564
00565 const Links* list = linksGivenLeft(leftID2);
00566 for (LinkItr i = list->begin(); i != list->end(); ++i)
00567 { const VectorLeftID& ld2 = (*i)->vLeftID();
00568 if (find(ld2.begin(), ld2.end(), leftID2) != ld2.end())
00569 {
00570 links.push_back(*i);
00571 }
00572 }
00573 }
00574 }
00575 }
00576
00577 void
00578 LatticeBase::
00579 shareLinksLeft(LeftItr li1, LeftItr li2, Links& links) const
00580 {
00581 shareLinksLeft(*li1, *li2, links);
00582 }
00583
00584
00585 void
00586 LatticeBase::
00587 shareLinksRight(RightID rightID1, RightID rightID2, Links& links) const
00588 {
00589
00590
00591 const VectorRightID* rd1 = vRightGivenRight(rightID1);
00592 if(0 != rd1)
00593 {
00594 if (find(rd1->begin(), rd1->end(), rightID2) != rd1->end())
00595 {
00596
00597
00598 const Links* list = linksGivenRight(rightID2);
00599 for (LinkItr i = list->begin(); i != list->end(); ++i)
00600 { const VectorRightID& rd2 = (*i)->vRightID();
00601 if (find(rd2.begin(), rd2.end(), rightID2) != rd2.end())
00602 {
00603 links.push_back(*i);
00604 }
00605 }
00606 }
00607 }
00608 }
00609
00610 void
00611 LatticeBase::
00612 shareLinksRight(RightItr ri1, RightItr ri2, Links& links) const
00613 {
00614 shareLinksRight(*ri1, *ri2, links);
00615 }
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 const LatticeBase::Link*
00629 LatticeBase ::
00630 cLshared(LeftID lid, RightID rid) const
00631 {
00632 const Link* pLink = 0;
00633
00634 const VectorRightID* v1 = vRightGivenLeft(lid);
00635 if(0 == v1)
00636 {
00637 return 0;
00638 }
00639
00640
00641 if (find(v1->begin(), v1->end(), rid) != v1->end())
00642 {
00643
00644
00645
00646 const Links* list = linksGivenLeft(lid);
00647 for (LinkItr i = list->begin(); i != list->end(); ++i)
00648 { const VectorRightID& v2 = (*i)->vRightID();
00649 if (find(v2.begin(), v2.end(), rid) != v2.end())
00650 {
00651 if (0 == pLink)
00652 {
00653 pLink = *i;
00654 }
00655 else
00656 {
00657 return 0;
00658 }
00659 }
00660 }
00661 }
00662 return pLink;
00663 }
00664
00665 const LatticeBase::Link*
00666 LatticeBase ::
00667 connectLink(LeftID lid, RightID rid) const
00668 {
00669 return cLshared(lid,rid);
00670 }
00671
00672 LatticeBase::Link*
00673 LatticeBase::
00674 connectLink(LeftID lid, RightID rid)
00675 {
00676 return const_cast<Link*>(cLshared(lid,rid));
00677 }
00678
00679 const LatticeBase::Link*
00680 LatticeBase ::
00681 connectLink(LeftItr li, RightItr ri) const
00682 {
00683 return connectLink(*li, *ri);
00684 }
00685
00686 LatticeBase::Link*
00687 LatticeBase::
00688 connectLink(LeftItr li, RightItr ri)
00689 {
00690 return connectLink(*li, *ri);
00691 }
00692
00693
00694
00695 const LatticeBase::Link*
00696 LatticeBase ::
00697 sLLshared(LeftID id1, LeftID id2) const
00698 {
00699 const Link* pLink = 0;
00700
00701 const VectorLeftID* v1 = vLeftGivenLeft(id1);
00702 if(0 == v1)
00703 {
00704 return 0;
00705 }
00706
00707
00708 if (find(v1->begin(), v1->end(), id2) != v1->end())
00709 {
00710
00711
00712
00713 const Links* list = linksGivenLeft(id1);
00714 for (LinkItr i = list->begin(); i != list->end(); ++i)
00715 { const VectorLeftID& v2 = (*i)->vLeftID();
00716 if (find(v2.begin(), v2.end(), id2) != v2.end())
00717 {
00718 if (0 == pLink)
00719 {
00720 pLink = *i;
00721 }
00722 else
00723 {
00724 return 0;
00725 }
00726 }
00727 }
00728 }
00729 return pLink;
00730 }
00731
00732 const LatticeBase::Link*
00733 LatticeBase ::
00734 shareLinkLeft(LeftID id1, LeftID id2) const
00735 {
00736 return sLLshared(id1,id2);
00737 }
00738
00739 LatticeBase::Link*
00740 LatticeBase::
00741 shareLinkLeft(LeftID id1, LeftID id2)
00742 {
00743 return const_cast<Link*>(sLLshared(id1,id2));
00744 }
00745
00746 const LatticeBase::Link*
00747 LatticeBase::
00748 shareLinkLeft(LeftItr i1, LeftItr i2) const
00749 {
00750 return shareLinkLeft(*i1, *i2);
00751 }
00752
00753 LatticeBase::Link*
00754 LatticeBase::
00755 shareLinkLeft(LeftItr i1, LeftItr i2)
00756 {
00757 return shareLinkLeft(*i1, *i2);
00758 }
00759
00760
00761
00762 const LatticeBase::Link*
00763 LatticeBase ::
00764 sLRshared(RightID id1, RightID id2) const
00765 {
00766 Link* pLink = 0;
00767
00768 const VectorRightID* v1 = vRightGivenRight(id1);
00769 if(0 == v1)
00770 {
00771 return 0;
00772 }
00773
00774
00775 if (find(v1->begin(), v1->end(), id2) != v1->end())
00776 {
00777
00778
00779
00780 const Links* list = linksGivenRight(id1);
00781 for (LinkItr i = list->begin(); i != list->end(); ++i)
00782 { const VectorRightID& v2 = (*i)->vRightID();
00783 if (find(v2.begin(), v2.end(), id2) != v2.end())
00784 {
00785 if (0 == pLink)
00786 {
00787 pLink = *i;
00788 }
00789 else
00790 {
00791 return 0;
00792 }
00793 }
00794 }
00795 }
00796 return pLink;
00797 }
00798
00799 const LatticeBase::Link*
00800 LatticeBase ::
00801 shareLinkRight(RightID id1, RightID id2) const
00802 {
00803
00804 return sLRshared(id1,id2);
00805 }
00806
00807 LatticeBase::Link*
00808 LatticeBase::
00809 shareLinkRight(RightID id1, RightID id2)
00810 {
00811 return const_cast<Link*>(sLRshared(id1,id2));
00812 }
00813
00814 const LatticeBase::Link*
00815 LatticeBase ::
00816 shareLinkRight(RightItr i1, RightItr i2) const
00817 {
00818 return shareLinkRight(*i1, *i2);
00819 }
00820
00821 LatticeBase::Link*
00822 LatticeBase::
00823 shareLinkRight(RightItr i1, RightItr i2)
00824 {
00825 return shareLinkRight(*i1, *i2);
00826 }
00827
00828
00829
00830
00831
00832 Bool_t
00833 LatticeBase::isEmpty() const
00834 {
00835 return 0 == m_Links.size();
00836 }
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846 Bool_t
00847 LatticeBase::isLNodeMulti() const
00848 {
00849 return m_Topology[LNodeMulti];
00850 }
00851
00852
00853 Bool_t
00854 LatticeBase::isRNodeMulti() const
00855 {
00856 return m_Topology[RNodeMulti];
00857 }
00858
00859
00860 Bool_t
00861 LatticeBase::isLLinkMulti() const
00862 {
00863 return m_Topology[LLinkMulti];
00864 }
00865
00866
00867 Bool_t
00868 LatticeBase::isRLinkMulti() const
00869 {
00870 return m_Topology[RLinkMulti];
00871 }
00872
00873
00874 string
00875 LatticeBase::topologyText() const
00876 {
00877 if ( !( isLNodeMulti() || isRNodeMulti()
00878 || isLLinkMulti() || isRLinkMulti()) )
00879 {
00880 return " default (single connections only)";
00881 }
00882 else
00883 {
00884 string s = "";
00885 if (m_Topology[LNodeMulti]) { s += " LNodeMulti";}
00886 if (m_Topology[RNodeMulti]) { s += " RNodeMulti";}
00887 if (m_Topology[LLinkMulti]) { s += " LLinkMulti";}
00888 if (m_Topology[RLinkMulti]) { s += " RLinkMulti";}
00889 return s;
00890 }
00891 }
00892
00893
00894
00895
00896
00897 void
00898 LatticeBase::show(ostream& os) const
00899 {
00900 typedef LatticeBase Lattice;
00901 os << "Lattice has topology " << "Sorry, not available yet" << endl
00902 << " It contains: " << m_LeftNodes.size() << " left data," << endl
00903 << " " << m_RightNodes.size() << " right data," << endl
00904 << " and " << m_Links.size() << " links." << endl;
00905
00906
00907 Lattice::LNodeItr iL = m_LeftNodes.begin();
00908 Lattice::LNodeItr iLend = m_LeftNodes.end();
00909 for ( ; iL != iLend; ++iL)
00910 {
00911 (*iL)->show(os);
00912 }
00913
00914
00915 Lattice::RNodeItr iR = m_RightNodes.begin();
00916 Lattice::RNodeItr iRend = m_RightNodes.end();
00917 for ( ; iR != iRend; ++iR)
00918 {
00919 (*iR)->show(os);
00920 }
00921
00922
00923 Lattice::LinkItr iLink = links().begin();
00924 Lattice::LinkItr iLinkEnd = links().end();
00925 for ( ; iLink != iLinkEnd; ++iLink)
00926 {
00927 if (0 != *iLink)
00928 {
00929 (*iLink)->show(os);
00930 }
00931 }
00932 }
00933
00934
00935 void
00936 LatticeBase::
00937 showLeft(LeftItr i, ostream& os) const
00938 {
00939 leftNode(*i)->show(os);
00940 }
00941
00942
00943 void
00944 LatticeBase::
00945 showLeft(LeftID id, ostream& os) const
00946 {
00947 leftNode(id)->show(os);
00948 }
00949
00950
00951 void
00952 LatticeBase::
00953 showRight(RightItr i, ostream& os) const
00954 {
00955 rightNode(*i)->show(os);
00956 }
00957
00958
00959 void
00960 LatticeBase::
00961 showRight(RightID id, ostream& os) const
00962 {
00963 rightNode(id)->show(os);
00964 }
00965
00966
00967 void
00968 LatticeBase::
00969 showLink(Link* pLink, ostream& os) const
00970 {
00971 pLink->show(os);
00972 }
00973
00974
00975 void
00976 LatticeBase::
00977 showLink(LinkItr i, ostream& os) const
00978 {
00979 (*i)->show(os);
00980 }
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991 LatticeBase::LeftNode*
00992 LatticeBase::newLeftNode(LeftID id)
00993 {
00994 LeftNode* pLN(0);
00995 if (find(m_VLeftID.begin(),m_VLeftID.end(),id) == m_VLeftID.end())
00996 {
00997 m_LeftNodes.push_back(pLN = new LeftNode(id));
00998 m_VLeftID .push_back(id);
00999 }
01000 else
01001 {
01002 MSG("Lat",Msg::kWarning) << "Duplicate left identifier: " << id << endl;
01003 }
01004 return pLN;
01005 }
01006
01007
01008 LatticeBase::RightNode*
01009 LatticeBase::newRightNode(RightID id)
01010 {
01011 RightNode* pRN(0);
01012 if (find(m_VRightID.begin(),m_VRightID.end(),id) == m_VRightID.end())
01013 {
01014 m_RightNodes.push_back(pRN = new RightNode(id));
01015 m_VRightID .push_back(id);
01016 }
01017 else
01018 {
01019 MSG("Lat",Msg::kWarning) << "Duplicate right identifier: " << id << endl;
01020 }
01021 return pRN;
01022 }
01023
01024
01025
01026
01027
01028
01029
01030 LatticeBase::LeftNode*
01031 LatticeBase::leftNode(LeftID leftID) const
01032 {
01033 LeftItr found = find(m_VLeftID.begin(),m_VLeftID.end(),leftID);
01034 if (found != m_VLeftID.end())
01035 {
01036 unsigned int index = found - m_VLeftID.begin();
01037 return m_LeftNodes[index];
01038 }
01039 else
01040 {
01041 return 0;
01042 }
01043 }
01044
01045
01046 LatticeBase::RightNode*
01047 LatticeBase::rightNode(RightID rightID) const
01048 {
01049 RightItr found = find(m_VRightID.begin(),m_VRightID.end(),rightID);
01050 if (found != m_VRightID.end())
01051 {
01052 unsigned int index = found - m_VRightID.begin();
01053 return m_RightNodes[index];
01054 }
01055 else
01056 {
01057 return 0;
01058 }
01059 }
01060
01061
01062
01063
01064
01065 Bool_t
01066 LatticeBase::checkLNtopo(LeftNode* pLN)
01067 {
01068 return m_Topology[LNodeMulti] || (0 == pLN->m_Links.size());
01069 }
01070
01071
01072 Bool_t
01073 LatticeBase::
01074 checkRNtopo(RightNode* pRN)
01075 {
01076 return m_Topology[RNodeMulti] || (0 == pRN->m_Links.size());
01077 }
01078
01079
01080 Bool_t
01081 LatticeBase::checkLLtopo(Link& link)
01082 {
01083 return m_Topology[LLinkMulti] || (0 == link.m_VLeftID.size());
01084 }
01085
01086
01087 Bool_t
01088 LatticeBase::checkRLtopo(Link& link)
01089 {
01090 return m_Topology[RLinkMulti] || (0 == link.m_VRightID.size());
01091 }
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104 void
01105 LatticeBase::
01106 addLeftNodeToLink(LeftID id, Link& link)
01107 {
01108
01109 VectorLeftID& ld = link.m_VLeftID;
01110 if (find(ld.begin(),ld.end(),id) != ld.end())
01111 {
01112 return;
01113 }
01114
01115 LeftNode* pThis = leftNode(id);
01116 Links& links = pThis->m_Links;
01117
01118
01119
01120 for (LeftItr iL = ld.begin(); iL != ld.end(); ++iL)
01121 {
01122 VectorLeftID& nv = pThis->m_VLeftID;
01123 if (find(nv.begin(),nv.end(),*iL) == nv.end())
01124 {
01125 leftNode(*iL)->m_VLeftID.push_back(id);
01126 pThis ->m_VLeftID.push_back(*iL);
01127 }
01128 }
01129
01130
01131
01132 ld .push_back(id);
01133 links.push_back(&link);
01134
01135
01136
01137 VectorRightID& rd = link.m_VRightID;
01138 for (RightItr iR = rd.begin(); iR != rd.end(); ++iR)
01139 {
01140 VectorRightID&fv = pThis->m_VRightID;
01141 if (find(fv.begin(),fv.end(),*iR) == fv.end())
01142 {
01143 rightNode(*iR)->m_VLeftID. push_back(id);
01144 pThis ->m_VRightID.push_back(*iR);
01145 }
01146 }
01147 }
01148
01149
01150 void
01151 LatticeBase::
01152 addRightNodeToLink(RightID id, Link& link)
01153 {
01154
01155 VectorRightID& rd = link.m_VRightID;
01156 if (find(rd.begin(),rd.end(),id) != rd.end())
01157 {
01158 return;
01159 }
01160
01161 RightNode* pThis = rightNode(id);
01162 Links& links = pThis->m_Links;
01163
01164
01165
01166 for (RightItr iR = rd.begin(); iR != rd.end(); ++iR)
01167 {
01168 VectorRightID nv = pThis->m_VRightID;
01169 if (find(nv.begin(),nv.end(),*iR) == nv.end())
01170 {
01171 rightNode(*iR)->m_VRightID.push_back(id);
01172 pThis ->m_VRightID.push_back(*iR);
01173 }
01174 }
01175
01176
01177
01178 rd .push_back(id);
01179 links.push_back(&link);
01180
01181
01182
01183 VectorLeftID& ld = link.m_VLeftID;
01184 for (LeftItr iL = ld.begin(); iL != ld.end(); ++iL)
01185 {
01186 VectorLeftID& fv = pThis->m_VLeftID;
01187 if (find(fv.begin(),fv.end(),*iL) == fv.end())
01188 {
01189 leftNode(*iL)->m_VRightID.push_back(id);
01190 pThis ->m_VLeftID .push_back(*iL);
01191 }
01192 }
01193 }