Geant4_10
G4ITBox.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4ITBox.cc 64057 2012-10-30 15:04:49Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include "G4ITBox.hh"
37 
38 G4ITBox::G4ITBox() : fNbIT(0), fpFirstIT(0), fpLastIT(0), fpPreviousBox(0), fpNextBox(0)
39 {;}
40 
42 {
43  if( fNbIT != 0 )
44  {
45  G4IT * aIT = fpFirstIT;
46  G4IT * nextIT;
47 
48  while( aIT != 0 )
49  {
50  nextIT = aIT->GetNext();
51  delete aIT;
52  aIT = nextIT;
53  }
54  }
55 
56  if(fpPreviousBox) fpPreviousBox->SetNextBox(fpNextBox) ;
57  if(fpNextBox) fpNextBox->SetPreviousBox(fpPreviousBox);
58 }
59 
60 const G4ITBox & G4ITBox::operator=(const G4ITBox &right)
61 {
62  fNbIT = right.fNbIT;
63  fpFirstIT = right.fpFirstIT;
64  fpLastIT = right.fpLastIT;
65  fpPreviousBox = 0;
66  fpNextBox = 0;
67  return *this;
68 }
69 
70 void G4ITBox::Push( G4IT * aIT )
71 {
72  if( fNbIT == 0 )
73  {
74  aIT->SetPrevious( 0 );
75  fpFirstIT = aIT;
76  }
77  else
78  {
79  fpLastIT->SetNext( aIT );
80  aIT->SetPrevious( fpLastIT );
81  }
82  fpLastIT = aIT;
83  fNbIT++;
84  aIT->SetITBox(this);
85 }
86 
87 void G4ITBox::Extract( G4IT * aStackedIT )
88 {
89  if( aStackedIT == fpFirstIT )
90  {
91  fpFirstIT = aStackedIT->GetNext();
92  }
93  else if( aStackedIT == fpLastIT )
94  {
95  fpLastIT = aStackedIT->GetPrevious();
96 
97  }
98 
99  if( aStackedIT->GetNext())
100  aStackedIT->GetNext()->SetPrevious(aStackedIT->GetPrevious());
101  if( aStackedIT->GetPrevious())
102  aStackedIT->GetPrevious()->SetNext(aStackedIT->GetNext());
103 
104  aStackedIT->SetNext(0);
105  aStackedIT->SetPrevious(0);
106  aStackedIT->SetITBox(0);
107  fNbIT--;
108 }
109 
111 {
112  if( fNbIT == 0 ) return 0;
113 
114  G4IT * temp = fpLastIT;
115  G4bool find = false;
116 
117  while(find == false && temp != 0)
118  {
119  if(temp-> GetTrack() == &track)
120  {
121  find = true;
122  break;
123  }
124  temp = temp->GetPrevious();
125  }
126 
127  return temp;
128 }
129 
130 const G4IT* G4ITBox::FindIT(const G4Track& track) const
131 {
132  if( fNbIT == 0 ) return 0;
133 
134  const G4IT * temp = fpLastIT;
135  G4bool find = false;
136 
137  while(find == false && temp != 0)
138  {
139  if(temp-> GetTrack() == &track)
140  {
141  find = true;
142  break;
143  }
144  temp = temp->GetPrevious();
145  }
146 
147  return temp;
148 }
149 
151 {
152  G4IT * ITToTransfer = fpFirstIT;
153  while(fNbIT)
154  {
155  Extract(ITToTransfer);
156  aStack->Push(ITToTransfer);
157  ITToTransfer = ITToTransfer->GetNext();
158  }
159 }
Definition: G4IT.hh:82
void SetNext(G4IT *)
Definition: G4IT.hh:188
void Push(G4IT *)
Definition: G4ITBox.cc:70
G4ITBox()
Definition: G4ITBox.cc:38
void SetITBox(G4ITBox *)
Definition: G4IT.hh:178
G4IT * GetPrevious()
Definition: G4IT.hh:193
G4IT * GetNext()
Definition: G4IT.hh:198
void SetPreviousBox(G4ITBox *box)
Definition: G4ITBox.hh:132
bool G4bool
Definition: G4Types.hh:79
void SetPrevious(G4IT *)
Definition: G4IT.hh:183
void SetNextBox(G4ITBox *box)
Definition: G4ITBox.hh:122
G4IT * FindIT(const G4Track &)
Definition: G4ITBox.cc:110
~G4ITBox()
Definition: G4ITBox.cc:41
void TransferTo(G4ITBox *)
Definition: G4ITBox.cc:150
void Extract(G4IT *)
Definition: G4ITBox.cc:87