00001 #ifndef MyString2Anything_hh 00002 #define MyString2Anything_hh 1 00003 00004 #include "myglobals.hh" 00005 #include "G4UnitsTable.hh" 00006 00007 #include <string> 00008 #include <sstream> 00009 00010 class MyString2Anything 00011 { 00012 public: 00013 MyString2Anything(); 00014 ~MyString2Anything(); 00015 00016 static void get_SD( G4String cont, G4String& m_str, G4double& m_dou ){ 00017 std::stringstream buf(cont); 00018 buf>>m_str>>m_dou; 00019 } 00020 00021 static void get_SDUI( G4String cont, G4String& m_str, G4double& m_dou, G4int& m_int){ 00022 G4String m_unit; 00023 std::stringstream buf(cont); 00024 buf>>m_str>>m_dou>>m_unit>>m_int; 00025 m_dou *= G4UnitDefinition::GetValueOf(m_unit); 00026 } 00027 00028 static void get_SIDU( G4String cont, G4String& m_str, G4int& m_int, G4double& m_dou ){ 00029 G4String m_unit; 00030 std::stringstream buf(cont); 00031 buf>>m_str>>m_int>>m_dou>>m_unit; 00032 m_dou *= G4UnitDefinition::GetValueOf(m_unit); 00033 } 00034 00035 static void get_SIDUI( G4String cont, G4String& m_str, G4int& m_int, G4double& m_dou, G4int& m_int2 ){ 00036 G4String m_unit; 00037 std::stringstream buf(cont); 00038 buf>>m_str>>m_int>>m_dou>>m_unit>>m_int2; 00039 m_dou *= G4UnitDefinition::GetValueOf(m_unit); 00040 } 00041 00042 static void get_SIIDU( G4String cont, G4String& m_str, G4int& m_int1, G4int& m_int2, G4double& m_dou ){ 00043 G4String m_unit; 00044 std::stringstream buf(cont); 00045 buf>>m_str>>m_int1>>m_int2>>m_dou>>m_unit; 00046 m_dou *= G4UnitDefinition::GetValueOf(m_unit); 00047 } 00048 00049 static void get_SIB( G4String cont, G4String& m_str, G4int& m_int, bool& m_bool ){ 00050 std::string val; 00051 std::stringstream buf(cont); 00052 buf>>m_str>>m_int>>val; 00053 m_bool = ConvertToBool(val); 00054 } 00055 00056 static void get_SID( G4String cont, G4String& m_str, G4int& m_int, G4double& m_dou ){ 00057 std::stringstream buf(cont); 00058 buf>>m_str>>m_int>>m_dou; 00059 } 00060 00061 static void get_SI( G4String cont, G4String& m_str, G4int& m_int ){ 00062 std::stringstream buf(cont); 00063 buf>>m_str>>m_int; 00064 } 00065 00066 static void get_SII( G4String cont, G4String& m_str, G4int& m_int, G4int& m_int2 ){ 00067 std::stringstream buf(cont); 00068 buf>>m_str>>m_int>>m_int2; 00069 } 00070 00071 static void get_SB( G4String cont, G4String& m_str, G4bool& m_bool){ 00072 std::stringstream buf(cont); 00073 buf>>m_str>>m_bool; 00074 } 00075 00076 static void get_SS( G4String cont, G4String& m_str, G4String& m_str2 ){ 00077 std::stringstream buf(cont); 00078 buf>>m_str>>m_str2; 00079 } 00080 00081 static void get_SSS( G4String cont, G4String& m_str, G4String& m_str2, G4String& m_str3 ){ 00082 std::stringstream buf(cont); 00083 buf>>m_str>>m_str2>>m_str3; 00084 } 00085 00086 static void get_SIS( G4String cont, G4String& m_str, G4int& m_int, G4String& m_str2 ){ 00087 std::stringstream buf(cont); 00088 buf>>m_str>>m_int>>m_str2; 00089 } 00090 00091 static void get_IS ( G4String cont, G4int& m_int, G4String& m_str ){ 00092 std::stringstream buf(cont); 00093 buf>>m_int>>m_str; 00094 } 00095 00096 static void get_I ( G4String cont, G4int& m_int){ 00097 std::stringstream buf(cont); 00098 buf>>m_int; 00099 } 00100 00101 static void get_IDU( G4String cont, G4int& m_int, G4double& m_dou ){ 00102 G4String m_unit; 00103 std::stringstream buf(cont); 00104 buf>>m_int>>m_dou>>m_unit; 00105 m_dou *= G4UnitDefinition::GetValueOf(m_unit); 00106 } 00107 00108 static void get_IIDU( G4String cont, G4int& m_int1, G4int& m_int2, G4double& m_dou ){ 00109 G4String m_unit; 00110 std::stringstream buf(cont); 00111 buf>>m_int1>>m_int2>>m_dou>>m_unit; 00112 m_dou *= G4UnitDefinition::GetValueOf(m_unit); 00113 } 00114 00115 static double get_U( G4String cont ){ 00116 double val = G4UnitDefinition::GetValueOf(cont); 00117 if (!val){ 00118 std::cout<<"WARNING: value of unit ("<<cont<<") is 0!!! will set it to 1!!!"<<std::endl; 00119 val = 1; 00120 } 00121 return val; 00122 } 00123 00124 static void get_ID( G4String cont, G4int& m_int, G4double& m_dou ){ 00125 std::stringstream buf(cont); 00126 buf>>m_int>>m_dou; 00127 } 00128 00129 static void get_IB( G4String cont, G4int& m_int, bool& m_bool){ 00130 G4String t_str; 00131 std::stringstream buf(cont); 00132 buf>>m_int>>t_str; 00133 m_bool = ConvertToBool(t_str); 00134 } 00135 00136 static G4bool ConvertToBool(G4String st) 00137 { 00138 st.toUpper(); 00139 G4bool vl = false; 00140 if( st=="Y" || st=="YES" || st=="1" || st=="T" || st=="TRUE" ) 00141 { vl = true; } 00142 return vl; 00143 } 00144 00145 }; 00146 00147 #endif