// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // $Id: G4VisListManager.hh,v 1.9 2010/12/11 17:01:25 allison Exp $ // GEANT4 tag $Name: $ // // Jane Tinslay, John Allison, Joseph Perl October 2005 // // Class Description: // Templated class to manage a set of objects, with one named // as current. Owns registered objects. // Class Description - End: #ifndef G4VISLISTMANAGER_HH #define G4VISLISTMANAGER_HH #include "G4String.hh" #include #include #include template class G4VisListManager { public: // With description G4VisListManager(); virtual ~G4VisListManager(); // Register ptr. Manager assumes ownership and // ptr becomes current void Register(T* ptr); void SetCurrent(const G4String& name); // Accessors const T* Current() const {return fpCurrent;} const std::map& Map() const; // Print configuration void Print(std::ostream& ostr, const G4String& name="") const; private: // Data members std::map fMap; T* fpCurrent; }; template G4VisListManager::G4VisListManager() :fpCurrent(0) {} template G4VisListManager::~G4VisListManager() { typename std::map::iterator iter = fMap.begin(); while (iter != fMap.end()) { delete iter->second; iter++; } } template void G4VisListManager::Register(T* ptr) { assert (0 != ptr); // Add to map. Replace if name the same. fMap[ptr->Name()] = ptr; fpCurrent = ptr; } template void G4VisListManager::SetCurrent(const G4String& name) { typename std::map::const_iterator iter = fMap.find(name); if (iter != fMap.end()) fpCurrent = fMap[name]; else { std::ostringstream o; o << "Key "<::SetCurrent(T* ptr) ", "NonExistentName", FatalErrorInArgument, o.str().c_str()); } } template void G4VisListManager::Print(std::ostream& ostr, const G4String& name) const { if (0 == fMap.size()) { G4cout<<" None"<Name()<::const_iterator iter = fMap.find(name); if (iter != fMap.end()) { iter->second->Print(ostr); } else { ostr<::const_iterator iter = fMap.begin(); while (iter != fMap.end()) { iter->second->Print(ostr); ostr< const std::map& G4VisListManager::Map() const { return fMap; } #endif