Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4GenericMessenger << 27 // 26 // 28 // Class description: << 27 // $Id: G4UImessenger.hh,v 1.9 2006-06-29 19:08:19 gunter Exp $ 29 // 28 // 30 // A generic messenger class. << 31 29 32 // Author: P.Mato, CERN - 27 September 2012 << 30 #ifndef G4GenericMessenger_h 33 // ------------------------------------------- << 31 #define G4GenericMessenger_h 1 34 #ifndef G4GenericMessenger_hh << 35 #define G4GenericMessenger_hh 1 << 36 32 37 #include "G4AnyMethod.hh" << 33 #include "G4UImessenger.hh" >> 34 #include "G4UIcommand.hh" 38 #include "G4AnyType.hh" 35 #include "G4AnyType.hh" >> 36 #include "G4AnyMethod.hh" 39 #include "G4ApplicationState.hh" 37 #include "G4ApplicationState.hh" 40 #include "G4UIcommand.hh" << 41 #include "G4UImessenger.hh" << 42 38 43 #include <map> 39 #include <map> 44 #include <vector> 40 #include <vector> 45 41 46 class G4UIdirectory; 42 class G4UIdirectory; 47 43 >> 44 /// This class is generic messenger. >> 45 48 class G4GenericMessenger : public G4UImessenge 46 class G4GenericMessenger : public G4UImessenger 49 { 47 { 50 public: << 48 public: 51 // Contructor << 49 /// Contructor 52 G4GenericMessenger(void* obj, const G4Stri << 50 G4GenericMessenger(void* obj, const G4String& dir = "", const G4String& doc = ""); 53 << 51 /// Destructor 54 // Destructor << 52 virtual ~G4GenericMessenger(); 55 ~G4GenericMessenger() override; << 53 /// The concrete, but generic implementation of this method. 56 << 54 virtual G4String GetCurrentValue(G4UIcommand* command); 57 // The concrete, but generic implementatio << 55 /// The concrete, generic implementation of this method converts the string "newValue" to action. 58 G4String GetCurrentValue(G4UIcommand* comm << 56 virtual void SetNewValue(G4UIcommand* command, G4String newValue); 59 << 57 60 // The concrete, generic implementation o << 58 public: 61 // the string "newValue" to action. << 59 struct Command { 62 void SetNewValue(G4UIcommand* command, G4S << 60 enum UnitSpec {UnitCategory, UnitDefault}; 63 << 61 Command(G4UIcommand* cmd, const std::type_info& ti) : command(cmd), type(&ti) {} 64 public: << 62 Command() : command(0), type(0) {} 65 struct Command << 63 // Command& operator =(const Command& rhs) { command = rhs.command; type = rhs.type; } 66 { << 64 Command& SetStates(G4ApplicationState s0) {command->AvailableForStates(s0); return *this;} 67 enum UnitSpec << 65 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1) {command->AvailableForStates(s0, s1); return *this;} 68 { << 66 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2){command->AvailableForStates(s0,s1,s2); return *this;} 69 UnitCategory, << 67 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3) {command->AvailableForStates(s0,s1,s2,s3); return *this;} 70 UnitDefault << 68 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3, G4ApplicationState s4) {command->AvailableForStates(s0,s1,s2,s3,s4); return *this;} 71 }; << 69 Command& SetRange(const G4String& range) {command->SetRange(range.c_str()); return *this;} 72 Command(G4UIcommand* cmd, const std::t << 70 Command& SetGuidance(const G4String& s) { command->SetGuidance(s); return *this; } 73 Command() = default; << 71 Command& SetUnit(const G4String&, UnitSpec = UnitDefault); 74 << 72 Command& SetUnitCategory(const G4String& u) {return SetUnit(u, UnitCategory);} 75 Command& SetStates(G4ApplicationState << 73 Command& SetDefaultUnit(const G4String& u) {return SetUnit(u, UnitDefault);} 76 { << 74 Command& SetParameterName(const G4String&, G4bool, G4bool =false); 77 command->AvailableForStates(s0); << 75 Command& SetDefaultValue(const G4String&); 78 return *this; << 76 Command& SetCandidates(const G4String&); 79 } << 77 80 Command& SetStates(G4ApplicationState << 78 G4UIcommand* command; 81 { << 79 const std::type_info* type; 82 command->AvailableForStates(s0, s1); << 80 }; 83 return *this; << 81 struct Property : public Command { 84 } << 82 Property(const G4AnyType& var, G4UIcommand* cmd) : Command(cmd, var.TypeInfo()) , variable(var) {} 85 Command& SetStates(G4ApplicationState << 83 Property() {} 86 { << 84 G4AnyType variable; 87 command->AvailableForStates(s0, s1, << 85 }; 88 return *this; << 86 struct Method : public Command { 89 } << 87 Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd) : Command(cmd, fun.ArgType()), method(fun), object(obj) {} 90 Command& SetStates(G4ApplicationState << 88 Method() : object(0) {} 91 G4ApplicationState << 89 G4AnyMethod method; 92 { << 90 void* object; 93 command->AvailableForStates(s0, s1, << 91 }; 94 return *this; << 92 95 } << 93 ///Declare Methods 96 Command& SetStates(G4ApplicationState << 94 //Command& DeclarePropertyWithUnit(const G4String& name, const G4Any& variable, const G4String& unit, const G4String& doc = ""); 97 G4ApplicationState << 95 Command& DeclareProperty(const G4String& name, const G4AnyType& variable, const G4String& doc = ""); 98 { << 96 Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun, const G4String& doc = ""); 99 command->AvailableForStates(s0, s1, << 97 //Command& DeclareMethodWithUnit(const G4String& name, const G4AnyFunc& fun, const G4String& unit, const G4String& doc = ""); 100 return *this; << 98 void SetDirectory(const G4String& dir) {directory = dir;} 101 } << 99 void SetGuidance(const G4String& s); 102 Command& SetRange(const G4String& rang << 100 103 { << 101 private: 104 command->SetRange(range.c_str()); << 102 std::map<G4String, Property> properties; 105 return *this; << 103 std::map<G4String, Method> methods; 106 } << 104 G4UIdirectory* dircmd; 107 Command& SetGuidance(const G4String& s << 105 G4String directory; 108 { << 106 void* object; 109 command->SetGuidance(s0); << 110 return *this; << 111 } << 112 Command& SetUnit(const G4String&, Unit << 113 Command& SetUnitCategory(const G4Strin << 114 Command& SetDefaultUnit(const G4String << 115 Command& SetParameterName(const G4Stri << 116 Command& SetParameterName(G4int pIdx, << 117 Command& SetParameterName(const G4Stri << 118 G4bool = fal << 119 Command& SetDefaultValue(const G4Strin << 120 Command& SetDefaultValue(G4int pIdx, c << 121 Command& SetCandidates(const G4String& << 122 Command& SetCandidates(G4int pIdx, con << 123 Command& SetToBeBroadcasted(G4bool s0) << 124 { << 125 command->SetToBeBroadcasted(s0); << 126 return *this; << 127 } << 128 Command& SetToBeFlushed(G4bool s0) << 129 { << 130 command->SetToBeFlushed(s0); << 131 return *this; << 132 } << 133 Command& SetWorkerThreadOnly(G4bool s0 << 134 { << 135 command->SetWorkerThreadOnly(s0); << 136 return *this; << 137 } << 138 << 139 G4UIcommand* command = nullptr; << 140 const std::type_info* type = nullptr; << 141 }; << 142 << 143 struct Property : public Command << 144 { << 145 Property(const G4AnyType& var, G4UIcom << 146 : Command(cmd, var.TypeInfo()), vari << 147 {} << 148 Property() = default; << 149 G4AnyType variable; << 150 }; << 151 << 152 struct Method : public Command << 153 { << 154 Method(const G4AnyMethod& fun, void* o << 155 : Command(cmd, fun.ArgType()), metho << 156 {} << 157 Method() = default; << 158 G4AnyMethod method; << 159 void* object = nullptr; << 160 }; << 161 << 162 // Declare Methods << 163 << 164 Command& DeclareProperty(const G4String& n << 165 const G4String& d << 166 Command& DeclarePropertyWithUnit(const G4S << 167 const G4A << 168 Command& DeclareMethod(const G4String& nam << 169 Command& DeclareMethodWithUnit(const G4Str << 170 const G4Any << 171 void SetDirectory(const G4String& dir) { d << 172 void SetGuidance(const G4String& s); << 173 void Sort(G4bool val = true) << 174 { << 175 if (dircmd != nullptr) { << 176 dircmd->Sort(val); << 177 } << 178 } << 179 << 180 private: << 181 std::map<G4String, Property> properties; << 182 std::map<G4String, Method> methods; << 183 G4UIdirectory* dircmd = nullptr; << 184 G4String directory; << 185 void* object = nullptr; << 186 }; 107 }; 187 108 >> 109 188 #endif 110 #endif >> 111 189 112