Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 49 of file G4GenericMessenger.cc.

49  : directory(dir), object(obj) {
50  // Check if parent commnand is already existing.
51  // In fact there is no way to check this. UImanager->GetTree()->FindPath() will always rerurn NULL is a dicrectory is given
52  size_t pos = dir.find_last_of('/', dir.size()-2);
53  while(pos != 0 && pos != std::string::npos) {
54  G4UIdirectory* d = new G4UIdirectory(dir.substr(0,pos+1).c_str());
55  G4String guidance = "Commands for ";
56  guidance += dir.substr(1,pos-1);
57  d->SetGuidance(guidance);
58  pos = dir.find_last_of('/', pos-1);
59  }
60  dircmd = new G4UIdirectory(dir);
61  dircmd->SetGuidance(doc);
62 }
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 64 of file G4GenericMessenger.cc.

64  {
65  delete dircmd;
66  for (std::map<G4String, Property>::iterator i = properties.begin(); i != properties.end(); i++) delete i->second.command;
67  for (std::map<G4String, Method>::iterator i = methods.begin(); i != methods.end(); i++) delete i->second.command;
68 }
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 113 of file G4GenericMessenger.cc.

113  {
114  G4String fullpath = directory+name;
115  G4UIcommand* cmd = new G4UIcommand(fullpath.c_str(), this);
116  if(doc != "") cmd->SetGuidance(doc);
117  for (size_t i = 0; i < fun.NArg(); i++) {
118  cmd->SetParameter(new G4UIparameter("arg", 's', false));
119  }
120  return methods[name] = Method(fun, object, cmd);
121 }
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
const XML_Char * name
Definition: expat.h:151
size_t NArg() const
Definition: G4AnyMethod.hh:141
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 124 of file G4GenericMessenger.cc.

124  {
125  G4String fullpath = directory+name;
126  if(fun.NArg()!=1) {
128  ed<<"G4GenericMessenger::DeclareMethodWithUnit() does not support a method that has more than\n"
129  <<"one arguments (or no argument). Please use G4GenericMessenger::DeclareMethod method for\n"
130  <<"your command <"<<fullpath<<">.";
131  G4Exception("G4GenericMessenger::DeclareMethodWithUnit()","Intercom70002",FatalException,ed);
132  }
133  G4UIcommand* cmd = new G4UIcmdWithADoubleAndUnit(fullpath.c_str(), this);
134  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetParameterName("value",false,false);
135  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetDefaultUnit(defaultUnit);
136  if(doc != "") cmd->SetGuidance(doc);
137  return methods[name] = Method(fun, object, cmd);
138 }
const XML_Char * name
Definition: expat.h:151
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
size_t NArg() const
Definition: G4AnyMethod.hh:141
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 72 of file G4GenericMessenger.cc.

72  {
73  G4String fullpath = directory+name;
74  G4UIcommand* cmd = new G4UIcommand(fullpath.c_str(), this);
75  if(doc != "") cmd->SetGuidance(doc);
76  char ptype;
77  if(var.TypeInfo() == typeid(int) || var.TypeInfo() == typeid(long) ||
78  var.TypeInfo() == typeid(unsigned int) || var.TypeInfo() == typeid(unsigned long)) ptype = 'i';
79  else if(var.TypeInfo() == typeid(float) || var.TypeInfo() == typeid(double)) ptype = 'd';
80  else if(var.TypeInfo() == typeid(bool)) ptype = 'b';
81  else if(var.TypeInfo() == typeid(G4String)) ptype = 's';
82  else ptype = 's';
83  cmd->SetParameter(new G4UIparameter("value", ptype, false));
84  return properties[name] = Property(var, cmd);
85 }
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:

Here is the caller graph for this function:

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

Definition at line 89 of file G4GenericMessenger.cc.

89  {
90  if(var.TypeInfo()!=typeid(float) && var.TypeInfo()!=typeid(double) && var.TypeInfo()!= typeid(G4ThreeVector))
91  { return DeclareProperty(name,var,doc); }
92  G4String fullpath = directory+name;
93  G4UIcommand* cmd;
94  if(var.TypeInfo()==typeid(float) || var.TypeInfo()==typeid(double))
95  {
96  cmd = new G4UIcmdWithADoubleAndUnit(fullpath.c_str(), this);
97  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetParameterName("value",false,false);
98  (static_cast<G4UIcmdWithADoubleAndUnit*>(cmd))->SetDefaultUnit(defaultUnit);
99  }
100  else
101  {
102  cmd = new G4UIcmdWith3VectorAndUnit(fullpath.c_str(), this);
103  (static_cast<G4UIcmdWith3VectorAndUnit*>(cmd))->SetParameterName("valueX","valueY","valueZ",false,false);
104  (static_cast<G4UIcmdWith3VectorAndUnit*>(cmd))->SetDefaultUnit(defaultUnit);
105  }
106 
107  if(doc != "") cmd->SetGuidance(doc);
108  return properties[name] = Property(var, cmd);
109 }
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 141 of file G4GenericMessenger.cc.

141  {
142  if ( properties.find(command->GetCommandName()) != properties.end()) {
143  Property& p = properties[command->GetCommandName()];
144  return p.variable.ToString();
145  }
146  else if ( methods.find(command->GetCommandName()) != methods.end()) {
147  G4cout<<" GetCurrentValue() is not available for a command defined by G4GenericMessenger::DeclareMethod()."<<G4endl;
148  return G4String();
149  }
150  else {
151  throw G4InvalidUICommand();
152  }
153 }
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 182 of file G4GenericMessenger.cc.

182  {
183  dircmd->SetGuidance(s);
184 }
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 155 of file G4GenericMessenger.cc.

155  {
156  // Check if there are units on this commands
157  if (typeid(*command) == typeid(G4UIcmdWithADoubleAndUnit)) {
159  }
160  else if (typeid(*command) == typeid(G4UIcmdWith3VectorAndUnit)) {
162  }
163 
164  if ( properties.find(command->GetCommandName()) != properties.end()) {
165  Property& p = properties[command->GetCommandName()];
166  p.variable.FromString(newValue);
167  }
168  else if (methods.find(command->GetCommandName()) != methods.end()) {
169  Method& m = methods[command->GetCommandName()];
170  if(m.method.NArg() == 0)
171  m.method.operator()(m.object);
172  else if (m.method.NArg() > 0) {
173  m.method.operator()(m.object,newValue);
174  }
175  else {
176  throw G4InvalidUICommand();
177  }
178  }
179 }
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: