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: G4MoleculeHandleManager.cc 64057 2012-10-30 15:04:49Z gcosmo $ 00027 // 00028 #include "G4MoleculeHandleManager.hh" 00029 #include "G4Molecule.hh" 00030 00031 using namespace std; 00032 00033 G4MoleculeHandleManager* G4MoleculeHandleManager::fInstance (0); 00034 00035 G4MoleculeHandleManager::G4MoleculeHandleManager() 00036 { 00037 // G4cout << "G4MoleculeHandleManager::G4MoleculeHandleManager()" << G4endl; 00038 } 00039 00040 G4bool G4MoleculeHandleManager::CompMoleculePointer::operator()(const G4Molecule* mol1, const G4Molecule* mol2) const 00041 { 00042 return (*mol1) < (*mol2); 00043 } 00044 00045 G4MoleculeHandleManager::~G4MoleculeHandleManager() 00046 { 00047 if(fMoleculeHandle.empty() == false) 00048 { 00049 MoleculeHandleMap::iterator it = fMoleculeHandle.begin(); 00050 for( ; it != fMoleculeHandle.end() ; it++) 00051 { 00052 it->second.reset(); 00053 } 00054 } 00055 } 00056 00057 void G4MoleculeHandleManager::DeleteInstance() 00058 { 00059 if(fInstance) 00060 { 00061 delete fInstance; 00062 fInstance = 0; 00063 } 00064 } 00065 00066 G4MoleculeHandleManager* G4MoleculeHandleManager::Instance() 00067 { 00068 if(!fInstance) 00069 { 00070 fInstance = new G4MoleculeHandleManager; 00071 } 00072 return fInstance; 00073 } 00074 00075 G4MoleculeHandle G4MoleculeHandleManager::GetMoleculeHandle(const G4Molecule* molecule) 00076 { 00077 MoleculeHandleMap::iterator it = fMoleculeHandle.find(molecule); 00078 G4MoleculeHandle molHandle; 00079 00080 if(it != fMoleculeHandle.end()) 00081 { 00082 molHandle = G4MoleculeHandle(it->second); 00083 } 00084 else 00085 { 00086 molHandle = G4MoleculeHandle(molecule); 00087 fMoleculeHandle.insert(make_pair(molecule, G4MoleculeHandle(molHandle))); 00088 } 00089 00090 return molHandle; 00091 }