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 // 00027 // $Id$ 00028 // 00029 00030 #ifndef G4UImessenger_h 00031 #define G4UImessenger_h 1 00032 00033 #include "globals.hh" 00034 #include "G4ios.hh" 00035 #include "G4UIdirectory.hh" 00036 00037 // class description: 00038 // 00039 // This class is the base class which represents a messenger which maintains 00040 // the commands. The user who wants to define some commands must create his/her 00041 // own concrete class derived from this class. The user's concrete messenger 00042 // must have a responsibility of creating and deleting commands. Also, it must 00043 // take care the delivering of the command to the destination class and replying 00044 // the current value(s) of the parameter(s). 00045 // 00046 00047 class G4UImessenger 00048 { 00049 public: // with description 00050 G4UImessenger(); 00051 G4UImessenger(const G4String& path, const G4String& dsc); 00052 // Constructor. In the implementation of the concrete messenger, all commands 00053 // related to the messenger must be constructed. 00054 virtual ~G4UImessenger(); 00055 // Destructor. In the implementation of the concrete messenger, all commands 00056 // defined in the constructor must be deleted. 00057 virtual G4String GetCurrentValue(G4UIcommand * command); 00058 // The concrete implementation of this method gets the current value(s) of the 00059 // parameter(s) of the given command from the destination class, converts the 00060 // value(s) to a string, and returns the string. Conversion could be done by 00061 // the ConvertToString() method of corresponding G4UIcmdXXX classes if the 00062 // the command is an object of these G4UIcmdXXX classes. 00063 virtual void SetNewValue(G4UIcommand * command,G4String newValue); 00064 // The concrete implementation of this method converts the string "newValue" 00065 // to value(s) of type(s) of the parameter(s). Convert methods corresponding 00066 // to the type of the command can be used if the command is an object of 00067 // G4UIcmdXXX classes. 00068 00069 public: 00070 G4bool operator == (const G4UImessenger& messenger) const; 00071 00072 protected: 00073 G4String ItoS(G4int i); 00074 G4String DtoS(G4double a); 00075 G4String BtoS(G4bool b); 00076 G4int StoI(G4String s); 00077 G4double StoD(G4String s); 00078 G4bool StoB(G4String s); 00079 00080 protected: 00081 void AddUIcommand(G4UIcommand * newCommand); 00082 00083 // shortcut way for creating directory and commands 00084 G4UIdirectory* baseDir; // used if new object is created 00085 G4String baseDirName; // used if dir already exists 00086 void CreateDirectory(const G4String& path, const G4String& dsc); 00087 template <typename T> T* CreateCommand(const G4String& cname, 00088 const G4String& dsc); 00089 00090 }; 00091 00092 template <typename T> 00093 T* G4UImessenger::CreateCommand(const G4String& cname, const G4String& dsc) 00094 { 00095 G4String path; 00096 if( cname(0) != '/' ) { 00097 path = baseDirName + cname; 00098 if (path(0) != '/') path = "/" + path; 00099 } 00100 00101 T* command = new T(path.c_str(), this); 00102 command-> SetGuidance(dsc.c_str()); 00103 00104 return command; 00105 } 00106 00107 #endif