Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:16:51

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 // G4UImessenger
0027 //
0028 // Class description:
0029 //
0030 // This class is the base class representing a messenger which keeps all basic
0031 // commands. The user who wants to define some commands must create his/her
0032 // own concrete class derived from this class. The user's concrete messenger
0033 // must have a responsibility of creating and deleting commands. Also, it must
0034 // take care of the delivering of the commands to the destination class and
0035 // provide the current value(s) of the parameter(s)
0036 
0037 // Author: Makoto Asai, 1998
0038 // --------------------------------------------------------------------
0039 #ifndef G4UImessenger_hh
0040 #define G4UImessenger_hh 1
0041 
0042 #include "G4UIdirectory.hh"
0043 #include "G4ios.hh"
0044 #include "globals.hh"
0045 
0046 class G4UImessenger
0047 {
0048   public:
0049     // Constructor. In the implementation of the concrete messenger,
0050     // all commands related to the messenger must be constructed
0051     G4UImessenger() = default;
0052     G4UImessenger(const G4String& path, const G4String& dsc, G4bool commandsToBeBroadcasted = true);
0053 
0054     // Destructor. In the implementation of the concrete messenger,
0055     // all commands defined in the constructor must be deleted
0056     virtual ~G4UImessenger();
0057 
0058     // The concrete implementation of this method gets the current value(s)
0059     // of the parameter(s) of the given command from the destination class,
0060     // converts the value(s) to a string, and returns the string.
0061     // Conversion could be done by the ConvertToString() method of
0062     // corresponding G4UIcmdXXX classes if the command is an object of
0063     // these G4UIcmdXXX classes
0064     virtual G4String GetCurrentValue(G4UIcommand* command);
0065 
0066     // The concrete implementation of this method converts the string
0067     // "newValue" to value(s) of type(s) of the parameter(s).
0068     // Converted methods corresponding to the type of the command can be
0069     // used if the command is an object of G4UIcmdXXX classes
0070     virtual void SetNewValue(G4UIcommand* command, G4String newValue);
0071 
0072     inline G4bool CommandsShouldBeInMaster() const { return commandsShouldBeInMaster; }
0073 
0074   protected:
0075     G4String ItoS(G4int i);
0076     G4String LtoS(G4long l);
0077     G4String DtoS(G4double a);
0078     G4String BtoS(G4bool b);
0079     G4int StoI(const G4String& s);
0080     G4long StoL(const G4String& s);
0081     G4double StoD(const G4String& s);
0082     G4bool StoB(const G4String& s);
0083 
0084     void AddUIcommand(G4UIcommand* newCommand);
0085 
0086     // Shortcut way for creating directory and commands
0087     void CreateDirectory(const G4String& path, const G4String& dsc,
0088                          G4bool commandsToBeBroadcasted = true);
0089     template<typename T>
0090     T* CreateCommand(const G4String& cname, const G4String& dsc);
0091 
0092   protected:
0093     G4UIdirectory* baseDir = nullptr;  // used if new object is created
0094     G4String baseDirName = "";  // used if dir already exists
0095     G4bool commandsShouldBeInMaster = false;
0096 };
0097 
0098 // Inline template implementations
0099 
0100 template<typename T>
0101 T* G4UImessenger::CreateCommand(const G4String& cname, const G4String& dsc)
0102 {
0103   G4String path;
0104   if (cname[0] != '/') {
0105     path = baseDirName + cname;
0106     if (path[0] != '/') {
0107       path = "/" + path;
0108     }
0109   }
0110 
0111   T* command = new T(path.c_str(), this);
0112   command->SetGuidance(dsc.c_str());
0113 
0114   return command;
0115 }
0116 
0117 #endif