Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GenericMessenger Class Reference

This class is generic messenger. More...

#include <G4GenericMessenger.hh>

Inheritance diagram for G4GenericMessenger:
Collaboration diagram for G4GenericMessenger:

Classes

struct  Command
 
struct  Method
 
struct  Property
 

Public Member Functions

 G4GenericMessenger (void *obj, const G4String &dir="", const G4String &doc="")
 Contructor. More...
 
virtual ~G4GenericMessenger ()
 Destructor. More...
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 The concrete, but generic implementation of this method. More...
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 The concrete, generic implementation of this method converts the string "newValue" to action. More...
 
CommandDeclareProperty (const G4String &name, const G4AnyType &variable, const G4String &doc="")
 Declare Methods. More...
 
CommandDeclarePropertyWithUnit (const G4String &name, const G4String &defaultUnit, const G4AnyType &variable, const G4String &doc="")
 
CommandDeclareMethod (const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
 
CommandDeclareMethodWithUnit (const G4String &name, const G4String &defaultUnit, const G4AnyMethod &fun, const G4String &doc="")
 
void SetDirectory (const G4String &dir)
 
void SetGuidance (const G4String &s)
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (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)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
G4bool commandsShouldBeInMaster
 

Detailed Description

This class is generic messenger.

Definition at line 46 of file G4GenericMessenger.hh.

Constructor & Destructor Documentation

G4GenericMessenger::G4GenericMessenger ( void obj,
const G4String dir = "",
const G4String doc = "" 
)

Contructor.

Definition at line 48 of file G4GenericMessenger.cc.

48  : directory(dir), object(obj) {
49  // Check if parent commnand is already existing.
50  // In fact there is no way to check this. UImanager->GetTree()->FindPath() will always rerurn NULL is a dicrectory is given
51  size_t pos = dir.find_last_of('/', dir.size()-2);
52  while(pos != 0 && pos != std::string::npos) {
53  G4UIdirectory* d = new G4UIdirectory(dir.substr(0,pos+1).c_str());
54  G4String guidance = "Commands for ";
55  guidance += dir.substr(1,pos-1);
56  d->SetGuidance(guidance);
57  pos = dir.find_last_of('/', pos-1);
58  }
59  dircmd = new G4UIdirectory(dir);
60  dircmd->SetGuidance(doc);
61 }
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
static const G4double pos

Here is the call graph for this function:

G4GenericMessenger::~G4GenericMessenger ( )
virtual

Destructor.

Definition at line 63 of file G4GenericMessenger.cc.

63  {
64  delete dircmd;
65  for (std::map<G4String, Property>::iterator i = properties.begin(); i != properties.end(); i++) delete i->second.command;
66  for (std::map<G4String, Method>::iterator i = methods.begin(); i != methods.end(); i++) delete i->second.command;
67 }
for(G4int i1=0;i1< theStableOnes.GetNumberOfIsotopes(static_cast< G4int >(anE->GetZ()));i1++)

Here is the call graph for this function:

Member Function Documentation

G4GenericMessenger::Command & G4GenericMessenger::DeclareMethod ( const G4String name,
const G4AnyMethod fun,
const G4String doc = "" 
)

Definition at line 112 of file G4GenericMessenger.cc.

112  {
113  G4String fullpath = directory+name;
114  G4UIcommand* cmd = new G4UIcommand(fullpath.c_str(), this);
115  if(doc != "") cmd->SetGuidance(doc);
116  for (size_t i = 0; i < fun.NArg(); i++) {
117  cmd->SetParameter(new G4UIparameter("arg", 's', false));
118  }
119  return methods[name] = Method(fun, object, cmd);
120 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
const XML_Char * name
Definition: expat.h:151
size_t NArg() const
Definition: G4AnyMethod.hh:139
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161

Here is the call graph for this function:

Here is the caller graph for this function:

G4GenericMessenger::Command & G4GenericMessenger::DeclareMethodWithUnit ( const G4String name,
const G4String defaultUnit,
const G4AnyMethod fun,
const G4String doc = "" 
)

Definition at line 123 of file G4GenericMessenger.cc.

123  {
124  G4String fullpath = directory+name;
125  if(fun.NArg()!=1) {
127  ed<<"G4GenericMessenger::DeclareMethodWithUnit() does not support a method that has more than\n"
128  <<"one arguments (or no argument). Please use G4GenericMessenger::DeclareMethod method for\n"
129  <<"your command <"<<fullpath<<">.";
130  G4Exception("G4GenericMessenger::DeclareMethodWithUnit()","Intercom70002",FatalException,ed);
131  }
132  G4UIcommand* cmd = new G4UIcmdWithADoubleAndUnit(fullpath.c_str(), this);
133  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetParameterName("value",false,false);
134  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetDefaultUnit(defaultUnit);
135  if(doc != "") cmd->SetGuidance(doc);
136  return methods[name] = Method(fun, object, cmd);
137 }
const XML_Char * name
Definition: expat.h:151
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
size_t NArg() const
Definition: G4AnyMethod.hh:139
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)

Here is the call graph for this function:

G4GenericMessenger::Command & G4GenericMessenger::DeclareProperty ( const G4String name,
const G4AnyType variable,
const G4String doc = "" 
)

Declare Methods.

Definition at line 71 of file G4GenericMessenger.cc.

71  {
72  G4String fullpath = directory+name;
73  G4UIcommand* cmd = new G4UIcommand(fullpath.c_str(), this);
74  if(doc != "") cmd->SetGuidance(doc);
75  char ptype;
76  if(var.TypeInfo() == typeid(int) || var.TypeInfo() == typeid(long) ||
77  var.TypeInfo() == typeid(unsigned int) || var.TypeInfo() == typeid(unsigned long)) ptype = 'i';
78  else if(var.TypeInfo() == typeid(float) || var.TypeInfo() == typeid(double)) ptype = 'd';
79  else if(var.TypeInfo() == typeid(bool)) ptype = 'b';
80  else if(var.TypeInfo() == typeid(G4String)) ptype = 's';
81  else ptype = 's';
82  cmd->SetParameter(new G4UIparameter("value", ptype, false));
83  return properties[name] = Property(var, cmd);
84 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
const XML_Char * name
Definition: expat.h:151
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)

Here is the call graph for this function:

G4GenericMessenger::Command & G4GenericMessenger::DeclarePropertyWithUnit ( const G4String name,
const G4String defaultUnit,
const G4AnyType variable,
const G4String doc = "" 
)

Definition at line 88 of file G4GenericMessenger.cc.

88  {
89  if(var.TypeInfo()!=typeid(float) && var.TypeInfo()!=typeid(double) && var.TypeInfo()!= typeid(G4ThreeVector))
90  { return DeclareProperty(name,var,doc); }
91  G4String fullpath = directory+name;
92  G4UIcommand* cmd;
93  if(var.TypeInfo()==typeid(float) || var.TypeInfo()==typeid(double))
94  {
95  cmd = new G4UIcmdWithADoubleAndUnit(fullpath.c_str(), this);
96  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetParameterName("value",false,false);
97  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetDefaultUnit(defaultUnit);
98  }
99  else
100  {
101  cmd = new G4UIcmdWith3VectorAndUnit(fullpath.c_str(), this);
102  (static_cast<G4UIcmdWith3VectorAndUnit*>(cmd))->SetParameterName("valueX","valueY","valueZ",false,false);
103  (static_cast<G4UIcmdWith3VectorAndUnit*>(cmd))->SetDefaultUnit(defaultUnit);
104  }
105 
106  if(doc != "") cmd->SetGuidance(doc);
107  return properties[name] = Property(var, cmd);
108 }
const XML_Char * name
Definition: expat.h:151
CLHEP::Hep3Vector G4ThreeVector
Command & DeclareProperty(const G4String &name, const G4AnyType &variable, const G4String &doc="")
Declare Methods.
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)

