File indexing completed on 2025-01-18 10:04:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef NCollection_EBTree_HeaderFile
0017 #define NCollection_EBTree_HeaderFile
0018
0019 #include <NCollection_UBTree.hxx>
0020 #include <Standard_Type.hxx>
0021 #include <Standard_Transient.hxx>
0022 #include <NCollection_List.hxx>
0023 #include <TColStd_SequenceOfInteger.hxx>
0024 #include <NCollection_DataMap.hxx>
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 template <class TheObjType, class TheBndType> class NCollection_EBTree
0037 : public NCollection_UBTree <TheObjType, TheBndType>
0038 {
0039 public:
0040 typedef NCollection_UBTree <TheObjType, TheBndType> UBTree;
0041 typedef typename UBTree::TreeNode TreeNode;
0042
0043
0044
0045
0046
0047 NCollection_EBTree (const Handle(NCollection_BaseAllocator)& theAllocator=0L)
0048 : UBTree (theAllocator) {}
0049
0050
0051
0052
0053
0054
0055
0056
0057 Standard_Boolean Add (const TheObjType& theObj, const TheBndType& theBnd) Standard_OVERRIDE
0058 {
0059 Standard_Boolean result = Standard_False;
0060 if (!Contains (theObj))
0061 {
0062
0063 UBTree::Add (theObj, theBnd);
0064
0065
0066 TreeNode& aNewNode = this->ChangeLastNode ();
0067 myObjNodeMap.Bind (theObj, &aNewNode);
0068
0069 if (!aNewNode.IsRoot ())
0070 {
0071 TreeNode& aNeiNode = aNewNode.ChangeParent ().ChangeChild (0);
0072 if (aNeiNode.IsLeaf ())
0073 {
0074 myObjNodeMap.UnBind (aNeiNode.Object ());
0075 myObjNodeMap.Bind (aNeiNode.Object (), &aNeiNode);
0076 }
0077 }
0078 result = Standard_True;
0079 }
0080 return result;
0081 }
0082
0083
0084
0085
0086
0087
0088 Standard_Boolean Remove (const TheObjType& theObj);
0089
0090
0091
0092
0093
0094 Standard_Boolean Contains (const TheObjType& theObj) const
0095 { return myObjNodeMap.IsBound (theObj); }
0096
0097
0098
0099
0100
0101 const TreeNode& FindNode (const TheObjType& theObj) const
0102 { return *myObjNodeMap.Find (theObj); }
0103
0104
0105
0106
0107 void Clear (const Handle(NCollection_BaseAllocator)& aNewAlloc = 0L) Standard_OVERRIDE
0108 {
0109 myObjNodeMap.Clear ();
0110 UBTree::Clear (aNewAlloc);
0111 }
0112
0113 private:
0114
0115
0116
0117 NCollection_EBTree (const NCollection_EBTree&);
0118
0119
0120 NCollection_EBTree& operator = (const NCollection_EBTree&);
0121
0122
0123
0124 NCollection_DataMap <TheObjType, TreeNode*>
0125 myObjNodeMap;
0126 };
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136 template <class TheObjType, class TheBndType>
0137 Standard_Boolean NCollection_EBTree<TheObjType,TheBndType>::Remove
0138 (const TheObjType& theObj)
0139 {
0140 Standard_Boolean result = Standard_False;
0141 if (Contains (theObj)) {
0142 TreeNode* pNode = myObjNodeMap (theObj);
0143 if (pNode->IsRoot()) {
0144
0145 Clear();
0146 }
0147 else {
0148
0149
0150
0151 myObjNodeMap.UnBind (theObj);
0152 TreeNode* pParent = &pNode->ChangeParent();
0153 pParent->Kill ((pNode == &pParent->Child(0) ? 0 : 1),
0154 this->Allocator());
0155 if (pParent->IsLeaf()) {
0156
0157 myObjNodeMap.UnBind (pParent->Object());
0158 myObjNodeMap.Bind (pParent->Object(), pParent);
0159 }
0160 while (!pParent->IsRoot()) {
0161 pParent = &pParent->ChangeParent();
0162 pParent->ChangeBnd() = pParent->Child(0).Bnd();
0163 pParent->ChangeBnd().Add (pParent->Child(1).Bnd());
0164 }
0165 }
0166 result = Standard_True;
0167 }
0168 return result;
0169 }
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 #define DEFINE_HEBTREE(_HEBTREE, _OBJTYPE, _BNDTYPE, _HUBTREE) \
0181 class _HEBTREE : public _HUBTREE \
0182 { \
0183 public: \
0184 typedef NCollection_UBTree <_OBJTYPE, _BNDTYPE> UBTree; \
0185 typedef NCollection_EBTree <_OBJTYPE, _BNDTYPE> EBTree; \
0186 \
0187 _HEBTREE () : _HUBTREE(new EBTree) {} \
0188 \
0189 \
0190 \
0191 \
0192 Standard_Boolean Remove (const _OBJTYPE& theObj) \
0193 { return ChangeETree().Remove (theObj); } \
0194 \
0195 Standard_Boolean Contains (const _OBJTYPE& theObj) const \
0196 { return ETree().Contains (theObj); } \
0197 \
0198 const UBTree::TreeNode& FindNode (const _OBJTYPE& theObj) const \
0199 { return ETree().FindNode (theObj); } \
0200 \
0201 \
0202 \
0203 const EBTree& ETree () const { return (const EBTree&) Tree(); } \
0204 EBTree& ChangeETree () { return (EBTree&) ChangeTree(); } \
0205 \
0206 DEFINE_STANDARD_RTTI_INLINE(_HEBTREE,_HUBTREE) \
0207 \
0208 }; \
0209 DEFINE_STANDARD_HANDLE (_HEBTREE, _HUBTREE)
0210
0211 #define IMPLEMENT_HEBTREE(_HEBTREE, _HUBTREE)
0212
0213
0214
0215 #endif