Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GenericMessenger::Command Struct Reference

#include <G4GenericMessenger.hh>

+ Inheritance diagram for G4GenericMessenger::Command:

Public Types

enum  UnitSpec { UnitCategory , UnitDefault }
 

Public Member Functions

 Command (G4UIcommand *cmd, const std::type_info &ti)
 
 Command ()
 
CommandSetStates (G4ApplicationState s0)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3)
 
CommandSetStates (G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4)
 
CommandSetRange (const G4String &range)
 
CommandSetGuidance (const G4String &s0)
 
CommandSetUnit (const G4String &, UnitSpec=UnitDefault)
 
CommandSetUnitCategory (const G4String &u)
 
CommandSetDefaultUnit (const G4String &u)
 
CommandSetParameterName (const G4String &, G4bool, G4bool=false)
 
CommandSetDefaultValue (const G4String &)
 
CommandSetCandidates (const G4String &)
 
CommandSetToBeBroadcasted (G4bool s0)
 
CommandSetToBeFlushed (G4bool s0)
 
CommandSetWorkerThreadOnly (G4bool s0)
 

Public Attributes

G4UIcommandcommand = nullptr
 
const std::type_info * type = nullptr
 

Detailed Description

Definition at line 68 of file G4GenericMessenger.hh.

Member Enumeration Documentation

◆ UnitSpec

Enumerator
UnitCategory 
UnitDefault 

Definition at line 70 of file G4GenericMessenger.hh.

Constructor & Destructor Documentation

◆ Command() [1/2]

G4GenericMessenger::Command::Command ( G4UIcommand cmd,
const std::type_info &  ti 
)
inline

Definition at line 75 of file G4GenericMessenger.hh.

76 : command(cmd)
77 , type(&ti)
78 {}
const std::type_info * type

◆ Command() [2/2]

G4GenericMessenger::Command::Command ( )
inline

Definition at line 79 of file G4GenericMessenger.hh.

80 {}

Member Function Documentation

◆ SetCandidates()

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

Definition at line 325 of file G4GenericMessenger.cc.

327{
328 G4UIparameter* theParam = command->GetParameter(0);
329 theParam->SetParameterCandidates(candList);
330 return *this;
331}
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:139
void SetParameterCandidates(const char *theString)

◆ SetDefaultUnit()

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

Definition at line 126 of file G4GenericMessenger.hh.

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

◆ SetDefaultValue()

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

Definition at line 333 of file G4GenericMessenger.cc.

335{
336 G4UIparameter* theParam = command->GetParameter(0);
337 theParam->SetDefaultValue(defVal);
338 return *this;
339}
void SetDefaultValue(const char *theDefaultValue)

◆ SetGuidance()

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

Definition at line 116 of file G4GenericMessenger.hh.

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

◆ SetParameterName()

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

Definition at line 315 of file G4GenericMessenger.cc.

317{
318 G4UIparameter* theParam = command->GetParameter(0);
319 theParam->SetParameterName(name);
320 theParam->SetOmittable(omittable);
321 theParam->SetCurrentAsDefault(currentAsDefault);
322 return *this;
323}
void SetParameterName(const char *pName)
void SetOmittable(G4bool om)
void SetCurrentAsDefault(G4bool val)

◆ SetRange()

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

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

◆ SetStates() [1/5]

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

Definition at line 82 of file G4GenericMessenger.hh.

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

◆ SetStates() [2/5]

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

Definition at line 87 of file G4GenericMessenger.hh.

88 {
90 return *this;
91 }

◆ SetStates() [3/5]

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

Definition at line 92 of file G4GenericMessenger.hh.

94 {
95 command->AvailableForStates(s0, s1, s2);
96 return *this;
97 }

◆ SetStates() [4/5]

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

Definition at line 98 of file G4GenericMessenger.hh.

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

◆ SetStates() [5/5]

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

Definition at line 104 of file G4GenericMessenger.hh.

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

