G4ModelCompoundCommandsT.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 // Jane Tinslay September 2006
00029 //
00030 // Compound model commands.
00031 //
00032 #ifndef G4MODELCOMPOUNDCOMMANDST_HH
00033 #define G4MODELCOMPOUNDCOMMANDST_HH
00034 
00035 #include "G4ModelApplyCommandsT.hh"
00036 #include "G4ModelCommandUtils.hh"
00037 #include "G4ModelCommandsT.hh"
00038 #include "G4String.hh"
00039 
00041 // Set interval context
00042 template <typename M>
00043 class G4ModelCmdAddIntervalContext: public G4ModelCmdApplyString<M> {
00044 
00045 public: // With description
00046 
00047   G4ModelCmdAddIntervalContext(M* model, const G4String& placement, 
00048                             const G4String& cmdName="addInterval")
00049     :G4ModelCmdApplyString<M>(model, placement, cmdName) 
00050   {
00051     G4UIcmdWithAString* cmd = G4ModelCmdApplyString<M>::Command();
00052     cmd->SetGuidance("Add interval.");
00053   }
00054   
00055   virtual ~G4ModelCmdAddIntervalContext() {
00056     std::vector<G4UImessenger*>::iterator iter = fMessengers.begin();
00057     
00058     while (iter != fMessengers.end()) {
00059       delete *iter;
00060       iter++;
00061     }
00062   }
00063   
00064 protected:
00065   
00066   virtual void Apply(const G4String& param) {
00067     G4String myString(param);
00068 
00069     G4String name;
00070     std::istringstream is(param);
00071     
00072     is >> name;
00073 
00074     myString.erase(0, name.size());
00075 
00076     G4String dir = G4VModelCommand<M>::Placement()+"/"+G4VModelCommand<M>::Model()->Name();
00077     
00078     G4VisTrajContext* context = new G4VisTrajContext(name);
00079     
00080     G4ModelCommandUtils::AddContextMsgrs(context, fMessengers, dir);
00081     G4VModelCommand<M>::Model()->AddIntervalContext(myString, context);
00082   }
00083 
00084 private:
00085   
00086   std::vector<G4UImessenger*> fMessengers;
00087 
00088 };
00089 
00091 // Set value context
00092 template <typename M>
00093 class G4ModelCmdAddValueContext: public G4ModelCmdApplyString<M> {
00094 
00095 public: // With description
00096 
00097   G4ModelCmdAddValueContext(M* model, const G4String& placement, 
00098                             const G4String& cmdName="addValue")
00099     :G4ModelCmdApplyString<M>(model, placement, cmdName) 
00100   {
00101     G4UIcmdWithAString* cmd = G4ModelCmdApplyString<M>::Command();
00102     cmd->SetGuidance("Add value.");
00103   }
00104   
00105   virtual ~G4ModelCmdAddValueContext() {
00106     std::vector<G4UImessenger*>::iterator iter = fMessengers.begin();
00107     
00108     while (iter != fMessengers.end()) {
00109       delete *iter;
00110       iter++;
00111     }
00112   }
00113 
00114 protected:
00115 
00116   virtual void Apply(const G4String& param) {
00117     G4String myString(param);
00118 
00119     G4String name;
00120     std::istringstream is(param);
00121     
00122     is >> name;
00123 
00124     myString.erase(0, name.size());
00125 
00126     G4String dir = G4VModelCommand<M>::Placement()+"/"+G4VModelCommand<M>::Model()->Name();
00127     
00128     G4VisTrajContext* context = new G4VisTrajContext(name);
00129     
00130     G4ModelCommandUtils::AddContextMsgrs(context, fMessengers, dir);
00131     G4VModelCommand<M>::Model()->AddValueContext(myString, context);
00132   }
00133 
00134 private:
00135   
00136   std::vector<G4UImessenger*> fMessengers;
00137 
00138 };
00139 
00140 #endif

Generated on Mon May 27 17:48:52 2013 for Geant4 by  doxygen 1.4.7