G4TrackList.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id: G4TrackList.hh 64057 2012-10-30 15:04:49Z gcosmo $
00027 //
00028 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
00029 //
00030 // WARNING : This class is released as a prototype.
00031 // It might strongly evolve or even disapear in the next releases.
00032 //
00033 // History:
00034 // -----------
00035 // 10 Oct 2011 M.Karamitros created
00036 //
00037 // -------------------------------------------------------------------
00038 
00039 #ifndef G4TRACKLIST_H
00040 #define G4TRACKLIST_H
00041 
00042 #include "globals.hh"
00043 #include "G4ReferenceCountedHandle.hh"
00044 
00045 class G4Track;
00046 class G4TrackList;
00047 class G4TrackList_Boundary;
00048 
00055 struct _ListRef
00056 {
00057     friend class G4TrackList ;
00058 protected :
00059     inline _ListRef(G4TrackList* __list) :fpTrackList(__list)
00060     {;}
00061 
00062     G4TrackList* fpTrackList;
00063 };
00064 
00072 class G4TrackListNode
00073 {
00074     friend class G4TrackList;
00075 
00076 public :
00077     G4Track* GetTrack() { return fpTrack; }
00078     G4TrackListNode* GetNext() { return fpNext;}
00079     G4TrackListNode* GetPrevious() { return fpPrevious;}
00080     bool IsAttached() { return fAttachedToList;}
00081 
00082 protected:
00084     G4TrackListNode(G4Track* track= 0);
00086     ~G4TrackListNode();
00087     void SetNext(G4TrackListNode* node) { fpNext = node;}
00088     void SetPrevious(G4TrackListNode* node) { fpPrevious = node;}
00089     void SetAttachedToList(bool flag) { fAttachedToList = flag;}
00090 
00091     bool fAttachedToList;
00092     G4ReferenceCountedHandle<_ListRef> fListRef;
00093     G4Track*         fpTrack;
00094     G4TrackListNode* fpPrevious;
00095     G4TrackListNode* fpNext;
00096 };
00097 
00098 struct G4TrackList_iterator ;
00099 
00106 class G4TrackList
00107 {
00108 private :
00109     G4int                               fNbTracks;
00110     G4TrackListNode *                   fpStart;
00111     G4TrackListNode *                   fpFinish;
00112     G4ReferenceCountedHandle<_ListRef>  fListRef;
00113 
00114     G4TrackListNode fBoundary;
00115     // Must be empty and link to the last non-empty node of the list
00116     // and to the first non-empty node of the list (begin())
00117     // The iterator returned by end() is linked to this empty node
00118 
00119 public:
00120     typedef G4TrackList_iterator iterator;
00121 
00122     G4TrackList();
00123     ~G4TrackList();
00124 
00125     inline G4Track* back()
00126     {
00127         if(fNbTracks != 0)
00128             return fpFinish->GetTrack();
00129         else return 0 ;
00130     }
00131     inline G4int size() const
00132     {
00133         return fNbTracks;
00134     }
00135     inline bool empty() const;
00136     iterator insert(iterator /*position*/, G4Track*);
00137     inline iterator begin();
00138     inline iterator end();
00144     bool Holds(const G4Track*) const;
00145 
00146     inline void push_front(G4Track* __track);
00147     inline void push_back(G4Track* __track);
00148     G4Track* pop_back();
00149 
00150     void remove(G4Track*);
00151 
00152     iterator pop(G4Track*);
00153     iterator pop(iterator __first, iterator __last);
00154     iterator erase(G4Track*);
00161     iterator erase(iterator __first, iterator __last);
00165     void transferTo(G4TrackList*);
00170 protected:
00171     G4TrackListNode* CreateNode(G4Track*);
00172     G4TrackListNode* Flag(G4Track*);
00173     G4TrackListNode* Unflag(G4Track*);
00174     void CheckFlag(G4TrackListNode*);
00175     void DeleteTrack(G4Track*);
00176 
00177     void Hook(G4TrackListNode* /*position*/, G4TrackListNode* /*toHook*/);
00178     void Unhook(G4TrackListNode*);
00179     G4TrackListNode* EraseTrackListNode(G4Track*);
00180 
00181 private:
00182     G4TrackList(const G4TrackList& other);
00183     G4TrackList & operator=
00184     (const G4TrackList &right);
00185     G4int operator==(const G4TrackList &right) const;
00186     G4int operator!=(const G4TrackList &right) const;
00187 };
00188 
00194 struct G4TrackList_iterator
00195 {
00196     friend class G4TrackList;
00197     typedef G4TrackList_iterator                    _Self;
00198     typedef G4TrackListNode                          _Node;
00199 
00200     G4TrackList_iterator()
00201         : fpNode() { }
00202 
00203     explicit
00204     G4TrackList_iterator(_Node* __x)
00205         : fpNode(__x) { }
00206 
00207     _Node* GetNode()
00208     { return fpNode; }
00209 
00210     G4Track*
00211     operator*();
00212 
00213     const G4Track*
00214     operator*() const;
00215 
00216     G4Track*
00217     operator->() ;
00218 
00219     const G4Track*
00220     operator->() const;
00221 
00222     _Self&
00223     operator++()
00224     {
00225         fpNode = fpNode->GetNext();
00226         return *this;
00227     }
00228 
00229     _Self
00230     operator++(int)
00231     {
00232         _Self __tmp = *this;
00233         fpNode = fpNode->GetNext();
00234         return __tmp;
00235     }
00236 
00237     _Self&
00238     operator--()
00239     {
00240         fpNode = fpNode->GetPrevious();
00241         return *this;
00242     }
00243 
00244     _Self
00245     operator--(int)
00246     {
00247         _Self __tmp = *this;
00248         fpNode = fpNode->GetPrevious();
00249         return __tmp;
00250     }
00251 
00252     bool
00253     operator==(const _Self& __x) const
00254     { return (fpNode == __x.fpNode); }
00255 
00256     bool
00257     operator!=(const _Self& __x) const
00258     {
00259         return (fpNode != __x.fpNode);
00260     }
00261 
00262 private:
00263     // The only member points to the G4TrackList_iterator element.
00264     _Node* fpNode;
00265 };
00266 
00267 inline bool G4TrackList::empty() const
00268 { return (fNbTracks == 0); }
00269 
00270 
00271 inline G4TrackList::iterator G4TrackList::begin()
00272 { return iterator(fpStart); }
00273 
00274 inline G4TrackList::iterator G4TrackList::end()
00275 { return iterator( &(fBoundary) ); }
00276 // return an iterator that contains an empty node
00277 // use for boundary checking only
00278 
00279 inline void G4TrackList::push_front(G4Track* track)
00280 {
00281     insert(begin(), track);
00282 }
00283 
00284 inline void G4TrackList::push_back(G4Track* track)
00285 {
00286     insert(end(), track);
00287 }
00288 
00289 #endif // G4TRACKLIST_H

Generated on Mon May 27 17:50:01 2013 for Geant4 by  doxygen 1.4.7