Geant4-11
Public Types | Public Member Functions | Data Fields
G4GenericMessenger::Method Struct Reference

#include <G4GenericMessenger.hh>

Inheritance diagram for G4GenericMessenger::Method:
G4GenericMessenger::Command

Public Types

enum  UnitSpec { UnitCategory , UnitDefault }
 

Public Member Functions

 Method ()
 
 Method (const G4AnyMethod &fun, void *obj, G4UIcommand *cmd)
 
Command & SetCandidates (const G4String &)
 
Command & SetCandidates (G4int pIdx, const G4String &)
 
Command & SetDefaultUnit (const G4String &u)
 
Command & SetDefaultValue (const G4String &)
 
Command & SetDefaultValue (G4int pIdx, const G4String &)
 
Command & SetGuidance (const G4String &s0)
 
Command & SetParameterName (const G4String &, const G4String &, const G4String &, G4bool, G4bool=false)
 
Command & SetParameterName (const G4String &, G4bool, G4bool=false)
 
Command & SetParameterName (G4int pIdx, const G4String &, G4bool, G4bool=false)
 
Command & SetRange (const G4String &range)
 
Command & SetStates (G4ApplicationState s0)
 
Command & SetStates (G4ApplicationState s0, G4ApplicationState s1)
 
Command & SetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2)
 
Command & SetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3)
 
Command & SetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4)
 
Command & SetToBeBroadcasted (G4bool s0)
 
Command & SetToBeFlushed (G4bool s0)
 
Command & SetUnit (const G4String &, UnitSpec=UnitDefault)
 
Command & SetUnitCategory (const G4String &u)
 
Command & SetWorkerThreadOnly (G4bool s0)
 

Data Fields

G4UIcommand * command = nullptr
 
G4AnyMethod method
 
void * object = nullptr
 
const std::type_info * type = nullptr
 

Detailed Description

Definition at line 168 of file G4GenericMessenger.hh.

Member Enumeration Documentation

◆ UnitSpec

Enumerator
UnitCategory 
UnitDefault 

Definition at line 70 of file G4GenericMessenger.hh.

Constructor & Destructor Documentation

◆ Method() [1/2]

G4GenericMessenger::Method::Method ( const G4AnyMethod &  fun,
void *  obj,
G4UIcommand *  cmd 
)
inline

Definition at line 170 of file G4GenericMessenger.hh.

171 : Command(cmd, fun.ArgType())
172 , method(fun)
173 , object(obj)
174 {}
const std::type_info & ArgType(size_t n=0) const
Definition: G4AnyMethod.hh:160

◆ Method() [2/2]

G4GenericMessenger::Method::Method ( )
inline

Definition at line 175 of file G4GenericMessenger.hh.

176 {}

Member Function Documentation

