Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:41

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // Author: Mathieu Karamitros
0027 
0028 // The code is developed in the framework of the ESA AO7146
0029 //
0030 // We would be very happy hearing from you, send us your feedback! :)
0031 //
0032 // In order for Geant4-DNA to be maintained and still open-source,
0033 // article citations are crucial. 
0034 // If you use Geant4-DNA chemistry and you publish papers about your software, 
0035 // in addition to the general paper on Geant4-DNA:
0036 //
0037 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
0038 //
0039 // we would be very happy if you could please also cite the following
0040 // reference papers on chemistry:
0041 //
0042 // J. Comput. Phys. 274 (2014) 841-882
0043 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508 
0044 
0045 #ifndef G4MOLECULEITERATOR_HH_
0046 #define G4MOLECULEITERATOR_HH_
0047 
0048 #include <map>
0049 #include "globals.hh"
0050 
0051 template<typename MOLECULE>
0052 class G4MoleculeIterator
0053 {
0054 protected:
0055   using MAP = std::map<G4String, MOLECULE *>;
0056   MAP* fMap;
0057   G4bool fDefined;
0058   typename MAP::iterator fIt;
0059 
0060 public:
0061   G4MoleculeIterator(MAP& _map) :
0062       fMap(&_map)
0063   {
0064     fDefined = false;
0065   }
0066 
0067   virtual ~G4MoleculeIterator()
0068   = default;
0069 
0070   G4MoleculeIterator(const G4MoleculeIterator& right)
0071   {
0072     fMap = right.fMap;
0073     fDefined = right.fDefined;
0074     fIt = right.fIt;
0075   }
0076 
0077   G4MoleculeIterator& operator=(const G4MoleculeIterator& right)
0078   {
0079     if (this == &right) return *this;
0080     fMap = right.fMap;
0081     fDefined = right.fDefined;
0082     fIt = right.fIt;
0083     return *this;
0084   }
0085 
0086   G4bool operator++(int)
0087   {
0088     if (!fDefined) return false;
0089     fIt++;
0090     return static_cast<G4bool>(fIt != fMap->end());
0091   }
0092 
0093   G4bool operator++()
0094   {
0095     if (!fDefined) return false;
0096     fIt++;
0097     return static_cast<G4bool>(fIt != fMap->end());
0098   }
0099 
0100   void reset()
0101   {
0102     fDefined = false;
0103   }
0104 
0105   G4bool operator()()
0106   {
0107     if (!fDefined)
0108     {
0109       fDefined = true;
0110       fIt = fMap->begin();
0111       return true;
0112     }
0113     
0114     fIt++;
0115    
0116     return static_cast<G4bool>(fIt != fMap->end());
0117   }
0118 
0119   const G4String& Name()
0120   {
0121     return fIt->first;
0122   }
0123 
0124   MOLECULE* value()
0125   {
0126     return fIt->second;
0127   }
0128 };
0129 
0130 #endif /* G4MOLECULEITERATOR_HH_ */