63 const char*
what()
const throw()
override
65 return "G4InvalidUICommand: command does not exist or is of invalid type";
70 : directory(dir), object(obj)
79 for (
const auto& propertie : properties) {
80 delete propertie.second.command;
82 for (
const auto& method : methods) {
83 delete method.second.command;
90 G4String fullpath = directory + name;
95 ->SetParameterName(
"valueX",
"valueY",
"valueZ",
false,
false);
101 || var.
TypeInfo() ==
typeid(
unsigned int) || var.
TypeInfo() ==
typeid(
unsigned long))
105 else if (var.
TypeInfo() ==
typeid(
float) || var.
TypeInfo() ==
typeid(
double)) {
108 else if (var.
TypeInfo() ==
typeid(
bool)) {
122 return properties[name] =
Property(var, cmd);
134 G4String fullpath = directory + name;
144 ->SetParameterName(
"valueX",
"valueY",
"valueZ",
false,
false);
151 return properties[name] =
Property(var, cmd);
157 G4String fullpath = directory + name;
158 auto* cmd =
new G4UIcommand(fullpath.c_str(),
this);
160 cmd->SetGuidance(doc);
162 for (std::size_t i = 0; i < fun.
NArg(); ++i) {
166 if (tInfo ==
typeid(
int) || tInfo ==
typeid(
long) || tInfo ==
typeid(
unsigned int)
167 || tInfo ==
typeid(
unsigned long))
171 else if (tInfo ==
typeid(
float) || tInfo ==
typeid(
double)) {
174 else if (tInfo ==
typeid(
bool)) {
177 else if (tInfo ==
typeid(
G4String)) {
185 return methods[name] =
Method(fun,
object, cmd);
193 G4String fullpath = directory + name;
194 if (fun.
NArg() != 1) {
196 ed <<
"G4GenericMessenger::DeclareMethodWithUnit() does not support a "
197 "method that has more than\n"
198 <<
"one arguments (or no argument). Please use "
199 "G4GenericMessenger::DeclareMethod method for\n"
200 <<
"your command <" << fullpath <<
">.";
209 return methods[name] =
Method(fun,
object, cmd);
214 if (properties.find(command->
GetCommandName()) != properties.cend()) {
219 G4cout <<
" GetCurrentValue() is not available for a command defined by "
220 "G4GenericMessenger::DeclareMethod()."
245 if (properties.find(command->
GetCommandName()) != properties.cend()) {
249 else if (methods.find(command->
GetCommandName()) != methods.cend()) {
251 if (m.method.NArg() == 0) {
252 m.method.operator()(m.object);
254 else if (m.method.NArg() > 0) {
257 for (std::size_t i = 0; i < m.method.NArg(); ++i) {
259 if(m.method.ArgType(i)==
typeid(
bool)) {
266 paraValue += aToken +
" ";
268 m.method.operator()(m.object, paraValue);
290 ed <<
"G4GenericMessenger::Command::SetUnit() is thread-unsafe and should "
292 <<
"in multi-threaded mode. For your command <" << cmdpath <<
">, use\n"
293 <<
" DeclarePropertyWithUnit(const G4String& name, const G4String& "
295 <<
" const G4AnyType& variable, const G4String& "
298 <<
" DeclareMethodWithUnit(const G4String& name, const G4String& "
300 <<
" const G4AnyType& variable, const G4String& "
302 <<
"to define a command with a unit <" << unit <<
">.";
304 ed <<
"\nPlease use a default unit instead of unit category.";
313 std::vector<G4String> guidance;
321 G4UIcommand tmp((cmdpath +
"_tmp").c_str(), messenger);
324 if (*
type ==
typeid(
float) || *
type ==
typeid(
double)) {
327 cmd_t->SetDefaultUnit(unit);
330 cmd_t->SetUnitCategory(unit);
332 cmd_t->SetParameterName(par_name, par_omitable);
338 cmd_t->SetDefaultUnit(unit);
341 cmd_t->SetUnitCategory(unit);
346 G4cerr <<
"Only parameters of type <double> or <float> can be associated "
351 for (
auto& i : guidance) {
362 return SetParameterName(0, name, omittable, currentAsDefault);
370 if (pIdx < 0 || pIdx >= (
G4int)(command->GetParameterEntries())) {
371 G4cerr <<
"Invalid parameter index : " << pIdx <<
"\nMethod ignored." <<
G4endl;
388 G4cerr <<
"This SetParameterName method is for G4ThreeVector!! "
389 <<
"Method ignored." <<
G4endl;
396 theParam = command->GetParameter(1);
400 theParam = command->GetParameter(2);
409 return SetCandidates(0, candList);
415 if (pIdx < 0 || pIdx >= (
G4int)(command->GetParameterEntries())) {
416 G4cerr <<
"Invalid parameter index : " << pIdx <<
"\nMethod ignored." <<
G4endl;
426 return SetDefaultValue(0, defVal);
432 if (pIdx < 0 || pIdx >= (
G4int)(command->GetParameterEntries())) {
433 G4cerr <<
"Invalid parameter index : " << pIdx <<
"\nMethod ignored." <<
G4endl;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const std::type_info & ArgType(size_t n=0) const
void FromString(const std::string &val)
const std::type_info & TypeInfo() const
std::string ToString() const
Command & DeclareMethod(const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
void SetGuidance(const G4String &s)
~G4GenericMessenger() override
Command & DeclareProperty(const G4String &name, const G4AnyType &variable, const G4String &doc="")
Command & DeclareMethodWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyMethod &fun, const G4String &doc="")
G4GenericMessenger(void *obj, const G4String &dir="", const G4String &doc="")
void SetNewValue(G4UIcommand *command, G4String newValue) override
G4String GetCurrentValue(G4UIcommand *command) override
Command & DeclarePropertyWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyType &variable, const G4String &doc="")
G4InvalidUICommand()=default
const char * what() const override
G4UImessenger * GetMessenger() const
const G4String & GetGuidanceLine(G4int i) const
G4UIparameter * GetParameter(G4int i) const
static G4String ConvertToString(G4bool boolVal)
const G4String & GetCommandPath() const
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
std::size_t GetGuidanceEntries() const
void SetRange(const char *rs)
static G4double ConvertToDimensionedDouble(const char *st)
const G4String & GetCommandName() const
const G4String & GetRange() const
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
void SetDefaultValue(const char *theDefaultValue)
void SetParameterName(const char *pName)
G4bool IsOmittable() const
void SetOmittable(G4bool om)
void SetParameterCandidates(const char *theString)
void SetCurrentAsDefault(G4bool val)
const G4String & GetParameterName() const
G4bool IsMultithreadedApplication()
Command & SetParameterName(const G4String &, G4bool, G4bool=false)
Command & SetCandidates(const G4String &)
Command & SetDefaultValue(const G4String &)
const std::type_info * type
Command & SetUnit(const G4String &, UnitSpec=UnitDefault)