Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4UImessenger << 27 // 23 // 28 // Author: Makoto Asai, 1998 << 24 // $Id: G4UImessenger.cc,v 1.5 2003/06/16 16:55:46 gunter Exp $ 29 // ------------------------------------------- << 25 // GEANT4 tag $Name: geant4-07-01 $ >> 26 // 30 27 31 #include "G4UImessenger.hh" 28 #include "G4UImessenger.hh" 32 << 33 #include "G4UIcommand.hh" << 34 #include "G4UIcommandTree.hh" << 35 #include "G4UIdirectory.hh" << 36 #include "G4UImanager.hh" 29 #include "G4UImanager.hh" 37 #include "G4UIparsing.hh" << 30 #include "G4UIcommand.hh" >> 31 #include <string.h> 38 #include "G4ios.hh" 32 #include "G4ios.hh" 39 33 40 #include <sstream> << 34 #include <strstream> 41 #include <utility> << 42 35 43 // ------------------------------------------- << 44 G4UImessenger::G4UImessenger(const G4String& p << 45 G4bool commandsTo << 46 { << 47 CreateDirectory(path, dsc, commandsToBeBroad << 48 } << 49 36 50 // ------------------------------------------- << 37 G4UImessenger::G4UImessenger() { } 51 G4UImessenger::~G4UImessenger() << 52 { << 53 delete baseDir; << 54 } << 55 38 56 // ------------------------------------------- << 39 G4UImessenger::~G4UImessenger() { } 57 G4String G4UImessenger::GetCurrentValue(G4UIco << 40 58 { << 41 G4String G4UImessenger::GetCurrentValue(G4UIcommand*) 59 return G4String{}; << 42 { >> 43 G4String nullString; >> 44 return nullString; 60 } 45 } 61 46 62 // ------------------------------------------- << 47 void G4UImessenger::SetNewValue(G4UIcommand*,G4String) 63 void G4UImessenger::SetNewValue(G4UIcommand*, << 48 { ; } 64 49 65 // ------------------------------------------- << 50 G4bool G4UImessenger::operator == (const G4UImessenger& messenger) const { 66 G4String G4UImessenger::ItoS(G4int i) << 51 return this == &messenger; 67 { << 68 std::ostringstream os; << 69 os << i; << 70 return G4String(os.str()); << 71 } 52 } 72 53 73 // ------------------------------------------- << 54 G4String G4UImessenger::ItoS(G4int i) 74 G4String G4UImessenger::LtoS(G4long l) << 75 { 55 { 76 std::ostringstream os; << 56 char defVal[20]; 77 os << l; << 57 std::ostrstream os(defVal,20); 78 return G4String(os.str()); << 58 os << i << '\0'; >> 59 return G4String(defVal); 79 } 60 } 80 61 81 // ------------------------------------------- << 82 G4String G4UImessenger::DtoS(G4double a) 62 G4String G4UImessenger::DtoS(G4double a) 83 { 63 { 84 std::ostringstream os; << 64 char defVal[40]; 85 os << a; << 65 std::ostrstream os(defVal,40); 86 return G4String(os.str()); << 66 os << a << '\0'; >> 67 return G4String(defVal); 87 } 68 } 88 69 89 // ------------------------------------------- << 90 G4String G4UImessenger::BtoS(G4bool b) 70 G4String G4UImessenger::BtoS(G4bool b) 91 { 71 { 92 return b ? "true" : "0"; << 72 G4String vl = "0"; >> 73 if(b) vl = "true"; >> 74 return vl; 93 } 75 } 94 76 95 // ------------------------------------------- << 77 G4int G4UImessenger::StoI(G4String s) 96 G4int G4UImessenger::StoI(const G4String& str) << 97 { 78 { 98 return G4UIparsing::StoT<G4int>(str); << 79 G4int vl; >> 80 const char* t = s; >> 81 std::istrstream is((char*)t); >> 82 is >> vl; >> 83 return vl; 99 } 84 } 100 85 101 // ------------------------------------------- << 86 G4double G4UImessenger::StoD(G4String s) 102 G4long G4UImessenger::StoL(const G4String& str << 103 { 87 { 104 return G4UIparsing::StoT<G4long>(str); << 88 G4double vl; >> 89 const char* t = s; >> 90 std::istrstream is((char*)t); >> 91 is >> vl; >> 92 return vl; 105 } 93 } 106 94 107 // ------------------------------------------- << 95 G4bool G4UImessenger::StoB(G4String s) 108 G4double G4UImessenger::StoD(const G4String& s << 109 { 96 { 110 return G4UIparsing::StoT<G4double>(str); << 97 G4String v = s; >> 98 v.toUpper(); >> 99 G4bool vl = false; >> 100 if( v=="Y" || v=="YES" || v=="1" || v=="T" || v=="TRUE" ) >> 101 { vl = true; } >> 102 return vl; 111 } 103 } 112 104 113 // ------------------------------------------- << 114 G4bool G4UImessenger::StoB(const G4String& str << 115 { << 116 const G4String& v = G4StrUtil::to_upper_copy << 117 return (v == "Y" || v == "YES" || v == "1" | << 118 } << 119 105 120 // ------------------------------------------- << 106 void G4UImessenger::AddUIcommand(G4UIcommand * newCommand) 121 void G4UImessenger::AddUIcommand(G4UIcommand* << 122 { 107 { 123 G4cerr << "Warning : Old style definition of << 108 G4cerr << "Warning : Old style definition of G4UIcommand <" 124 << ">." << G4endl; << 109 << newCommand->GetCommandPath() << ">." << G4endl; 125 } 110 } 126 111 127 // ------------------------------------------- << 128 void G4UImessenger::CreateDirectory(const G4St << 129 G4bool com << 130 { << 131 G4UImanager* ui = G4UImanager::GetUIpointer( << 132 << 133 G4String fullpath = path; << 134 if (fullpath.back() != '/') { << 135 fullpath.append("/"); << 136 } << 137 << 138 G4UIcommandTree* tree = ui->GetTree()->FindC << 139 if (tree != nullptr) { << 140 baseDirName = tree->GetPathName(); << 141 } << 142 else { << 143 baseDir = new G4UIdirectory(fullpath.c_str << 144 baseDirName = std::move(fullpath); << 145 baseDir->SetGuidance(dsc.c_str()); << 146 } << 147 } << 148 112