Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:24

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 //
0027 // Generic model manager. Manages models, associated
0028 // factories, messengers, command placement etc
0029 //
0030 // Jane Tinslay, March 2006
0031 //
0032 #ifndef G4VISMODELMANAGER_HH
0033 #define G4VISMODELMANAGER_HH
0034 
0035 #include "G4UImessenger.hh"
0036 #include "G4VisCommandModelCreate.hh"
0037 #include "G4VisListManager.hh"
0038 #include "G4VModelFactory.hh"
0039 #include <vector>
0040 
0041 template <typename Model>
0042 class G4VisModelManager {
0043 
0044 public: // With description
0045 
0046   // Useful typedef's
0047   typedef G4VisListManager<Model> List;
0048   typedef G4VModelFactory<Model> Factory;
0049 
0050   G4VisModelManager(const G4String&);
0051   virtual ~G4VisModelManager();
0052 
0053   // Registration methods
0054   void Register(Model*);
0055   void Register(Factory*); 
0056 
0057   // Change/Retrieve "Current" object
0058   void SetCurrent(const G4String&);
0059   const Model* Current() const;
0060 
0061   // Command placement
0062   G4String Placement() const;
0063 
0064   // Print factory and model data
0065   void Print(std::ostream& ostr, const G4String& name="") const;
0066 
0067   // Accessors
0068   const List* ListManager() const;
0069   const std::vector<Factory*>& FactoryList() const;
0070 
0071 private:
0072 
0073   // Private copy constructor and assigment operator - copying and
0074   // assignment not allowed.  Keeps Coverity happy.
0075   G4VisModelManager (const G4VisModelManager&);
0076   G4VisModelManager& operator = (const G4VisModelManager&);
0077 
0078   // Data members
0079   G4String fPlacement;
0080   List* fpModelList;  
0081   std::vector<Factory*> fFactoryList;
0082   std::vector<G4UImessenger*> fMessengerList;
0083 
0084 };
0085 
0086 template <typename Model>
0087 G4VisModelManager<Model>::G4VisModelManager(const G4String& placement)
0088   :fPlacement(placement)
0089   ,fpModelList(new List)
0090 {}
0091 
0092 template <typename Model>
0093 G4VisModelManager<Model>::~G4VisModelManager() 
0094 {
0095   // Cleanup
0096   std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
0097   
0098   while (iterMsgr != fMessengerList.end()) {
0099     delete *iterMsgr;
0100     iterMsgr++;
0101   }
0102 
0103   typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
0104   
0105   while (iterFactory != fFactoryList.end()) {
0106     delete *iterFactory;
0107     iterFactory++;
0108   }
0109 
0110   delete fpModelList;
0111 }
0112 
0113 template <typename Model>
0114 void
0115 G4VisModelManager<Model>::Register(Model* model)
0116 {
0117   fpModelList->Register(model);
0118 }
0119 
0120 template <typename Model>
0121 void
0122 G4VisModelManager<Model>::Register(Factory* factory)
0123 {
0124   // Assume ownership
0125   fFactoryList.push_back(factory);
0126 
0127   // Generate "create" command for this factory
0128   fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
0129 }
0130 
0131 template <typename Model>
0132 void
0133 G4VisModelManager<Model>::SetCurrent(const G4String& model) 
0134 {
0135   fpModelList->SetCurrent(model);
0136 }
0137 
0138 template <typename Model>
0139 const Model*
0140 G4VisModelManager<Model>::Current() const
0141 {
0142   return fpModelList->Current();
0143 }
0144 
0145 template <typename Model>
0146 G4String
0147 G4VisModelManager<Model>::Placement() const
0148 {
0149   return fPlacement;
0150 }
0151 
0152 template <typename Model>
0153 void
0154 G4VisModelManager<Model>::Print(std::ostream& ostr, const G4String& name) const
0155 {
0156   ostr<<"Registered model factories:"<<std::endl;
0157 
0158   typename std::vector<Factory*>::const_iterator iter = fFactoryList.begin();
0159 
0160   while (iter != fFactoryList.end()) {
0161     (*iter)->Print(ostr);
0162     iter++;
0163   }
0164 
0165   if (0 == fFactoryList.size()) ostr<<"  None"<<std::endl;
0166 
0167   ostr<<std::endl;
0168   ostr<<"Registered models: "<<std::endl;
0169 
0170   fpModelList->Print(ostr, name);
0171 }
0172 
0173 template <typename Model>
0174 const G4VisListManager<Model>*
0175 G4VisModelManager<Model>::ListManager() const
0176 {
0177   return fpModelList;
0178 }
0179 
0180 template <typename Model>
0181 const std::vector<G4VModelFactory<Model>*>&
0182 G4VisModelManager<Model>::FactoryList() const
0183 {
0184   return fFactoryList;
0185 }
0186 
0187 #endif