Import Geant4 10.7.0 source tree
This commit is contained in:
@@ -23,89 +23,102 @@
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// G4UImessenger
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// This class is the base class representing a messenger which keeps all basic
|
||||
// commands. The user who wants to define some commands must create his/her
|
||||
// own concrete class derived from this class. The user's concrete messenger
|
||||
// must have a responsibility of creating and deleting commands. Also, it must
|
||||
// take care of the delivering of the commands to the destination class and
|
||||
// provide the current value(s) of the parameter(s)
|
||||
|
||||
#ifndef G4UImessenger_h
|
||||
#define G4UImessenger_h 1
|
||||
// Author: Makoto Asai, 1998
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4UImessenger_hh
|
||||
#define G4UImessenger_hh 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4ios.hh"
|
||||
#include "G4UIdirectory.hh"
|
||||
|
||||
// class description:
|
||||
//
|
||||
// This class is the base class which represents a messenger which maintains
|
||||
// the commands. The user who wants to define some commands must create his/her
|
||||
// own concrete class derived from this class. The user's concrete messenger
|
||||
// must have a responsibility of creating and deleting commands. Also, it must
|
||||
// take care the delivering of the command to the destination class and replying
|
||||
// the current value(s) of the parameter(s).
|
||||
//
|
||||
|
||||
class G4UImessenger
|
||||
class G4UImessenger
|
||||
{
|
||||
public: // with description
|
||||
G4UImessenger();
|
||||
G4UImessenger(const G4String& path, const G4String& dsc,
|
||||
G4bool commandsToBeBroadcasted = true);
|
||||
// Constructor. In the implementation of the concrete messenger, all commands
|
||||
// related to the messenger must be constructed.
|
||||
virtual ~G4UImessenger();
|
||||
// Destructor. In the implementation of the concrete messenger, all commands
|
||||
// defined in the constructor must be deleted.
|
||||
virtual G4String GetCurrentValue(G4UIcommand * command);
|
||||
// The concrete implementation of this method gets the current value(s) of the
|
||||
// parameter(s) of the given command from the destination class, converts the
|
||||
// value(s) to a string, and returns the string. Conversion could be done by
|
||||
// the ConvertToString() method of corresponding G4UIcmdXXX classes if the
|
||||
// the command is an object of these G4UIcmdXXX classes.
|
||||
virtual void SetNewValue(G4UIcommand * command,G4String newValue);
|
||||
// The concrete implementation of this method converts the string "newValue"
|
||||
// to value(s) of type(s) of the parameter(s). Convert methods corresponding
|
||||
// to the type of the command can be used if the command is an object of
|
||||
// G4UIcmdXXX classes.
|
||||
|
||||
public:
|
||||
G4bool operator == (const G4UImessenger& messenger) const;
|
||||
|
||||
G4UImessenger();
|
||||
G4UImessenger(const G4String& path, const G4String& dsc,
|
||||
G4bool commandsToBeBroadcasted = true);
|
||||
// Constructor. In the implementation of the concrete messenger,
|
||||
// all commands related to the messenger must be constructed
|
||||
|
||||
virtual ~G4UImessenger();
|
||||
// Destructor. In the implementation of the concrete messenger,
|
||||
// all commands defined in the constructor must be deleted
|
||||
|
||||
virtual G4String GetCurrentValue(G4UIcommand* command);
|
||||
// The concrete implementation of this method gets the current value(s)
|
||||
// of the parameter(s) of the given command from the destination class,
|
||||
// converts the value(s) to a string, and returns the string.
|
||||
// Conversion could be done by the ConvertToString() method of
|
||||
// corresponding G4UIcmdXXX classes if the command is an object of
|
||||
// these G4UIcmdXXX classes
|
||||
|
||||
virtual void SetNewValue(G4UIcommand* command, G4String newValue);
|
||||
// The concrete implementation of this method converts the string
|
||||
// "newValue" to value(s) of type(s) of the parameter(s).
|
||||
// Converted methods corresponding to the type of the command can be
|
||||
// used if the command is an object of G4UIcmdXXX classes
|
||||
|
||||
G4bool operator==(const G4UImessenger& messenger) const;
|
||||
G4bool operator!=(const G4UImessenger& messenger) const;
|
||||
|
||||
inline G4bool CommandsShouldBeInMaster() const
|
||||
{
|
||||
return commandsShouldBeInMaster;
|
||||
}
|
||||
|
||||
protected:
|
||||
G4String ItoS(G4int i);
|
||||
G4String DtoS(G4double a);
|
||||
G4String BtoS(G4bool b);
|
||||
G4int StoI(G4String s);
|
||||
G4double StoD(G4String s);
|
||||
G4bool StoB(G4String s);
|
||||
|
||||
G4String ItoS(G4int i);
|
||||
G4String DtoS(G4double a);
|
||||
G4String BtoS(G4bool b);
|
||||
G4int StoI(G4String s);
|
||||
G4long StoL(G4String s);
|
||||
G4double StoD(G4String s);
|
||||
G4bool StoB(G4String s);
|
||||
|
||||
void AddUIcommand(G4UIcommand* newCommand);
|
||||
|
||||
void CreateDirectory(const G4String& path, const G4String& dsc,
|
||||
G4bool commandsToBeBroadcasted = true);
|
||||
template <typename T>
|
||||
T* CreateCommand(const G4String& cname, const G4String& dsc);
|
||||
// Shortcut way for creating directory and commands
|
||||
|
||||
protected:
|
||||
void AddUIcommand(G4UIcommand * newCommand);
|
||||
|
||||
// shortcut way for creating directory and commands
|
||||
G4UIdirectory* baseDir; // used if new object is created
|
||||
G4String baseDirName; // used if dir already exists
|
||||
void CreateDirectory(const G4String& path, const G4String& dsc,
|
||||
G4bool commandsToBeBroadcasted=true);
|
||||
template <typename T> T* CreateCommand(const G4String& cname,
|
||||
const G4String& dsc);
|
||||
|
||||
protected:
|
||||
G4bool commandsShouldBeInMaster;
|
||||
public:
|
||||
G4bool CommandsShouldBeInMaster() const
|
||||
{ return commandsShouldBeInMaster; }
|
||||
G4UIdirectory* baseDir = nullptr; // used if new object is created
|
||||
G4String baseDirName = ""; // used if dir already exists
|
||||
G4bool commandsShouldBeInMaster = false;
|
||||
};
|
||||
|
||||
// Inline template implementations
|
||||
|
||||
template <typename T>
|
||||
T* G4UImessenger::CreateCommand(const G4String& cname, const G4String& dsc)
|
||||
{
|
||||
G4String path;
|
||||
if( cname(0) != '/' ) {
|
||||
if(cname(0) != '/')
|
||||
{
|
||||
path = baseDirName + cname;
|
||||
if (path(0) != '/') path = "/" + path;
|
||||
if(path(0) != '/')
|
||||
path = "/" + path;
|
||||
}
|
||||
|
||||
T* command = new T(path.c_str(), this);
|
||||
command-> SetGuidance(dsc.c_str());
|
||||
command->SetGuidance(dsc.c_str());
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user