Geant4  10.00.p03
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 //
27 // $Id: G4UImessenger.hh,v 1.9 2006-06-29 19:08:19 gunter Exp $
28 //
29 
30 #ifndef G4GenericMessenger_h
31 #define G4GenericMessenger_h 1
32 
33 #include "G4UImessenger.hh"
34 #include "G4UIcommand.hh"
35 #include "G4AnyType.hh"
36 #include "G4AnyMethod.hh"
37 #include "G4ApplicationState.hh"
38 
39 #include <map>
40 #include <vector>
41 
42 class G4UIdirectory;
43 
45 
47 {
48 public:
50  G4GenericMessenger(void* obj, const G4String& dir = "", const G4String& doc = "");
52  virtual ~G4GenericMessenger();
54  virtual G4String GetCurrentValue(G4UIcommand* command);
56  virtual void SetNewValue(G4UIcommand* command, G4String newValue);
57 
58 public:
59  struct Command {
61  Command(G4UIcommand* cmd, const std::type_info& ti) : command(cmd), type(&ti) {}
62  Command() : command(0), type(0) {}
63  // Command& operator =(const Command& rhs) { command = rhs.command; type = rhs.type; }
64  Command& SetStates(G4ApplicationState s0) {command->AvailableForStates(s0); return *this;}
69  Command& SetRange(const G4String& range) {command->SetRange(range.c_str()); return *this;}
70  Command& SetGuidance(const G4String& s) { command->SetGuidance(s); return *this; }
74  Command& SetParameterName(const G4String&, G4bool, G4bool =false);
77  Command& SetToBeBroadcasted(G4bool s) { command->SetToBeBroadcasted(s); return *this; }
78  Command& SetToBeFlushed(G4bool s) { command->SetToBeFlushed(s); return *this; }
79  Command& SetWorkerThreadOnly(G4bool s) { command->SetWorkerThreadOnly(s); return *this; }
80 
82  const std::type_info* type;
83  };
84  struct Property : public Command {
85  Property(const G4AnyType& var, G4UIcommand* cmd) : Command(cmd, var.TypeInfo()) , variable(var) {}
86  Property() {}
88  };
89  struct Method : public Command {
90  Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd) : Command(cmd, fun.ArgType()), method(fun), object(obj) {}
91  Method() : object(0) {}
93  void* object;
94  };
95 
97  Command& DeclareProperty(const G4String& name, const G4AnyType& variable, const G4String& doc = "");
99  (const G4String& name, const G4String& defaultUnit, const G4AnyType& variable, const G4String& doc = "");
100  Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun, const G4String& doc = "");
102  (const G4String& name, const G4String& defaultUnit, const G4AnyMethod& fun, const G4String& doc = "");
103  void SetDirectory(const G4String& dir) {directory = dir;}
104  void SetGuidance(const G4String& s);
105 
106 private:
107  std::map<G4String, Property> properties;
108  std::map<G4String, Method> methods;
111  void* object;
112 };
113 
114 
115 #endif
116 
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1)
virtual G4String GetCurrentValue(G4UIcommand *command)
The concrete, but generic implementation of this method.
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3)
Command(G4UIcommand *cmd, const std::type_info &ti)
This class is generic messenger.
const std::type_info * type
std::map< G4String, Method > methods
Command & SetDefaultUnit(const G4String &u)
Command & DeclareProperty(const G4String &name, const G4AnyType &variable, const G4String &doc="")
Declare Methods.
G4String name
Definition: TRTMaterials.hh:40
This class represents any object method.
Definition: G4AnyMethod.hh:67
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:184
G4UIdirectory * dircmd
Command & DeclareMethod(const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
Command & SetToBeFlushed(G4bool s)
Command & DeclareMethodWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyMethod &fun, const G4String &doc="")
Command & SetUnitCategory(const G4String &u)
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
The concrete, generic implementation of this method converts the string "newValue" to action...
static const double s
Definition: G4SIunits.hh:150
Command & SetDefaultValue(const G4String &)
static int variable(const string &name, double &result, const dic_type &dictionary)
Definition: Evaluator.cc:71
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4)
G4GenericMessenger(void *obj, const G4String &dir="", const G4String &doc="")
Contructor.
bool G4bool
Definition: G4Types.hh:79
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
virtual ~G4GenericMessenger()
Destructor.
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
std::map< G4String, Property > properties
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:225
Command & SetStates(G4ApplicationState s0)
void SetGuidance(const G4String &s)
Command & SetRange(const G4String &range)
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:192
Command & SetToBeBroadcasted(G4bool s)
This class represents any data type.
Definition: G4AnyType.hh:63
Command & SetCandidates(const G4String &)
Method(const G4AnyMethod &fun, void *obj, G4UIcommand *cmd)
Command & SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2)
Command & SetWorkerThreadOnly(G4bool s)
void SetDirectory(const G4String &dir)
Command & SetParameterName(const G4String &, G4bool, G4bool=false)
Command & DeclarePropertyWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyType &variable, const G4String &doc="")
Command & SetGuidance(const G4String &s)
G4ApplicationState
void SetToBeFlushed(G4bool val)
Definition: G4UIcommand.hh:188
Property(const G4AnyType &var, G4UIcommand *cmd)
Command & SetUnit(const G4String &, UnitSpec=UnitDefault)