G4VisModelManager.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$
00027 //
00028 // Generic model manager. Manages models, associated
00029 // factories, messengers, command placement etc
00030 //
00031 // Jane Tinslay, March 2006
00032 //
00033 #ifndef G4VISMODELMANAGER_HH
00034 #define G4VISMODELMANAGER_HH
00035 
00036 #include "G4UImessenger.hh"
00037 #include "G4VisCommandModelCreate.hh"
00038 #include "G4VisListManager.hh"
00039 #include "G4VModelFactory.hh"
00040 #include <vector>
00041 
00042 template <typename Model>
00043 class G4VisModelManager {
00044 
00045 public: // With description
00046 
00047   // Useful typedef's
00048   typedef G4VisListManager<Model> List;
00049   typedef G4VModelFactory<Model> Factory;
00050 
00051   G4VisModelManager(const G4String&);
00052   virtual ~G4VisModelManager();
00053 
00054   // Registration methods
00055   void Register(Model*);
00056   void Register(Factory*); 
00057 
00058   // Change/Retrieve "Current" object
00059   void SetCurrent(const G4String&);
00060   const Model* Current() const;
00061 
00062   // Command placement
00063   G4String Placement() const;
00064 
00065   // Print factory and model data
00066   void Print(std::ostream& ostr, const G4String& name="") const;
00067 
00068   // Accessors
00069   const List* ListManager() const;
00070   const std::vector<Factory*>& FactoryList() const;
00071 
00072 private:
00073 
00074   // Private copy constructor and assigment operator - copying and
00075   // assignment not allowed.  Keeps Coverity happy.
00076   G4VisModelManager (const G4VisModelManager&);
00077   G4VisModelManager& operator = (const G4VisModelManager&);
00078 
00079   // Data members
00080   G4String fPlacement;
00081   List* fpModelList;  
00082   std::vector<Factory*> fFactoryList;
00083   std::vector<G4UImessenger*> fMessengerList;
00084 
00085 };
00086 
00087 template <typename Model>
00088 G4VisModelManager<Model>::G4VisModelManager(const G4String& placement)
00089   :fPlacement(placement)
00090   ,fpModelList(new List)
00091 {}
00092 
00093 template <typename Model>
00094 G4VisModelManager<Model>::~G4VisModelManager() 
00095 {
00096   // Cleanup
00097   std::vector<G4UImessenger*>::iterator iterMsgr = fMessengerList.begin();
00098   
00099   while (iterMsgr != fMessengerList.end()) {
00100     delete *iterMsgr;
00101     iterMsgr++;
00102   }
00103 
00104   typename std::vector<Factory*>::iterator iterFactory = fFactoryList.begin();
00105   
00106   while (iterFactory != fFactoryList.end()) {
00107     delete *iterFactory;
00108     iterFactory++;
00109   }
00110 
00111   delete fpModelList;
00112 }
00113 
00114 template <typename Model>
00115 void
00116 G4VisModelManager<Model>::Register(Model* model)
00117 {
00118   fpModelList->Register(model);
00119 }
00120 
00121 template <typename Model>
00122 void
00123 G4VisModelManager<Model>::Register(Factory* factory)
00124 {
00125   // Assume ownership
00126   fFactoryList.push_back(factory);
00127 
00128   // Generate "create" command for this factory
00129   fMessengerList.push_back(new G4VisCommandModelCreate<Factory>(factory, fPlacement));
00130 }
00131 
00132 template <typename Model>
00133 void
00134 G4VisModelManager<Model>::SetCurrent(const G4String& model) 
00135 {
00136   fpModelList->SetCurrent(model);
00137 }
00138 
00139 template <typename Model>
00140 const Model*
00141 G4VisModelManager<Model>::Current() const
00142 {
00143   return fpModelList->Current();
00144 }
00145 
00146 template <typename Model>
00147 G4String
00148 G4VisModelManager<Model>::Placement() const
00149 {
00150   return fPlacement;
00151 }
00152 
00153 template <typename Model>
00154 void
00155 G4VisModelManager<Model>::Print(std::ostream& ostr, const G4String& name) const
00156 {
00157   ostr<<"Registered model factories:"<<std::endl;
00158 
00159   typename std::vector<Factory*>::const_iterator iter = fFactoryList.begin();
00160 
00161   while (iter != fFactoryList.end()) {
00162     (*iter)->Print(ostr);
00163     iter++;
00164   }
00165 
00166   if (0 == fFactoryList.size()) ostr<<"  None"<<std::endl;
00167 
00168   ostr<<std::endl;
00169   ostr<<"Registered models: "<<std::endl;
00170 
00171   fpModelList->Print(ostr, name);
00172 }
00173 
00174 template <typename Model>
00175 const G4VisListManager<Model>*
00176 G4VisModelManager<Model>::ListManager() const
00177 {
00178   return fpModelList;
00179 }
00180 
00181 template <typename Model>
00182 const std::vector<G4VModelFactory<Model>*>&
00183 G4VisModelManager<Model>::FactoryList() const
00184 {
00185   return fFactoryList;
00186 }
00187 
00188 #endif

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