Geant4_10
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
G4Track * operator->()
Definition: G4TrackList.cc:49
G4TrackListNode _Node
Definition: G4TrackList.hh:198
G4TrackList_iterator iterator
Definition: G4TrackList.hh:120
bool Holds(const G4Track *) const
Definition: G4TrackList.cc:137
G4TrackListNode * Flag(G4Track *)
Definition: G4TrackList.cc:142
bool operator==(const _Self &__x) const
Definition: G4TrackList.hh:253
G4TrackListNode * EraseTrackListNode(G4Track *)
Definition: G4TrackList.cc:325
G4TrackList_iterator _Self
Definition: G4TrackList.hh:197
void push_back(G4Track *__track)
Definition: G4TrackList.hh:284
G4Track * fpTrack
Definition: G4TrackList.hh:93
int G4int
Definition: G4Types.hh:78
void DeleteTrack(G4Track *)
Definition: G4TrackList.cc:335
G4TrackListNode * CreateNode(G4Track *)
Definition: G4TrackList.cc:170
iterator begin()
Definition: G4TrackList.hh:271
G4ReferenceCountedHandle< _ListRef > fListRef
Definition: G4TrackList.hh:92
G4Track * operator*()
Definition: G4TrackList.cc:45
G4TrackListNode * fpPrevious
Definition: G4TrackList.hh:94
iterator pop(G4Track *)
Definition: G4TrackList.cc:317
bool empty() const
Definition: G4TrackList.hh:267
G4int size() const
Definition: G4TrackList.hh:131
iterator end()
Definition: G4TrackList.hh:274
iterator insert(iterator, G4Track *)
Definition: G4TrackList.cc:258
void transferTo(G4TrackList *)
Definition: G4TrackList.cc:389
G4Track * pop_back()
Definition: G4TrackList.cc:308
void SetNext(G4TrackListNode *node)
Definition: G4TrackList.hh:87
void SetPrevious(G4TrackListNode *node)
Definition: G4TrackList.hh:88
G4TrackListNode(G4Track *track=0)
Definition: G4TrackList.cc:64
G4TrackListNode * GetPrevious()
Definition: G4TrackList.hh:79
void CheckFlag(G4TrackListNode *)
Definition: G4TrackList.cc:269
G4Track * back()
Definition: G4TrackList.hh:125
void Unhook(G4TrackListNode *)
Definition: G4TrackList.cc:225
_ListRef(G4TrackList *__list)
Definition: G4TrackList.hh:59
iterator erase(G4Track *)
Definition: G4TrackList.cc:346
G4TrackList_iterator(_Node *__x)
Definition: G4TrackList.hh:204
G4TrackListNode * fpNext
Definition: G4TrackList.hh:95
void Hook(G4TrackListNode *, G4TrackListNode *)
Definition: G4TrackList.cc:176
G4TrackList * fpTrackList
Definition: G4TrackList.hh:62
G4Track * GetTrack()
Definition: G4TrackList.hh:77
void push_front(G4Track *__track)
Definition: G4TrackList.hh:279
G4TrackListNode * GetNext()
Definition: G4TrackList.hh:78
G4TrackListNode * Unflag(G4Track *)
Definition: G4TrackList.cc:288
bool operator!=(const _Self &__x) const
Definition: G4TrackList.hh:257
void SetAttachedToList(bool flag)
Definition: G4TrackList.hh:89