Geant4-11
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 {
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 {
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);
131 Command& SetParameterName(G4int pIdx, const G4String&, G4bool, G4bool = false);
132 Command& SetParameterName(const G4String&, const G4String&, const G4String&,
133 G4bool, G4bool = false);
135 Command& SetDefaultValue(G4int pIdx, const G4String&);
137 Command& SetCandidates(G4int pIdx, const G4String&);
139 {
141 return *this;
142 }
144 {
146 return *this;
147 }
149 {
151 return *this;
152 }
153
155 const std::type_info* type = nullptr;
156 };
157
158 struct Property : public Command
159 {
161 : Command(cmd, var.TypeInfo())
162 , variable(var)
163 {}
166 };
167
168 struct Method : public Command
169 {
170 Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd)
171 : Command(cmd, fun.ArgType())
172 , method(fun)
173 , object(obj)
174 {}
176 {}
178 void* object = nullptr;
179 };
180
181 // Declare Methods
182
184 const G4String& doc = "");
186 const G4String& defaultUnit,
187 const G4AnyType& variable,
188 const G4String& doc = "");
189 Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun,
190 const G4String& doc = "");
192 const G4String& defaultUnit,
193 const G4AnyMethod& fun,
194 const G4String& doc = "");
195 void SetDirectory(const G4String& dir) { directory = dir; }
196 void SetGuidance(const G4String& s);
197 void Sort(G4bool val = true)
198 { if(dircmd) dircmd->Sort(val); }
199
200 private:
201
202 std::map<G4String, Property> properties;
203 std::map<G4String, Method> methods;
206 void* object = nullptr;
207};
208
209#endif
static int variable(const string &name, double &result, const dic_type &dictionary)
Definition: Evaluator.cc:70
G4ApplicationState
static constexpr double s
Definition: G4SIunits.hh:154
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)
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
void Sort(G4bool val=true)
G4UIdirectory * dircmd
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)
G4GenericMessenger(void *obj, const G4String &dir="", const G4String &doc="")
std::map< G4String, Method > methods
Command & DeclarePropertyWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyType &variable, const G4String &doc="")
std::map< G4String, Property > properties
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:288
void Sort(G4bool val=true)
const char * name(G4int ptype)
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)