Geant4 10.7.0
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 "G4UImessenger.hh"
38#include "G4UIcommand.hh"
39#include "G4AnyType.hh"
40#include "G4AnyMethod.hh"
41#include "G4ApplicationState.hh"
42
43#include <map>
44#include <vector>
45
46class G4UIdirectory;
47
49{
50 public:
51
52 G4GenericMessenger(void* obj, const G4String& dir = "",
53 const G4String& doc = "");
54 // Contructor
55
56 virtual ~G4GenericMessenger();
57 // Destructor
58
59 virtual G4String GetCurrentValue(G4UIcommand* command);
60 // The concrete, but generic implementation of this method.
61
62 virtual void SetNewValue(G4UIcommand* command, G4String newValue);
63 // The concrete, generic implementation of this method converts
64 // the string "newValue" to action.
65
66 public:
67
68 struct Command
69 {
71 {
74 };
75 Command(G4UIcommand* cmd, const std::type_info& ti)
76 : command(cmd)
77 , type(&ti)
78 {}
80 {}
81
83 {
85 return *this;
86 }
88 {
90 return *this;
91 }
94 {
95 command->AvailableForStates(s0, s1, s2);
96 return *this;
97 }
100 {
101 command->AvailableForStates(s0, s1, s2, s3);
102 return *this;
103 }
107 {
108 command->AvailableForStates(s0, s1, s2, s3, s4);
109 return *this;
110 }
111 Command& SetRange(const G4String& range)
112 {
113 command->SetRange(range.c_str());
114 return *this;
115 }
117 {
118 command->SetGuidance(s0);
119 return *this;
120 }
123 {
124 return SetUnit(u, UnitCategory);
125 }
127 {
128 return SetUnit(u, UnitDefault);
129 }
130 Command& SetParameterName(const G4String&, G4bool, G4bool = false);
134 {
136 return *this;
137 }
139 {
141 return *this;
142 }
144 {
146 return *this;
147 }
148
150 const std::type_info* type = nullptr;
151 };
152
153 struct Property : public Command
154 {
156 : Command(cmd, var.TypeInfo())
157 , variable(var)
158 {}
161 };
162
163 struct Method : public Command
164 {
165 Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd)
166 : Command(cmd, fun.ArgType())
167 , method(fun)
168 , object(obj)
169 {}
171 {}
173 void* object = nullptr;
174 };
175
176 // Declare Methods
177
178 Command& DeclareProperty(const G4String& name, const G4AnyType& variable,
179 const G4String& doc = "");
181 const G4String& defaultUnit,
182 const G4AnyType& variable,
183 const G4String& doc = "");
184 Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun,
185 const G4String& doc = "");
187 const G4String& defaultUnit,
188 const G4AnyMethod& fun,
189 const G4String& doc = "");
190 void SetDirectory(const G4String& dir) { directory = dir; }
191 void SetGuidance(const G4String& s);
192
193 private:
194
195 std::map<G4String, Property> properties;
196 std::map<G4String, Method> methods;
197 G4UIdirectory* dircmd = nullptr;
198 G4String directory;
199 void* object = nullptr;
200};
201
202#endif
G4ApplicationState
bool G4bool
Definition: G4Types.hh:86
Command & DeclareMethod(const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
void SetGuidance(const G4String &s)
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
Command & DeclareProperty(const G4String &name, const G4AnyType &variable, const G4String &doc="")
virtual G4String GetCurrentValue(G4UIcommand *command)
Command & DeclareMethodWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyMethod &fun, const G4String &doc="")
void SetDirectory(const G4String &dir)
Command & DeclarePropertyWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyType &variable, const G4String &doc="")
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:174
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:176
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:273
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 &)
const std::type_info * type
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)