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 26 // G4GenericMessenger 27 // 27 // 28 // Class description: 28 // Class description: 29 // 29 // 30 // A generic messenger class. 30 // A generic messenger class. 31 31 32 // Author: P.Mato, CERN - 27 September 2012 32 // Author: P.Mato, CERN - 27 September 2012 33 // ------------------------------------------- 33 // -------------------------------------------------------------------- 34 #ifndef G4GenericMessenger_hh 34 #ifndef G4GenericMessenger_hh 35 #define G4GenericMessenger_hh 1 35 #define G4GenericMessenger_hh 1 36 36 37 #include "G4AnyMethod.hh" << 37 #include "G4UImessenger.hh" >> 38 #include "G4UIcommand.hh" 38 #include "G4AnyType.hh" 39 #include "G4AnyType.hh" >> 40 #include "G4AnyMethod.hh" 39 #include "G4ApplicationState.hh" 41 #include "G4ApplicationState.hh" 40 #include "G4UIcommand.hh" << 41 #include "G4UImessenger.hh" << 42 42 43 #include <map> 43 #include <map> 44 #include <vector> 44 #include <vector> 45 45 46 class G4UIdirectory; 46 class G4UIdirectory; 47 47 48 class G4GenericMessenger : public G4UImessenge 48 class G4GenericMessenger : public G4UImessenger 49 { 49 { 50 public: 50 public: 51 // Contructor << 52 G4GenericMessenger(void* obj, const G4Stri << 53 51 54 // Destructor << 52 G4GenericMessenger(void* obj, const G4String& dir = "", >> 53 const G4String& doc = ""); >> 54 // Contructor >> 55 55 ~G4GenericMessenger() override; 56 ~G4GenericMessenger() override; >> 57 // Destructor 56 58 57 // The concrete, but generic implementatio << 58 G4String GetCurrentValue(G4UIcommand* comm 59 G4String GetCurrentValue(G4UIcommand* command) override; >> 60 // The concrete, but generic implementation of this method. 59 61 >> 62 void SetNewValue(G4UIcommand* command, G4String newValue) override; 60 // The concrete, generic implementation o 63 // The concrete, generic implementation of this method converts 61 // the string "newValue" to action. 64 // the string "newValue" to action. 62 void SetNewValue(G4UIcommand* command, G4S << 63 65 64 public: << 66 public: >> 67 65 struct Command 68 struct Command 66 { 69 { 67 enum UnitSpec << 70 enum UnitSpec 68 { << 71 { 69 UnitCategory, << 72 UnitCategory, 70 UnitDefault << 73 UnitDefault 71 }; << 74 }; 72 Command(G4UIcommand* cmd, const std::t << 75 Command(G4UIcommand* cmd, const std::type_info& ti) 73 Command() = default; << 76 : command(cmd) 74 << 77 , type(&ti) 75 Command& SetStates(G4ApplicationState << 78 {} 76 { << 79 Command() = default; 77 command->AvailableForStates(s0); << 80 78 return *this; << 81 Command& SetStates(G4ApplicationState s0) 79 } << 82 { 80 Command& SetStates(G4ApplicationState << 83 command->AvailableForStates(s0); 81 { << 84 return *this; 82 command->AvailableForStates(s0, s1); << 85 } 83 return *this; << 86 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1) 84 } << 87 { 85 Command& SetStates(G4ApplicationState << 88 command->AvailableForStates(s0, s1); 86 { << 89 return *this; 87 command->AvailableForStates(s0, s1, << 90 } 88 return *this; << 91 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, 89 } << 92 G4ApplicationState s2) 90 Command& SetStates(G4ApplicationState << 93 { 91 G4ApplicationState << 94 command->AvailableForStates(s0, s1, s2); 92 { << 95 return *this; 93 command->AvailableForStates(s0, s1, << 96 } 94 return *this; << 97 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, 95 } << 98 G4ApplicationState s2, G4ApplicationState s3) 96 Command& SetStates(G4ApplicationState << 99 { 97 G4ApplicationState << 100 command->AvailableForStates(s0, s1, s2, s3); 98 { << 101 return *this; 99 command->AvailableForStates(s0, s1, << 102 } 100 return *this; << 103 Command& SetStates(G4ApplicationState s0, G4ApplicationState s1, 101 } << 104 G4ApplicationState s2, G4ApplicationState s3, 102 Command& SetRange(const G4String& rang << 105 G4ApplicationState s4) 103 { << 106 { 104 command->SetRange(range.c_str()); << 107 command->AvailableForStates(s0, s1, s2, s3, s4); 105 return *this; << 108 return *this; 106 } << 109 } 107 Command& SetGuidance(const G4String& s << 110 Command& SetRange(const G4String& range) 108 { << 111 { 109 command->SetGuidance(s0); << 112 command->SetRange(range.c_str()); 110 return *this; << 113 return *this; 111 } << 114 } 112 Command& SetUnit(const G4String&, Unit << 115 Command& SetGuidance(const G4String& s0) 113 Command& SetUnitCategory(const G4Strin << 116 { 114 Command& SetDefaultUnit(const G4String << 117 command->SetGuidance(s0); 115 Command& SetParameterName(const G4Stri << 118 return *this; 116 Command& SetParameterName(G4int pIdx, << 119 } 117 Command& SetParameterName(const G4Stri << 120 Command& SetUnit(const G4String&, UnitSpec = UnitDefault); 118 G4bool = fal << 121 Command& SetUnitCategory(const G4String& u) 119 Command& SetDefaultValue(const G4Strin << 122 { 120 Command& SetDefaultValue(G4int pIdx, c << 123 return SetUnit(u, UnitCategory); 121 Command& SetCandidates(const G4String& << 124 } 122 Command& SetCandidates(G4int pIdx, con << 125 Command& SetDefaultUnit(const G4String& u) 123 Command& SetToBeBroadcasted(G4bool s0) << 126 { 124 { << 127 return SetUnit(u, UnitDefault); 125 command->SetToBeBroadcasted(s0); << 128 } 126 return *this; << 129 Command& SetParameterName(const G4String&, G4bool, G4bool = false); 127 } << 130 Command& SetParameterName(G4int pIdx, const G4String&, G4bool, G4bool = false); 128 Command& SetToBeFlushed(G4bool s0) << 131 Command& SetParameterName(const G4String&, const G4String&, const G4String&, 129 { << 132 G4bool, G4bool = false); 130 command->SetToBeFlushed(s0); << 133 Command& SetDefaultValue(const G4String&); 131 return *this; << 134 Command& SetDefaultValue(G4int pIdx, const G4String&); 132 } << 135 Command& SetCandidates(const G4String&); 133 Command& SetWorkerThreadOnly(G4bool s0 << 136 Command& SetCandidates(G4int pIdx, const G4String&); 134 { << 137 Command& SetToBeBroadcasted(G4bool s0) 135 command->SetWorkerThreadOnly(s0); << 138 { 136 return *this; << 139 command->SetToBeBroadcasted(s0); 137 } << 140 return *this; >> 141 } >> 142 Command& SetToBeFlushed(G4bool s0) >> 143 { >> 144 command->SetToBeFlushed(s0); >> 145 return *this; >> 146 } >> 147 Command& SetWorkerThreadOnly(G4bool s0) >> 148 { >> 149 command->SetWorkerThreadOnly(s0); >> 150 return *this; >> 151 } 138 152 139 G4UIcommand* command = nullptr; << 153 G4UIcommand* command = nullptr; 140 const std::type_info* type = nullptr; << 154 const std::type_info* type = nullptr; 141 }; 155 }; 142 156 143 struct Property : public Command 157 struct Property : public Command 144 { 158 { 145 Property(const G4AnyType& var, G4UIcom << 159 Property(const G4AnyType& var, G4UIcommand* cmd) 146 : Command(cmd, var.TypeInfo()), vari << 160 : Command(cmd, var.TypeInfo()) 147 {} << 161 , variable(var) 148 Property() = default; << 162 {} 149 G4AnyType variable; << 163 Property() = default; >> 164 G4AnyType variable; 150 }; 165 }; 151 166 152 struct Method : public Command 167 struct Method : public Command 153 { 168 { 154 Method(const G4AnyMethod& fun, void* o << 169 Method(const G4AnyMethod& fun, void* obj, G4UIcommand* cmd) 155 : Command(cmd, fun.ArgType()), metho << 170 : Command(cmd, fun.ArgType()) 156 {} << 171 , method(fun) 157 Method() = default; << 172 , object(obj) 158 G4AnyMethod method; << 173 {} 159 void* object = nullptr; << 174 Method() = default; >> 175 G4AnyMethod method; >> 176 void* object = nullptr; 160 }; 177 }; 161 178 162 // Declare Methods 179 // Declare Methods 163 180 164 Command& DeclareProperty(const G4String& n 181 Command& DeclareProperty(const G4String& name, const G4AnyType& variable, 165 const G4String& d 182 const G4String& doc = ""); 166 Command& DeclarePropertyWithUnit(const G4S << 183 Command& DeclarePropertyWithUnit(const G4String& name, 167 const G4A << 184 const G4String& defaultUnit, 168 Command& DeclareMethod(const G4String& nam << 185 const G4AnyType& variable, 169 Command& DeclareMethodWithUnit(const G4Str << 186 const G4String& doc = ""); 170 const G4Any << 187 Command& DeclareMethod(const G4String& name, const G4AnyMethod& fun, >> 188 const G4String& doc = ""); >> 189 Command& DeclareMethodWithUnit(const G4String& name, >> 190 const G4String& defaultUnit, >> 191 const G4AnyMethod& fun, >> 192 const G4String& doc = ""); 171 void SetDirectory(const G4String& dir) { d 193 void SetDirectory(const G4String& dir) { directory = dir; } 172 void SetGuidance(const G4String& s); 194 void SetGuidance(const G4String& s); 173 void Sort(G4bool val = true) 195 void Sort(G4bool val = true) 174 { 196 { 175 if (dircmd != nullptr) { << 197 if(dircmd != nullptr) >> 198 { 176 dircmd->Sort(val); 199 dircmd->Sort(val); 177 } 200 } 178 } 201 } 179 202 180 private: 203 private: >> 204 181 std::map<G4String, Property> properties; 205 std::map<G4String, Property> properties; 182 std::map<G4String, Method> methods; 206 std::map<G4String, Method> methods; 183 G4UIdirectory* dircmd = nullptr; 207 G4UIdirectory* dircmd = nullptr; 184 G4String directory; 208 G4String directory; 185 void* object = nullptr; 209 void* object = nullptr; 186 }; 210 }; 187 211 188 #endif 212 #endif 189 213