◆ SetToBeBroadcasted()

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

Definition at line 133 of file G4GenericMessenger.hh.

134 {
136 return *this;
137 }
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172

◆ SetToBeFlushed()

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

Definition at line 138 of file G4GenericMessenger.hh.

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

◆ SetUnit()

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

Definition at line 236 of file G4GenericMessenger.cc.

238{
239 // Change the type of command (unfortunatelly this is done a posteriory)
240 // We need to delete the old command before creating the new one and therefore
241 // we need to recover the information before the deletetion
243 {
244 G4String cmdpath = command->GetCommandPath();
246 ed << "G4GenericMessenger::Command::SetUnit() is thread-unsafe and should "
247 "not be used\n"
248 << "in multi-threaded mode. For your command <" << cmdpath << ">, use\n"
249 << " DeclarePropertyWithUnit(const G4String& name, const G4String& "
250 "defaultUnit,\n"
251 << " const G4AnyType& variable, const G4String& "
252 "doc)\n"
253 << "or\n"
254 << " DeclareMethodWithUnit(const G4String& name, const G4String& "
255 "defaultUnit,\n"
256 << " const G4AnyType& variable, const G4String& "
257 "doc)\n"
258 << "to define a command with a unit <" << unit << ">.";
259 if(spec != UnitDefault)
260 {
261 ed << "\nPlease use a default unit instead of unit category.";
262 }
263 G4Exception("G4GenericMessenger::Command::SetUnit()", "Intercom70001",
264 FatalException, ed);
265 return *this;
266 }
267
268 G4String cmdpath = command->GetCommandPath();
269 G4UImessenger* messenger = command->GetMessenger();
270 G4String range = command->GetRange();
271 std::vector<G4String> guidance;
273 G4bool par_omitable = command->GetParameter(0)->IsOmittable();
274 for(std::size_t i = 0; i < command->GetGuidanceEntries(); ++i)
275 guidance.push_back(command->GetGuidanceLine(i));
276 // Before deleting the command we need to add a fake one to avoid deleting
277 // the directory entry and with its guidance
278 G4UIcommand tmp((cmdpath + "_tmp").c_str(), messenger);
279 delete command;
280
281 if(*type == typeid(float) || *type == typeid(double))
282 {
284 new G4UIcmdWithADoubleAndUnit(cmdpath, messenger);
285 if(spec == UnitDefault)
286 cmd_t->SetDefaultUnit(unit);
287 else if(spec == UnitCategory)
288 cmd_t->SetUnitCategory(unit);
289 cmd_t->SetParameterName(par_name, par_omitable);
290 command = cmd_t;
291 }
292 else if(*type == typeid(G4ThreeVector))
293 {
295 new G4UIcmdWith3VectorAndUnit(cmdpath, messenger);
296 if(spec == UnitDefault)
297 cmd_t->SetDefaultUnit(unit);
298 else if(spec == UnitCategory)
299 cmd_t->SetUnitCategory(unit);
300 command = cmd_t;
301 }
302 else
303 {
304 G4cerr << "Only parameters of type <double> or <float> can be associated "
305 "with units"
306 << G4endl;
307 return *this;
308 }
309 for(std::size_t i = 0; i < guidance.size(); ++i)
310 command->SetGuidance(guidance[i]);
311 command->SetRange(range);
312 return *this;
313}
@ 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
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
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

Referenced by SetDefaultUnit(), and SetUnitCategory().

◆ SetUnitCategory()

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

Definition at line 122 of file G4GenericMessenger.hh.

123 {
124 return SetUnit(u, UnitCategory);
125 }

◆ SetWorkerThreadOnly()

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

Definition at line 143 of file G4GenericMessenger.hh.

144 {
146 return *this;
147 }
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:176

Member Data Documentation

◆ command

G4UIcommand* G4GenericMessenger::Command::command = nullptr

◆ type

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

Definition at line 150 of file G4GenericMessenger.hh.

Referenced by SetUnit().


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