ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GenericMessenger.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4GenericMessenger.hh
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 //
28 
29 #ifndef G4GenericMessenger_h
30 #define G4GenericMessenger_h 1
31 
32 #include "G4UImessenger.hh"
33 #include "G4UIcommand.hh"
34 #include "G4AnyType.hh"
35 #include "G4AnyMethod.hh"
36 #include "G4ApplicationState.hh"
37 
38 #include <map>
39 #include <vector>
40 
41 class G4UIdirectory;
42 
44 
46 {
47 public:
49  G4GenericMessenger(void* obj, const G4String& dir = "", const G4String& doc = "");
51  virtual ~G4GenericMessenger();
53  virtual G4String GetCurrentValue(G4UIcommand* command);
55  virtual void SetNewValue(G4UIcommand* command, G4String newValue);
56 
57 public:
58  struct Command {
60  Command(G4UIcommand* cmd, const std::type_info& ti) : command(cmd), type(&ti) {}
61  Command() : command(0), type(0) {}
62  // Command& operator =(const Command& rhs) { command = rhs.command; type = rhs.type; }
63  Command& SetStates(G4ApplicationState s0) {command->AvailableForStates(s0); return *this;}
68  Command& SetRange(const G4String& range) {command->SetRange(range.c_str()); return *this;}
69  Command& SetGuidance(const G4String& s0) { command->SetGuidance(s0); return *this; }
73  Command& SetParameterName(const G4String&, G4bool, G4bool =false);
76  Command& SetToBeBroadcasted(G4bool s0) { command->SetToBeBroadcasted(s0); return *this; }
77  Command& SetToBeFlushed(G4bool s0) { command->SetToBeFlushed(s0); return *this; }
78  Command& SetWorkerThreadOnly(G4bool s0) { command->SetWorkerThreadOnly(s0); return *this; }
79 
81  const std::type_info* type;
82  };
83  struct Property : public Command {
84  Property(const G4AnyType& var, G4UIcommand* cmd) : Command(cmd, var.TypeInfo()) , variable(var) {}
85  Property() {}
87  };
88  struct Method : public Command {
89  Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd) : Command(cmd, fun.ArgType()), method(fun), object(obj) {}
90  Method() : object(0) {}
92  void* object;
93  };
94 
96  Command& DeclareProperty(const G4String& name, const G4AnyType& variable, const G4String& doc = "");
98  (const G4String& name, const G4String& defaultUnit, const G4AnyType& variable, const G4String& doc = "");
99  Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun, const G4String& doc = "");
101  (const G4String& name, const G4String& defaultUnit, const G4AnyMethod& fun, const G4String& doc = "");
103  void SetGuidance(const G4String& s);
104 
105 private:
106  std::map<G4String, Property> properties;
107  std::map<G4String, Method> methods;
110  void* object;
111 };
112 
113 
114 #endif
115