Here is the call graph for this function:

G4String G4GenericMessenger::GetCurrentValue ( G4UIcommand command)
virtual

The concrete, but generic implementation of this method.

Reimplemented from G4UImessenger.

Definition at line 140 of file G4GenericMessenger.cc.

140  {
141  if ( properties.find(command->GetCommandName()) != properties.end()) {
142  Property& p = properties[command->GetCommandName()];
143  return p.variable.ToString();
144  }
145  else if ( methods.find(command->GetCommandName()) != methods.end()) {
146  G4cout<<" GetCurrentValue() is not available for a command defined by G4GenericMessenger::DeclareMethod()."<<G4endl;
147  return G4String();
148  }
149  else {
150  throw G4InvalidUICommand();
151  }
152 }
const char * p
Definition: xmltok.h:285
G4GLOB_DLL std::ostream G4cout
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

void G4GenericMessenger::SetDirectory ( const G4String dir)
inline

Definition at line 103 of file G4GenericMessenger.hh.

103 {directory = dir;}
void G4GenericMessenger::SetGuidance ( const G4String s)

Definition at line 181 of file G4GenericMessenger.cc.

181  {
182  dircmd->SetGuidance(s);
183 }
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161

Here is the call graph for this function:

void G4GenericMessenger::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
virtual

The concrete, generic implementation of this method converts the string "newValue" to action.

Reimplemented from G4UImessenger.

Definition at line 154 of file G4GenericMessenger.cc.

154  {
155  // Check if there are units on this commands
156  if (typeid(*command) == typeid(G4UIcmdWithADoubleAndUnit)) {
158  }
159  else if (typeid(*command) == typeid(G4UIcmdWith3VectorAndUnit)) {
161  }
162 
163  if ( properties.find(command->GetCommandName()) != properties.end()) {
164  Property& p = properties[command->GetCommandName()];
165  p.variable.FromString(newValue);
166  }
167  else if (methods.find(command->GetCommandName()) != methods.end()) {
168  Method& m = methods[command->GetCommandName()];
169  if(m.method.NArg() == 0)
170  m.method.operator()(m.object);
171  else if (m.method.NArg() > 0) {
172  m.method.operator()(m.object,newValue);
173  }
174  else {
175  throw G4InvalidUICommand();
176  }
177  }
178 }
const char * p
Definition: xmltok.h:285
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:372
static G4double ConvertToDimensionedDouble(const char *st)
Definition: G4UIcommand.cc:463
static constexpr double m
Definition: G4SIunits.hh:129
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:485

Here is the call graph for this function:


The documentation for this class was generated from the following files: