#include <G4GenericMessenger.hh>
|
| G4GenericMessenger (void *obj, const G4String &dir="", const G4String &doc="") |
|
| ~G4GenericMessenger () override |
|
G4String | GetCurrentValue (G4UIcommand *command) override |
|
void | SetNewValue (G4UIcommand *command, G4String newValue) override |
|
Command & | DeclareProperty (const G4String &name, const G4AnyType &variable, const G4String &doc="") |
|
Command & | DeclarePropertyWithUnit (const G4String &name, const G4String &defaultUnit, const G4AnyType &variable, const G4String &doc="") |
|
Command & | DeclareMethod (const G4String &name, const G4AnyMethod &fun, const G4String &doc="") |
|
Command & | DeclareMethodWithUnit (const G4String &name, const G4String &defaultUnit, const G4AnyMethod &fun, const G4String &doc="") |
|
void | SetDirectory (const G4String &dir) |
|
void | SetGuidance (const G4String &s) |
|
void | Sort (G4bool val=true) |
|
| G4UImessenger ()=default |
|
| G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true) |
|
virtual | ~G4UImessenger () |
|
G4bool | CommandsShouldBeInMaster () const |
|
Definition at line 48 of file G4GenericMessenger.hh.
◆ G4GenericMessenger()
G4GenericMessenger::G4GenericMessenger |
( |
void * | obj, |
|
|
const G4String & | dir = "", |
|
|
const G4String & | doc = "" ) |
Definition at line 69 of file G4GenericMessenger.cc.
70 : directory(dir), object(obj)
71{
74}
void SetGuidance(const char *aGuidance)
◆ ~G4GenericMessenger()
G4GenericMessenger::~G4GenericMessenger |
( |
| ) |
|
|
override |
Definition at line 76 of file G4GenericMessenger.cc.
77{
78 delete dircmd;
79 for (const auto& propertie : properties) {
80 delete propertie.second.command;
81 }
82 for (const auto& method : methods) {
83 delete method.second.command;
84 }
85}
◆ DeclareMethod()
Definition at line 155 of file G4GenericMessenger.cc.
156{
158 auto* cmd =
new G4UIcommand(fullpath.c_str(),
this);
159 if (!doc.empty()) {
160 cmd->SetGuidance(doc);
161 }
162 for (std::size_t i = 0; i < fun.
NArg(); ++i) {
164 char ptype = 's';
166 if (tInfo == typeid(int) || tInfo == typeid(long) || tInfo == typeid(unsigned int)
167 || tInfo == typeid(unsigned long))
168 {
169 ptype = 'i';
170 }
171 else if (tInfo == typeid(float) || tInfo == typeid(double)) {
172 ptype = 'd';
173 }
174 else if (tInfo == typeid(bool)) {
175 ptype = 'b';
176 }
177 else if (tInfo ==
typeid(
G4String)) {
178 ptype = 's';
179 }
180 else {
181 ptype = 's';
182 }
184 }
185 return methods[
name] = Method(fun,
object, cmd);
186}
const std::type_info & ArgType(size_t n=0) const
const char * name(G4int ptype)
◆ DeclareMethodWithUnit()
Definition at line 188 of file G4GenericMessenger.cc.
192{
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 << ">.";
202 }
206 if (!doc.empty()) {
208 }
209 return methods[
name] = Method(fun,
object, cmd);
210}
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
◆ DeclareProperty()
Definition at line 88 of file G4GenericMessenger.cc.
89{
95 ->SetParameterName("valueX", "valueY", "valueZ", false, false);
96 }
97 else {
99 char ptype;
100 if (var.TypeInfo() == typeid(int) || var.TypeInfo() == typeid(long)
101 || var.TypeInfo() == typeid(unsigned int) || var.TypeInfo() == typeid(unsigned long))
102 {
103 ptype = 'i';
104 }
105 else if (var.TypeInfo() == typeid(float) || var.TypeInfo() == typeid(double)) {
106 ptype = 'd';
107 }
108 else if (var.TypeInfo() == typeid(bool)) {
109 ptype = 'b';
110 }
111 else if (var.TypeInfo() ==
typeid(
G4String)) {
112 ptype = 's';
113 }
114 else {
115 ptype = 's';
116 }
118 }
119 if (!doc.empty()) {
121 }
122 return properties[
name] = Property(var, cmd);
123}
void SetParameter(G4UIparameter *const newParameter)
Referenced by DeclarePropertyWithUnit(), and G4SteppingVerboseWithUnits::SetManager().
◆ DeclarePropertyWithUnit()
Definition at line 126 of file G4GenericMessenger.cc.
128{
129 if (var.TypeInfo() != typeid(float) && var.TypeInfo() != typeid(double)
131 {
133 }
136 if (var.TypeInfo() == typeid(float) || var.TypeInfo() == typeid(double)) {
140 }
141 else {
144 ->SetParameterName("valueX", "valueY", "valueZ", false, false);
146 }
147
148 if (!doc.empty()) {
150 }
151 return properties[
name] = Property(var, cmd);
152}
Command & DeclareProperty(const G4String &name, const G4AnyType &variable, const G4String &doc="")
◆ GetCurrentValue()
Reimplemented from G4UImessenger.
Definition at line 212 of file G4GenericMessenger.cc.
213{
214 if (properties.find(command->
GetCommandName()) != properties.cend()) {
216 return p.variable.ToString();
217 }
219 G4cout <<
" GetCurrentValue() is not available for a command defined by "
220 "G4GenericMessenger::DeclareMethod()."
223 }
224
226}
G4GLOB_DLL std::ostream G4cout
const G4String & GetCommandName() const
◆ SetDirectory()
void G4GenericMessenger::SetDirectory |
( |
const G4String & | dir | ) |
|
|
inline |
◆ SetGuidance()
void G4GenericMessenger::SetGuidance |
( |
const G4String & | s | ) |
|
◆ SetNewValue()
Reimplemented from G4UImessenger.
Definition at line 228 of file G4GenericMessenger.cc.
229{
230
233 }
236 }
239 newValue = "1";
240 } else {
241 newValue = "0";
242 }
243 }
244
245 if (properties.find(command->
GetCommandName()) != properties.cend()) {
247 p.variable.FromString(newValue);
248 }
249 else if (methods.find(command->
GetCommandName()) != methods.cend()) {
251 if (m.method.NArg() == 0) {
252 m.method.operator()(m.object);
253 }
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)) {
261 aToken = "1";
262 } else {
263 aToken = "0";
264 }
265 }
266 paraValue += aToken + " ";
267 }
268 m.method.operator()(m.object, paraValue);
269 }
270 else {
272 }
273 }
274}
static G4String ConvertToString(G4bool boolVal)
static G4double ConvertToDimensionedDouble(const char *st)
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
◆ Sort()
void G4GenericMessenger::Sort |
( |
G4bool | val = true | ) |
|
|
inline |
Definition at line 173 of file G4GenericMessenger.hh.
174 {
175 if (dircmd != nullptr) {
177 }
178 }
void Sort(G4bool val=true)
The documentation for this class was generated from the following files: