Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GenericMessenger.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4GenericMessenger
27//
28// Class description:
29//
30// A generic messenger class.
31
32// Author: P.Mato, CERN - 27 September 2012
33// --------------------------------------------------------------------
34#ifndef G4GenericMessenger_hh
35#define G4GenericMessenger_hh 1
36
37#include "G4AnyMethod.hh"
38#include "G4AnyType.hh"
39#include "G4ApplicationState.hh"
40#include "G4UIcommand.hh"
41#include "G4UImessenger.hh"
42
43#include <map>
44#include <vector>
45
46class G4UIdirectory;
47
49{
50 public:
51 // Contructor
52 G4GenericMessenger(void* obj, const G4String& dir = "", const G4String& doc = "");
53
54 // Destructor
55 ~G4GenericMessenger() override;
56
57 // The concrete, but generic implementation of this method.
58 G4String GetCurrentValue(G4UIcommand* command) override;
59
60 // The concrete, generic implementation of this method converts
61 // the string "newValue" to action.
62 void SetNewValue(G4UIcommand* command, G4String newValue) override;
63
64 public:
65 struct Command
66 {
72 Command(G4UIcommand* cmd, const std::type_info& ti) : command(cmd), type(&ti) {}
73 Command() = default;
74
76 {
78 return *this;
79 }
81 {
83 return *this;
84 }
102 Command& SetRange(const G4String& range)
103 {
104 command->SetRange(range.c_str());
105 return *this;
106 }
108 {
109 command->SetGuidance(s0);
110 return *this;
111 }
115 Command& SetParameterName(const G4String&, G4bool, G4bool = false);
116 Command& SetParameterName(G4int pIdx, const G4String&, G4bool, G4bool = false);
117 Command& SetParameterName(const G4String&, const G4String&, const G4String&, G4bool,
118 G4bool = false);
120 Command& SetDefaultValue(G4int pIdx, const G4String&);
122 Command& SetCandidates(G4int pIdx, const G4String&);
124 {
126 return *this;
127 }
129 {
131 return *this;
132 }
134 {
136 return *this;
137 }
138
140 const std::type_info* type = nullptr;
141 };
142
143 struct Property : public Command
144 {
146 : Command(cmd, var.TypeInfo()), variable(var)
147 {}
148 Property() = default;
150 };
151
152 struct Method : public Command
153 {
154 Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd)
155 : Command(cmd, fun.ArgType()), method(fun), object(obj)
156 {}
157 Method() = default;
159 void* object = nullptr;
160 };
161
162 // Declare Methods
163
164 Command& DeclareProperty(const G4String& name, const G4AnyType& variable,
165 const G4String& doc = "");
166 Command& DeclarePropertyWithUnit(const G4String& name, const G4String& defaultUnit,
167 const G4AnyType& variable, const G4String& doc = "");
168 Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun, const G4String& doc = "");
169 Command& DeclareMethodWithUnit(const G4String& name, const G4String& defaultUnit,
170 const G4AnyMethod& fun, const G4String& doc = "");
171 void SetDirectory(const G4String& dir) { directory = dir; }
172 void SetGuidance(const G4String& s);
173 void Sort(G4bool val = true)
174 {
175 if (dircmd != nullptr) {
176 dircmd->Sort(val);
177 }
178 }
179
180 private:
181 std::map<G4String, Property> properties;
182 std::map<G4String, Method> methods;
183 G4UIdirectory* dircmd = nullptr;
184 G4String directory;
185 void* object = nullptr;
186};
187
188#endif
G4ApplicationState
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
Command & DeclareMethod(const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
void SetGuidance(const G4String &s)
void Sort(G4bool val=true)
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="")
void SetDirectory(const G4String &dir)
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="")
void SetToBeBroadcasted(G4bool val)
void SetGuidance(const char *aGuidance)
void SetToBeFlushed(G4bool val)
void SetRange(const char *rs)
void SetWorkerThreadOnly(G4bool val=true)
void AvailableForStates(G4ApplicationState s1)
void Sort(G4bool val=true)
Command & SetUnitCategory(const G4String &u)
Command & SetParameterName(const G4String &, G4bool, G4bool=false)
Command & SetStates(G4ApplicationState s0)
Command & SetDefaultUnit(const G4String &u)
Command & SetRange(const G4String &range)
Command & SetToBeFlushed(G4bool s0)
Command & SetWorkerThreadOnly(G4bool s0)
Command & SetCandidates(const G4String &)
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2)
Command & SetGuidance(const G4String &s0)
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4)
Command & SetDefaultValue(const G4String &)
Command(G4UIcommand *cmd, const std::type_info &ti)
Command & SetToBeBroadcasted(G4bool s0)
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3)
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1)
Command & SetUnit(const G4String &, UnitSpec=UnitDefault)
Method(const G4AnyMethod &fun, void *obj, G4UIcommand *cmd)
Property(const G4AnyType &var, G4UIcommand *cmd)