Geant4  10.00.p01
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 G4GenericMmessenger_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 
79  const std::type_info* type;
80  };
81  struct Property : public Command {
82  Property(const G4AnyType& var, G4UIcommand* cmd) : Command(cmd, var.TypeInfo()) , variable(var) {}
83  Property() {}
85  };
86  struct Method : public Command {
87  Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd) : Command(cmd, fun.ArgType()), method(fun), object(obj) {}
88  Method() : object(0) {}
90  void* object;
91  };
92 
94  Command& DeclareProperty(const G4String& name, const G4AnyType& variable, const G4String& doc = "");
96  (const G4String& name, const G4String& defaultUnit, const G4AnyType& variable, const G4String& doc = "");
97  Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun, const G4String& doc = "");
99  (const G4String& name, const G4String& defaultUnit, const G4AnyMethod& fun, const G4String& doc = "");
100  void SetDirectory(const G4String& dir) {directory = dir;}
101  void SetGuidance(const G4String& s);
102 
103 private:
104  std::map<G4String, Property> properties;
105  std::map<G4String, Method> methods;
108  void* object;
109 };
110 
111 
112 #endif
113 
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
G4UIdirectory * dircmd
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="")
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)
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)
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
Property(const G4AnyType &var, G4UIcommand *cmd)
Command & SetUnit(const G4String &, UnitSpec=UnitDefault)