0024157: Parallelization of assembly part of BO
[occt.git] / src / PCollection / PCollection_HSingleList.gxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 // ----------------------------------------------------------------------
20 // HSingleList implementation:
21 // Last Revision : Feb,10 1992 J.P Tirault
22 //                 Implementation of ShallowCopy, ShallowDump
23 //                 methods.
24 // -------------------------------------------------------------------------
25
26 #include <Standard_NoSuchObject.hxx>
27 #include <Standard_NotImplemented.hxx>
28 #include <Standard_ProgramError.hxx>
29 #include <Standard_OStream.hxx>
30
31 // -------------------------------------------------------------------------
32 //                                                                         -
33 // Constructor Returns an empty list                                       -
34 // ----------                                                              -
35 //                                                                         -
36 // -------------------------------------------------------------------------
37 PCollection_HSingleList::PCollection_HSingleList ()
38 {
39  Next.Nullify();
40 }
41
42
43 // -------------------------------------------------------------------------
44 //                                                                         -
45 // Construct : Add an item at the beginning of the list                    -
46 // ---------                                                               -
47 //                                                                         -
48 // -------------------------------------------------------------------------
49 Handle(PCollection_HSingleList) 
50   PCollection_HSingleList::Construct(const Item& T)const
51 {
52
53
54  Handle(PCollection_HSingleList) me , L ;
55  me = this;
56 #ifndef OBJS
57  L = new PCollection_HSingleList;
58 #else
59  L = new (os_segment::of(this)) PCollection_HSingleList;
60 #endif
61  L->ChangeForwardPointer ( me );
62  L->SetValue ( T );                     
63  return L;
64 }
65
66
67 // -------------------------------------------------------------------------
68 //                                                                         -
69 // Shallowcopy : Redefinition of the shallowcopy dump                      -
70 // -----------                                                             -
71
72 //                                                                         -
73 // -------------------------------------------------------------------------
74 Handle(Standard_Persistent) PCollection_HSingleList::ShallowCopy() const
75 {
76   Handle(PCollection_HSingleList) TheList,          // Traversal depth of <this>
77                                 TheCopy,          // The list returned
78                                 Pred,             // Backward pointer
79                                 Succ;             // Forward pointer
80 #ifndef OBJS
81   TheCopy = new PCollection_HSingleList;            // Initialization of the list
82 #else
83   TheCopy = new (os_segment::of(this)) PCollection_HSingleList;            // Initialization of the list
84 #endif
85                                                   // that will be returned
86   Standard_Boolean FirstTime = Standard_True;                 
87
88   TheList = this;                                 // Start at the beginning
89   Pred = Succ = TheCopy;
90   
91   while ( ! TheList->IsEmpty() ) {                // Append each item at the
92     Succ = Succ->Construct(TheList->Value());     // end of the list
93     if ( FirstTime ){
94       FirstTime = Standard_False;
95       TheCopy   = Succ;
96     }
97     else{
98       Pred->ChangeForwardPointer(Succ);           // Make the link between 
99     }                                             // Pred and Succ
100     Pred = Succ;
101     Succ = Succ->Tail();
102     TheList = TheList->Tail();                   
103   }
104   return TheCopy;                                 // Returns the header
105 }
106
107 // -------------------------------------------------------------------------
108 //                                                                         -
109 // ShallowDump Redefinition of the shallowdump method                      -
110 // -----------                                                             -
111 //                                                                         -
112 // -------------------------------------------------------------------------
113 void PCollection_HSingleList::ShallowDump(Standard_OStream& S) const
114 {
115   Handle(PCollection_HSingleList) TheList;
116   TheList = this;
117   S << "begin class HSingleList " << endl;
118   while ( ! TheList->IsEmpty() ) {                
119     ::ShallowDump(TheList->Value(), S);
120     TheList = TheList->Tail();
121   }
122   S << "end class HSingleList" << endl;
123   
124 }
125
126
127
128 /* Anciens INLINE */
129
130 Item PCollection_HSingleList::Value() const {
131   Standard_NoSuchObject_Raise_if(IsEmpty(),
132                                  "Empty Element in HSingleList::Value");
133      return Data;
134 }
135
136 Handle(PCollection_HSingleList) PCollection_HSingleList::Tail() const {
137   Standard_NoSuchObject_Raise_if (IsEmpty(),
138                                   "Empty Element in HSingleList::Value");
139   return Next;
140 }
141
142
143 Standard_Boolean PCollection_HSingleList::IsEmpty()const
144 {
145   return Next.IsNull();
146 }
147
148
149 void PCollection_HSingleList::SetValue(const Item& T)
150 {
151   Standard_NoSuchObject_Raise_if (IsEmpty(),
152                                   "Empty Element in HSingleList::SetValue");
153   Data = T;
154 }
155
156
157 // -------------------------------------------------------------------------
158 //                                                                         -
159 // SwapTail : Exchange the tail of the current list with an another list   -
160 // --------                                                                -
161 //                                                                         -
162 // -------------------------------------------------------------------------
163 void PCollection_HSingleList::SwapTail(Handle(PCollection_HSingleList)&
164                                             WithList)
165 {
166   Standard_NoSuchObject_Raise_if (IsEmpty(),
167                                   "Empty Element in HSingleList::SwapTail");
168   Handle(PCollection_HSingleList) L = Next;
169   Next     = WithList;
170   WithList = L;
171 }
172
173
174 void PCollection_HSingleList::ChangeForwardPointer
175    (const Handle(PCollection_HSingleList)& L)
176 {
177      Next = L;
178 }
179
180