File indexing completed on 2025-01-18 09:58:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef G4CONVERSIONUTILS_HH
0032 #define G4CONVERSIONUTILS_HH
0033
0034 #include "globals.hh"
0035 #include "G4DimensionedDouble.hh"
0036 #include "G4DimensionedThreeVector.hh"
0037 #include <sstream>
0038
0039 namespace G4ConversionUtils
0040 {
0041
0042
0043
0044 template <typename Value>
0045 G4bool Convert(const G4String& myInput, Value& output)
0046 {
0047 G4String input = G4StrUtil::strip_copy(myInput);
0048
0049 std::istringstream is(input);
0050 char tester;
0051
0052 return ((is >> output) && !is.get(tester));
0053 }
0054
0055
0056 template<>
0057 inline G4bool Convert(const G4String& myInput, G4DimensionedDouble& output)
0058 {
0059 G4String input = G4StrUtil::strip_copy(myInput);
0060
0061 G4double value;
0062 G4String unit;
0063
0064 std::istringstream is(input);
0065 char tester;
0066
0067 if (!(is >> value >> unit) || is.get(tester)) return false;
0068
0069 output = G4DimensionedDouble(value, unit);
0070
0071 return true;
0072 }
0073
0074 template<> inline G4bool Convert(const G4String& myInput,
0075 G4DimensionedThreeVector& output)
0076 {
0077 G4String input = G4StrUtil::strip_copy(myInput);
0078
0079 G4double value1, value2, value3;
0080 G4String unit;
0081
0082 std::istringstream is(input);
0083 char tester;
0084
0085 if (!(is >> value1 >> value2 >> value3 >>unit) || is.get(tester)) return false;
0086
0087 output = G4DimensionedThreeVector(G4ThreeVector(value1, value2, value3), unit);
0088
0089 return true;
0090 }
0091
0092 template<> inline G4bool Convert(const G4String& myInput, G4ThreeVector& output)
0093 {
0094 G4String input = G4StrUtil::strip_copy(myInput);
0095
0096 G4double value1, value2, value3;
0097
0098 std::istringstream is(input);
0099 char tester;
0100
0101 if (!(is >> value1 >> value2 >> value3) || is.get(tester)) return false;
0102 output = G4ThreeVector(value1, value2, value3);
0103
0104 return true;
0105 }
0106
0107
0108
0109
0110 template <typename Value> G4bool Convert(const G4String& myInput, Value& value1,
0111 Value& value2)
0112 {
0113 G4String input = G4StrUtil::strip_copy(myInput);
0114
0115 std::istringstream is(input);
0116 char tester;
0117
0118 return ((is >> value1 >> value2) && (!is.get(tester)));
0119 }
0120
0121
0122 template<> inline G4bool Convert(const G4String& myInput, G4DimensionedDouble& min,
0123 G4DimensionedDouble& max)
0124 {
0125 G4String input = G4StrUtil::strip_copy(myInput);
0126
0127 G4double valueMin, valueMax;
0128 G4String unitsMin, unitsMax;
0129
0130 std::istringstream is(input);
0131 char tester;
0132
0133 if (!(is >> valueMin >> unitsMin >> valueMax >> unitsMax) || is.get(tester)) return false;;
0134
0135 min = G4DimensionedDouble(valueMin, unitsMin);
0136 max = G4DimensionedDouble(valueMax, unitsMax);
0137
0138 return true;
0139 }
0140
0141 template<> inline G4bool Convert(const G4String& myInput, G4DimensionedThreeVector& min,
0142 G4DimensionedThreeVector& max)
0143 {
0144 G4String input = G4StrUtil::strip_copy(myInput);
0145
0146 G4double valueMinX, valueMinY, valueMinZ;
0147 G4double valueMaxX, valueMaxY, valueMaxZ;
0148 G4String unitMin, unitMax;
0149
0150 std::istringstream is(input);
0151 char tester;
0152
0153 if (!(is >> valueMinX >> valueMinY >> valueMinZ >> unitMin >> valueMaxX >> valueMaxY >> valueMaxZ >> unitMax)
0154 || is.get(tester)) return false;
0155
0156 min = G4DimensionedThreeVector(G4ThreeVector(valueMinX, valueMinY, valueMinZ), unitMin);
0157 max = G4DimensionedThreeVector(G4ThreeVector(valueMaxX, valueMaxY, valueMaxZ), unitMax);
0158
0159 return true;
0160 }
0161
0162 template<> inline G4bool Convert(const G4String& myInput, G4ThreeVector& min,
0163 G4ThreeVector& max)
0164 {
0165 G4String input = G4StrUtil::strip_copy(myInput);
0166
0167 G4double valueMinX, valueMinY, valueMinZ;
0168 G4double valueMaxX, valueMaxY, valueMaxZ;
0169
0170 std::istringstream is(input);
0171 char tester;
0172
0173 if (!(is >> valueMinX >> valueMinY >> valueMinZ >> valueMaxX >> valueMaxY >> valueMaxZ)
0174 || is.get(tester)) return false;
0175
0176 min = G4ThreeVector(valueMinX, valueMinY, valueMinZ);
0177 max = G4ThreeVector(valueMaxX, valueMaxY, valueMaxZ);
0178
0179 return true;
0180 }
0181
0182 }
0183
0184 #endif