Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TrackList.hh
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: G4TrackList.hh 64057 2012-10-30 15:04:49Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // WARNING : This class is released as a prototype.
31 // It might strongly evolve or even disapear in the next releases.
32 //
33 // History:
34 // -----------
35 // 10 Oct 2011 M.Karamitros created
36 //
37 // -------------------------------------------------------------------
38 
39 #ifndef G4TRACKLIST_H
40 #define G4TRACKLIST_H
41 
42 #include "globals.hh"
44 
45 class G4Track;
46 class G4TrackList;
47 class G4TrackList_Boundary;
48 
55 struct _ListRef
56 {
57  friend class G4TrackList ;
58 protected :
59  inline _ListRef(G4TrackList* __list) :fpTrackList(__list)
60  {;}
61 
63 };
64 
73 {
74  friend class G4TrackList;
75 
76 public :
77  G4Track* GetTrack() { return fpTrack; }
80  bool IsAttached() { return fAttachedToList;}
81 
82 protected:
84  G4TrackListNode(G4Track* track= 0);
87  void SetNext(G4TrackListNode* node) { fpNext = node;}
88  void SetPrevious(G4TrackListNode* node) { fpPrevious = node;}
89  void SetAttachedToList(bool flag) { fAttachedToList = flag;}
90 
96 };
97 
98 struct G4TrackList_iterator ;
99 
107 {
108 private :
109  G4int fNbTracks;
110  G4TrackListNode * fpStart;
111  G4TrackListNode * fpFinish;
113 
114  G4TrackListNode fBoundary;
115  // Must be empty and link to the last non-empty node of the list
116  // and to the first non-empty node of the list (begin())
117  // The iterator returned by end() is linked to this empty node
118 
119 public:
121 
122  G4TrackList();
123  ~G4TrackList();
124 
125  inline G4Track* back()
126  {
127  if(fNbTracks != 0)
128  return fpFinish->GetTrack();
129  else return 0 ;
130  }
131  inline G4int size() const
132  {
133  return fNbTracks;
134  }
135  inline bool empty() const;
136  iterator insert(iterator /*position*/, G4Track*);
137  inline iterator begin();
138  inline iterator end();
144  bool Holds(const G4Track*) const;
145 
146  inline void push_front(G4Track* __track);
147  inline void push_back(G4Track* __track);
148  G4Track* pop_back();
149 
150  void remove(G4Track*);
151 
152  iterator pop(G4Track*);
153  iterator pop(iterator __first, iterator __last);
161  iterator erase(iterator __first, iterator __last);
165  void transferTo(G4TrackList*);
170 protected:
174  void CheckFlag(G4TrackListNode*);
175  void DeleteTrack(G4Track*);
176 
177  void Hook(G4TrackListNode* /*position*/, G4TrackListNode* /*toHook*/);
178  void Unhook(G4TrackListNode*);
180 
181 private:
182  G4TrackList(const G4TrackList& other);
183  G4TrackList & operator=
184  (const G4TrackList &right);
185  G4int operator==(const G4TrackList &right) const;
186  G4int operator!=(const G4TrackList &right) const;
187 };
188 
195 {
196  friend class G4TrackList;
199 
201  : fpNode() { }
202 
203  explicit
205  : fpNode(__x) { }
206 
208  { return fpNode; }
209 
210  G4Track*
211  operator*();
212 
213  const G4Track*
214  operator*() const;
215 
216  G4Track*
217  operator->() ;
218 
219  const G4Track*
220  operator->() const;
221 
222  _Self&
224  {
225  fpNode = fpNode->GetNext();
226  return *this;
227  }
228 
229  _Self
231  {
232  _Self __tmp = *this;
233  fpNode = fpNode->GetNext();
234  return __tmp;
235  }
236 
237  _Self&
239  {
240  fpNode = fpNode->GetPrevious();
241  return *this;
242  }
243 
244  _Self
246  {
247  _Self __tmp = *this;
248  fpNode = fpNode->GetPrevious();
249  return __tmp;
250  }
251 
252  bool
253  operator==(const _Self& __x) const
254  { return (fpNode == __x.fpNode); }
255 
256  bool
257  operator!=(const _Self& __x) const
258  {
259  return (fpNode != __x.fpNode);
260  }
261 
262 private:
263  // The only member points to the G4TrackList_iterator element.
264  _Node* fpNode;
265 };
266 
267 inline bool G4TrackList::empty() const
268 { return (fNbTracks == 0); }
269 
270 
272 { return iterator(fpStart); }
273 
275 { return iterator( &(fBoundary) ); }
276 // return an iterator that contains an empty node
277 // use for boundary checking only
278 
279 inline void G4TrackList::push_front(G4Track* track)
280 {
281  insert(begin(), track);
282 }
283 
284 inline void G4TrackList::push_back(G4Track* track)
285 {
286  insert(end(), track);
287 }
288 
289 #endif // G4TRACKLIST_H