00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef G4CONVERSIONUTILS_HH
00033 #define G4CONVERSIONUTILS_HH
00034
00035 #include "globals.hh"
00036 #include "G4DimensionedDouble.hh"
00037 #include "G4DimensionedThreeVector.hh"
00038 #include <sstream>
00039
00040 namespace G4ConversionUtils
00041 {
00042
00043
00044
00045 template <typename Value>
00046 G4bool Convert(const G4String& myInput, Value& output)
00047 {
00048 G4String input(myInput);
00049 input = input.strip();
00050
00051 std::istringstream is(input);
00052 char tester;
00053
00054 return ((is >> output) && !is.get(tester));
00055 }
00056
00057
00058 template<>
00059 inline G4bool Convert(const G4String& myInput, G4DimensionedDouble& output)
00060 {
00061 G4String input(myInput);
00062 input = input.strip();
00063
00064 G4double value;
00065 G4String unit;
00066
00067 std::istringstream is(input);
00068 char tester;
00069
00070 if (!(is >> value >> unit) || is.get(tester)) return false;
00071
00072 output = G4DimensionedDouble(value, unit);
00073
00074 return true;
00075 }
00076
00077 template<> inline G4bool Convert(const G4String& myInput,
00078 G4DimensionedThreeVector& output)
00079 {
00080 G4String input(myInput);
00081 input = input.strip();
00082
00083 G4double value1, value2, value3;
00084 G4String unit;
00085
00086 std::istringstream is(input);
00087 char tester;
00088
00089 if (!(is >> value1 >> value2 >> value3 >>unit) || is.get(tester)) return false;
00090
00091 output = G4DimensionedThreeVector(G4ThreeVector(value1, value2, value3), unit);
00092
00093 return true;
00094 }
00095
00096 template<> inline G4bool Convert(const G4String& myInput, G4ThreeVector& output)
00097 {
00098 G4String input(myInput);
00099 input = input.strip();
00100
00101 G4double value1, value2, value3;
00102
00103 std::istringstream is(input);
00104 char tester;
00105
00106 if (!(is >> value1 >> value2 >> value3) || is.get(tester)) return false;
00107 output = G4ThreeVector(value1, value2, value3);
00108
00109 return true;
00110 }
00111
00112
00113
00114
00115 template <typename Value> G4bool Convert(const G4String& myInput, Value& value1,
00116 Value& value2)
00117 {
00118 G4String input(myInput);
00119 input = input.strip();
00120
00121 std::istringstream is(input);
00122 char tester;
00123
00124 return ((is >> value1 >> value2) && (!is.get(tester)));
00125 }
00126
00127
00128 template<> inline G4bool Convert(const G4String& myInput, G4DimensionedDouble& min,
00129 G4DimensionedDouble& max)
00130 {
00131 G4String input(myInput);
00132 input = input.strip();
00133
00134 G4double valueMin, valueMax;
00135 G4String unitsMin, unitsMax;
00136
00137 std::istringstream is(input);
00138 char tester;
00139
00140 if (!(is >> valueMin >> unitsMin >> valueMax >> unitsMax) || is.get(tester)) return false;;
00141
00142 min = G4DimensionedDouble(valueMin, unitsMin);
00143 max = G4DimensionedDouble(valueMax, unitsMax);
00144
00145 return true;
00146 }
00147
00148 template<> inline G4bool Convert(const G4String& myInput, G4DimensionedThreeVector& min,
00149 G4DimensionedThreeVector& max)
00150 {
00151 G4String input(myInput);
00152 input = input.strip();
00153
00154 G4double valueMinX, valueMinY, valueMinZ;
00155 G4double valueMaxX, valueMaxY, valueMaxZ;
00156 G4String unitMin, unitMax;
00157
00158 std::istringstream is(input);
00159 char tester;
00160
00161 if (!(is >> valueMinX >> valueMinY >> valueMinZ >> unitMin >> valueMaxX >> valueMaxY >> valueMaxZ >> unitMax)
00162 || is.get(tester)) return false;
00163
00164 min = G4DimensionedThreeVector(G4ThreeVector(valueMinX, valueMinY, valueMinZ), unitMin);
00165 max = G4DimensionedThreeVector(G4ThreeVector(valueMaxX, valueMaxY, valueMaxZ), unitMax);
00166
00167 return true;
00168 }
00169
00170 template<> inline G4bool Convert(const G4String& myInput, G4ThreeVector& min,
00171 G4ThreeVector& max)
00172 {
00173 G4String input(myInput);
00174 input = input.strip();
00175
00176 G4double valueMinX, valueMinY, valueMinZ;
00177 G4double valueMaxX, valueMaxY, valueMaxZ;
00178
00179 std::istringstream is(input);
00180 char tester;
00181
00182 if (!(is >> valueMinX >> valueMinY >> valueMinZ >> valueMaxX >> valueMaxY >> valueMaxZ)
00183 || is.get(tester)) return false;
00184
00185 min = G4ThreeVector(valueMinX, valueMinY, valueMinZ);
00186 max = G4ThreeVector(valueMaxX, valueMaxY, valueMaxZ);
00187
00188 return true;
00189 }
00190
00191 }
00192
00193 #endif