NeoPZ
pzlink.cpp
Go to the documentation of this file.
1 
6 #include "pzlink.h"
7 #include "pzespmat.h"
8 
9 
10 /*** Constructor ***/
11 
12 template< class ElemType >
14 {
15  fHead = fThis = fLast = NULL;
16  fpBefore = &fHead;
17 #ifdef WORKPOOL
18  fWp = 0;
19 #endif
20 }
21 
22 /*** Destructor ***/
23 
24 template< class ElemType >
26 {
27 #ifdef WORKPOOL
28  if(!fWp) {
29 #endif
30  fThis = fHead;
31  while ( fHead != NULL )
32  {
33  fHead = fHead->next;
34  delete( fThis );
35  fThis = fHead;
36  }
37 #ifdef WORKPOOL
38  }
39 #endif
40 }
41 
42 
43 
44 /*** Insert ***/
45 
46 template< class ElemType >
47 int
48 TPZLink<ElemType>::Insert( ElemType &elem )
49 {
50  Node *newNode;
51 #ifdef WORKPOOL
52  if(fWp) newNode = (Node *) fWp->NewPointer(sizeof(Node));
53  else newNode = new (Node);
54 #else
55  newNode = new( Node );
56 #endif
57  if ( newNode == NULL )
58  return( 0 );
59 
60  newNode->elem = elem;
61  if ( (newNode->next = fThis) == NULL )
62  fLast = newNode;
63 
64  *fpBefore = fThis = newNode;
65 
66  return( 1 );
67 }
68 
69 
70 
71 /*** Append ***/
72 
73 template< class ElemType >
74 int
75 TPZLink<ElemType>::Append( ElemType &elem )
76 {
77  // Vai para o final da lista.
78  while ( fThis != NULL )
79  {
80  fpBefore = &fThis->next;
81  fThis = fThis->next;
82  }
83 
84  return( Insert( elem ) );
85 }
86 
87 
88 
89 /*** Remove ***/
90 
91 template< class ElemType >
92 int
94 {
95  if ( fThis == NULL )
96  return( 0 );
97 
98  fThis = fThis->next;
99 #ifdef WORKPOOL
100  if(!fWp) delete( *fpBefore );
101  else fWp->Release(*fpBefore);
102 #else
103  delete( *fpBefore );
104 #endif
105  *fpBefore = fThis;
106 
107  // Se removeu o ultimo elemento, ajusta o ponteiro fLast.
108  //
109  if ( fThis == NULL )
110  {
111  Head();
112  if ( fThis == NULL )
113  fLast = NULL;
114  else
115  {
116  while ( fThis->next != NULL )
117  fThis = fThis->next;
118  fLast = fThis;
119  fThis = NULL;
120  }
121  }
122 
123  return( 1 );
124 }
125 
126 
127 
128 /*** Update ***/
129 
130 template< class ElemType >
131 int TPZLink<ElemType>::Update( ElemType &elem )
132 {
133  if ( fThis == NULL )
134  return( 0 );
135 
136  fThis->elem = elem;
137  return( 1 );
138 }
139 
140 
141 
142 /*** Clear ***/
143 
144 template< class ElemType >
145 int
147 {
148  fThis = fHead;
149  while ( fThis != NULL )
150  {
151  fThis = fThis->next;
152 #ifdef WORKPOOL
153  if(fWp) fWp->Release(fHead);
154  else delete fHead;
155 #else
156  delete( fHead );
157 #endif
158  fHead = fThis;
159  }
160  fpBefore = &fHead;
161  fThis = fLast = NULL;
162  return( 1 );
163 }
164 
165 
166 
167 /*** Operator = ***/
168 
169 template< class ElemType >
172 {
173  // Guarda a posicao atual da lista 'src'.
174  Node **oldBefore = src.fpBefore;
175 
176  Clear();
177 
178  // Copia os elementos da lista.
179  src.Head();
180  ElemType elem;
181  while ( src.Get( &elem ) )
182  {
183  Append( elem );
184  src.Next();
185  }
186 
187  // Volta a lista 'src' aa posicao inicial.
188  src.fpBefore = oldBefore;
189  src.fThis = *oldBefore;
190 
191  Head();
192  return( *this );
193 }
194 
195 
196 
197 /*********************** Tipos usados *************************/
198 
199 template class TPZLink<TPZSpMatrix<REAL>::TPZNode>;
200 
void Append(TPZVec< TVar > &u1, TPZVec< TVar > &u2, TPZVec< TVar > &u12)
Append u2 vector after u1 vector in u12 vector.
Contains TPZSpMatrix class which defines sparse matrix class.