31 #ifndef G4ATTVALUEFILTERT_HH
32 #define G4ATTVALUEFILTERT_HH
45 IsEqual(
const T&
value): fValue(value) {};
46 bool operator()(
const std::pair<const G4String, T>& myPair)
const
48 return myPair.second == fValue;
57 InInterval(
const T&
value): fValue(value) {};
58 bool operator()(
const std::pair<
const G4String, std::pair<T, T> >& myPair)
const
60 T min = myPair.second.first;
61 T max = myPair.second.second;
62 return ((fValue > min || fValue == min) && (fValue < max));
70 template <
typename T,
typename ConversionErrorPolicy = G4ConversionFatalError>
85 virtual void PrintAll(std::ostream& ostr)
const;
95 typedef std::pair<T, T>
Pair;
106 template <
typename T,
typename ConversionErrorPolicy>
109 template <
typename T,
typename ConversionErrorPolicy>
112 template <
typename T,
typename ConversionErrorPolicy>
119 if (!
G4ConversionUtils::Convert(input, value)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
121 typename SingleValueMap::const_iterator iterValues =
122 std::find_if(fSingleValueMap.begin(), fSingleValueMap.end(), IsEqual<T>(
value));
124 if (iterValues != fSingleValueMap.end()) {
125 element = iterValues->
first;
129 typename IntervalMap::const_iterator iterIntervals =
130 std::find_if(fIntervalMap.begin(), fIntervalMap.end(), InInterval<T>(
value));
132 if (iterIntervals != fIntervalMap.end()) {
133 element = iterIntervals->
first;
140 template <
typename T,
typename ConversionErrorPolicy>
147 if (!
G4ConversionUtils::Convert(input, value)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
149 typename SingleValueMap::const_iterator iterValues =
150 std::find_if(fSingleValueMap.begin(), fSingleValueMap.end(), IsEqual<T>(
value));
152 if (iterValues != fSingleValueMap.end())
return true;
154 typename IntervalMap::const_iterator iterIntervals =
155 std::find_if(fIntervalMap.begin(), fIntervalMap.end(), InInterval<T>(
value));
157 if (iterIntervals != fIntervalMap.end())
return true;
162 template <
typename T,
typename ConversionErrorPolicy>
169 if (!
G4ConversionUtils::Convert(input, min, max)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
171 std::pair<T, T> myPair(min, max);
172 fIntervalMap[input] = myPair;
175 template <
typename T,
typename ConversionErrorPolicy>
181 if (!
G4ConversionUtils::Convert(input, output)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
183 fSingleValueMap[input] = output;
186 template <
typename T,
typename ConversionErrorPolicy>
190 ostr<<
"Printing data for filter: "<<
Name()<<std::endl;
192 ostr<<
"Interval data:"<<std::endl;
194 typename IntervalMap::const_iterator iterIntervals = fIntervalMap.begin();
196 while (iterIntervals != fIntervalMap.end()) {
197 ostr<<iterIntervals->second.first<<
" : "<<iterIntervals->second.second<<std::endl;
201 ostr<<
"Single value data:"<<std::endl;
203 typename SingleValueMap::const_iterator iterValues = fSingleValueMap.begin();
205 while (iterValues != fSingleValueMap.end()) {
206 ostr<<iterValues->second<<std::endl;
211 template <
typename T,
typename ConversionErrorPolicy>
215 fIntervalMap.clear();
216 fSingleValueMap.clear();