◆ SetCandidates() [1/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetCandidates ( const G4String &  candList)
inherited

Definition at line 387 of file G4GenericMessenger.cc.

389{
390 return SetCandidates(0,candList);
391}
Command & SetCandidates(const G4String &)

◆ SetCandidates() [2/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetCandidates ( G4int  pIdx,
const G4String &  candList 
)
inherited

Definition at line 393 of file G4GenericMessenger.cc.

395{
396 if(pIdx < 0 || pIdx >= (G4int)(command->GetParameterEntries()))
397 {
398 G4cerr << "Invalid parameter index : " << pIdx << "\nMethod ignored."
399 << G4endl;
400 return *this;
401 }
402 G4UIparameter* theParam = command->GetParameter(pIdx);
403 theParam->SetParameterCandidates(candList);
404 return *this;
405}
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:139
void SetParameterCandidates(const char *theString)

References G4cerr, G4endl, and G4UIparameter::SetParameterCandidates().

◆ SetDefaultUnit()

Command & G4GenericMessenger::Command::SetDefaultUnit ( const G4String &  u)
inlineinherited

Definition at line 126 of file G4GenericMessenger.hh.

127 {
128 return SetUnit(u, UnitDefault);
129 }
Command & SetUnit(const G4String &, UnitSpec=UnitDefault)

References G4GenericMessenger::Command::SetUnit(), and G4GenericMessenger::Command::UnitDefault.

◆ SetDefaultValue() [1/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetDefaultValue ( const G4String &  defVal)
inherited

Definition at line 407 of file G4GenericMessenger.cc.

409{
410 return SetDefaultValue(0,defVal);
411}
Command & SetDefaultValue(const G4String &)

◆ SetDefaultValue() [2/2]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetDefaultValue ( G4int  pIdx,
const G4String &  defVal 
)
inherited

Definition at line 413 of file G4GenericMessenger.cc.

415{
416 if(pIdx < 0 || pIdx >= (G4int)(command->GetParameterEntries()))
417 {
418 G4cerr << "Invalid parameter index : " << pIdx << "\nMethod ignored."
419 << G4endl;
420 return *this;
421 }
422 G4UIparameter* theParam = command->GetParameter(pIdx);
423 theParam->SetDefaultValue(defVal);
424 return *this;
425}
void SetDefaultValue(const char *theDefaultValue)

References G4cerr, G4endl, and G4UIparameter::SetDefaultValue().

◆ SetGuidance()

Command & G4GenericMessenger::Command::SetGuidance ( const G4String &  s0)
inlineinherited

Definition at line 116 of file G4GenericMessenger.hh.

117 {
119 return *this;
120 }
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156

References G4GenericMessenger::Command::command, G4InuclParticleNames::s0, and G4UIcommand::SetGuidance().

◆ SetParameterName() [1/3]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetParameterName ( const G4String &  namex,
const G4String &  namey,
const G4String &  namez,
G4bool  omittable,
G4bool  currentAsDefault = false 
)
inherited

Definition at line 362 of file G4GenericMessenger.cc.

365{
366 if(*type != typeid(G4ThreeVector))
367 {
368 G4cerr << "This SetParameterName method is for G4ThreeVector!! "
369 << "Method ignored." << G4endl;
370 return *this;
371 }
372 G4UIparameter* theParam = command->GetParameter(0);
373 theParam->SetParameterName(namex);
374 theParam->SetOmittable(omittable);
375 theParam->SetCurrentAsDefault(currentAsDefault);
376 theParam = command->GetParameter(1);
377 theParam->SetParameterName(namey);
378 theParam->SetOmittable(omittable);
379 theParam->SetCurrentAsDefault(currentAsDefault);
380 theParam = command->GetParameter(2);
381 theParam->SetParameterName(namez);
382 theParam->SetOmittable(omittable);
383 theParam->SetCurrentAsDefault(currentAsDefault);
384 return *this;
385}
void SetParameterName(const char *pName)
void SetOmittable(G4bool om)
void SetCurrentAsDefault(G4bool val)
const std::type_info * type

References G4cerr, G4endl, G4UIparameter::SetCurrentAsDefault(), G4UIparameter::SetOmittable(), and G4UIparameter::SetParameterName().

◆ SetParameterName() [2/3]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetParameterName ( const G4String &  name,
G4bool  omittable,
G4bool  currentAsDefault = false 
)
inherited

Definition at line 339 of file G4GenericMessenger.cc.

341{
342 return SetParameterName(0,name,omittable,currentAsDefault);
343}
const char * name(G4int ptype)
Command & SetParameterName(const G4String &, G4bool, G4bool=false)

References G4InuclParticleNames::name().

◆ SetParameterName() [3/3]

G4GenericMessenger::Command & G4GenericMessenger::Command::SetParameterName ( G4int  pIdx,
const G4String &  name,
G4bool  omittable,
G4bool  currentAsDefault = false 
)
inherited

Definition at line 345 of file G4GenericMessenger.cc.

348{
349 if(pIdx < 0 || pIdx >= (G4int)(command->GetParameterEntries()))
350 {
351 G4cerr << "Invalid parameter index : " << pIdx << "\nMethod ignored."
352 << G4endl;
353 return *this;
354 }
355 G4UIparameter* theParam = command->GetParameter(pIdx);
356 theParam->SetParameterName(name);
357 theParam->SetOmittable(omittable);
358 theParam->SetCurrentAsDefault(currentAsDefault);
359 return *this;
360}

References G4cerr, G4endl, G4InuclParticleNames::name(), G4UIparameter::SetCurrentAsDefault(), G4UIparameter::SetOmittable(), and G4UIparameter::SetParameterName().

◆ SetRange()

Command & G4GenericMessenger::Command::SetRange ( const G4String &  range)
inlineinherited

Definition at line 111 of file G4GenericMessenger.hh.

112 {
113 command->SetRange(range.c_str());
114 return *this;
115 }
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120

References G4GenericMessenger::Command::command, and G4UIcommand::SetRange().

◆ SetStates() [1/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState  s0)
inlineinherited

Definition at line 82 of file G4GenericMessenger.hh.

83 {
85 return *this;
86 }
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:288

References G4UIcommand::AvailableForStates(), G4GenericMessenger::Command::command, and G4InuclParticleNames::s0.

Referenced by G4SteppingVerboseWithUnits::SetManager().

◆ SetStates() [2/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState  s0,
G4ApplicationState  s1 
)
inlineinherited

◆ SetStates() [3/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState  s0,
G4ApplicationState  s1,
G4ApplicationState  s2 
)
inlineinherited

Definition at line 92 of file G4GenericMessenger.hh.

94 {
96 return *this;
97 }

References G4UIcommand::AvailableForStates(), G4GenericMessenger::Command::command, and G4InuclParticleNames::s0.

◆ SetStates() [4/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState  s0,
G4ApplicationState  s1,
G4ApplicationState  s2,
G4ApplicationState  s3 
)
inlineinherited

Definition at line 98 of file G4GenericMessenger.hh.

100 {
101 command->AvailableForStates(s0, s1, s2, s3);
102 return *this;
103 }

References G4UIcommand::AvailableForStates(), G4GenericMessenger::Command::command, and G4InuclParticleNames::s0.

◆ SetStates() [5/5]

Command & G4GenericMessenger::Command::SetStates ( G4ApplicationState  s0,
G4ApplicationState  s1,
G4ApplicationState  s2,
G4ApplicationState  s3,
G4ApplicationState  s4 
)
inlineinherited

Definition at line 104 of file G4GenericMessenger.hh.

107 {
108 command->AvailableForStates(s0, s1, s2, s3, s4);
109 return *this;
110 }

References G4UIcommand::AvailableForStates(), G4GenericMessenger::Command::command, and G4InuclParticleNames::s0.

◆ SetToBeBroadcasted()

Command & G4GenericMessenger::Command::SetToBeBroadcasted ( G4bool  s0)
inlineinherited

Definition at line 138 of file G4GenericMessenger.hh.

139 {
141 return *this;
142 }
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172

References G4GenericMessenger::Command::command, G4InuclParticleNames::s0, and G4UIcommand::SetToBeBroadcasted().

◆ SetToBeFlushed()

Command & G4GenericMessenger::Command::SetToBeFlushed ( G4bool  s0)
inlineinherited

Definition at line 143 of file G4GenericMessenger.hh.

144 {
146 return *this;
147 }
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:174

References G4GenericMessenger::Command::command, G4InuclParticleNames::s0, and G4UIcommand::SetToBeFlushed().

◆ SetUnit()

G4GenericMessenger::Command & G4GenericMessenger::Command::SetUnit ( const G4String &  unit,
UnitSpec  spec = UnitDefault 
)
inherited

Definition at line 260 of file G4GenericMessenger.cc.

262{
263 // Change the type of command (unfortunatelly this is done a posteriory)
264 // We need to delete the old command before creating the new one and therefore
265 // we need to recover the information before the deletetion
267 {
268 G4String cmdpath = command->GetCommandPath();
270 ed << "G4GenericMessenger::Command::SetUnit() is thread-unsafe and should "
271 "not be used\n"
272 << "in multi-threaded mode. For your command <" << cmdpath << ">, use\n"
273 << " DeclarePropertyWithUnit(const G4String& name, const G4String& "
274 "defaultUnit,\n"
275 << " const G4AnyType& variable, const G4String& "
276 "doc)\n"
277 << "or\n"
278 << " DeclareMethodWithUnit(const G4String& name, const G4String& "
279 "defaultUnit,\n"
280 << " const G4AnyType& variable, const G4String& "
281 "doc)\n"
282 << "to define a command with a unit <" << unit << ">.";
283 if(spec != UnitDefault)
284 {
285 ed << "\nPlease use a default unit instead of unit category.";
286 }
287 G4Exception("G4GenericMessenger::Command::SetUnit()", "Intercom70001",
288 FatalException, ed);
289 return *this;
290 }
291
292 G4String cmdpath = command->GetCommandPath();
293 G4UImessenger* messenger = command->GetMessenger();
294 G4String range = command->GetRange();
295 std::vector<G4String> guidance;
297 G4bool par_omitable = command->GetParameter(0)->IsOmittable();
298 for(std::size_t i = 0; i < command->GetGuidanceEntries(); ++i)
299 guidance.push_back(command->GetGuidanceLine(i));
300 // Before deleting the command we need to add a fake one to avoid deleting
301 // the directory entry and with its guidance
302 G4UIcommand tmp((cmdpath + "_tmp").c_str(), messenger);
303 delete command;
304
305 if(*type == typeid(float) || *type == typeid(double))
306 {
308 new G4UIcmdWithADoubleAndUnit(cmdpath, messenger);
309 if(spec == UnitDefault)
310 cmd_t->SetDefaultUnit(unit);
311 else if(spec == UnitCategory)
312 cmd_t->SetUnitCategory(unit);
313 cmd_t->SetParameterName(par_name, par_omitable);
314 command = cmd_t;
315 }
316 else if(*type == typeid(G4ThreeVector))
317 {
319 new G4UIcmdWith3VectorAndUnit(cmdpath, messenger);
320 if(spec == UnitDefault)
321 cmd_t->SetDefaultUnit(unit);
322 else if(spec == UnitCategory)
323 cmd_t->SetUnitCategory(unit);
324 command = cmd_t;
325 }
326 else
327 {
328 G4cerr << "Only parameters of type <double> or <float> can be associated "
329 "with units"
330 << G4endl;
331 return *this;
332 }
333 for(std::size_t i = 0; i < guidance.size(); ++i)
334 command->SetGuidance(guidance[i]);
335 command->SetRange(range);
336 return *this;
337}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
void SetDefaultUnit(const char *defUnit)
void SetUnitCategory(const char *unitCategory)
void SetUnitCategory(const char *unitCategory)
void SetDefaultUnit(const char *defUnit)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4UImessenger * GetMessenger() const
Definition: G4UIcommand.hh:144
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:132
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:136
std::size_t GetGuidanceEntries() const
Definition: G4UIcommand.hh:128
const G4String & GetRange() const
Definition: G4UIcommand.hh:127
G4bool IsOmittable() const
const G4String & GetParameterName() const
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:130

References G4GenericMessenger::Command::command, FatalException, G4cerr, G4endl, G4Exception(), G4UIcommand::GetCommandPath(), G4UIcommand::GetGuidanceEntries(), G4UIcommand::GetGuidanceLine(), G4UIcommand::GetMessenger(), G4UIcommand::GetParameter(), G4UIparameter::GetParameterName(), G4UIcommand::GetRange(), G4Threading::IsMultithreadedApplication(), G4UIparameter::IsOmittable(), G4UIcmdWith3VectorAndUnit::SetDefaultUnit(), G4UIcmdWithADoubleAndUnit::SetDefaultUnit(), G4UIcommand::SetGuidance(), G4UIcmdWithADoubleAndUnit::SetParameterName(), G4UIcommand::SetRange(), G4UIcmdWith3VectorAndUnit::SetUnitCategory(), G4UIcmdWithADoubleAndUnit::SetUnitCategory(), G4GenericMessenger::Command::type, G4GenericMessenger::Command::UnitCategory, and G4GenericMessenger::Command::UnitDefault.

Referenced by G4GenericMessenger::Command::SetDefaultUnit(), and G4GenericMessenger::Command::SetUnitCategory().

◆ SetUnitCategory()

Command & G4GenericMessenger::Command::SetUnitCategory ( const G4String &  u)
inlineinherited

◆ SetWorkerThreadOnly()

Command & G4GenericMessenger::Command::SetWorkerThreadOnly ( G4bool  s0)
inlineinherited

Definition at line 148 of file G4GenericMessenger.hh.

149 {
151 return *this;
152 }
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:176

References G4GenericMessenger::Command::command, G4InuclParticleNames::s0, and G4UIcommand::SetWorkerThreadOnly().

Field Documentation

◆ command

G4UIcommand* G4GenericMessenger::Command::command = nullptr
inherited

◆ method

G4AnyMethod G4GenericMessenger::Method::method

Definition at line 177 of file G4GenericMessenger.hh.

◆ object

void* G4GenericMessenger::Method::object = nullptr

Definition at line 178 of file G4GenericMessenger.hh.

◆ type

const std::type_info* G4GenericMessenger::Command::type = nullptr
inherited

Definition at line 155 of file G4GenericMessenger.hh.

Referenced by G4GenericMessenger::Command::SetUnit().


The documentation for this struct was generated from the following file: