31#ifndef G4ATTVALUEFILTERT_HH
32#define G4ATTVALUEFILTERT_HH
47 IsEqual(
const T& value): fValue(value) {};
48 bool operator()(
const std::pair<const G4String, T>& myPair)
const
50 return myPair.second == fValue;
59 InInterval(
const T& value): fValue(value) {};
60 bool operator()(
const std::pair<
const G4String, std::pair<T, T> >& myPair)
const
62 T
min = myPair.second.first;
63 T
max = myPair.second.second;
64 return ((fValue > min || fValue == min) && (fValue < max));
72template <
typename T,
typename ConversionErrorPolicy = G4ConversionFatalError>
87 virtual void PrintAll(std::ostream& ostr)
const;
97 typedef std::pair<T, T> Pair;
98 typedef typename std::map<G4String, Pair> IntervalMap;
99 typedef std::map<G4String, T> SingleValueMap;
103 IntervalMap fIntervalMap;
104 SingleValueMap fSingleValueMap;
108template <
typename T,
typename ConversionErrorPolicy>
111template <
typename T,
typename ConversionErrorPolicy>
114template <
typename T,
typename ConversionErrorPolicy>
121 if (!
G4ConversionUtils::Convert(input, value)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
123 typename SingleValueMap::const_iterator iterValues =
124 std::find_if(fSingleValueMap.begin(), fSingleValueMap.end(), IsEqual<T>(value));
126 if (iterValues != fSingleValueMap.end()) {
127 element = iterValues->first;
131 typename IntervalMap::const_iterator iterIntervals =
132 std::find_if(fIntervalMap.begin(), fIntervalMap.end(), InInterval<T>(value));
134 if (iterIntervals != fIntervalMap.end()) {
135 element = iterIntervals->first;
142template <
typename T,
typename ConversionErrorPolicy>
149 if (!
G4ConversionUtils::Convert(input, value)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
151 typename SingleValueMap::const_iterator iterValues =
152 std::find_if(fSingleValueMap.begin(), fSingleValueMap.end(), IsEqual<T>(value));
154 if (iterValues != fSingleValueMap.end())
return true;
156 typename IntervalMap::const_iterator iterIntervals =
157 std::find_if(fIntervalMap.begin(), fIntervalMap.end(), InInterval<T>(value));
159 if (iterIntervals != fIntervalMap.end())
return true;
164template <
typename T,
typename ConversionErrorPolicy>
171 if (!
G4ConversionUtils::Convert(input, min, max)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
173 fIntervalMap[input] = std::pair<T, T> (min, max);
176template <
typename T,
typename ConversionErrorPolicy>
182 if (!
G4ConversionUtils::Convert(input, output)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
184 fSingleValueMap[input] = std::move(output);
187template <
typename T,
typename ConversionErrorPolicy>
191 ostr<<
"Printing data for filter: "<<
Name()<<std::endl;
193 ostr<<
"Interval data:"<<std::endl;
195 typename IntervalMap::const_iterator iterIntervals = fIntervalMap.begin();
197 while (iterIntervals != fIntervalMap.end()) {
198 ostr<<iterIntervals->second.first<<
" : "<<iterIntervals->second.second<<std::endl;
202 ostr<<
"Single value data:"<<std::endl;
204 typename SingleValueMap::const_iterator iterValues = fSingleValueMap.begin();
206 while (iterValues != fSingleValueMap.end()) {
207 ostr<<iterValues->second<<std::endl;
212template <
typename T,
typename ConversionErrorPolicy>
216 fIntervalMap.clear();
217 fSingleValueMap.clear();
virtual void PrintAll(std::ostream &ostr) const
G4bool GetValidElement(const G4AttValue &input, G4String &interval) const
G4bool Accept(const G4AttValue &attVal) const
void LoadSingleValueElement(const G4String &input)
void LoadIntervalElement(const G4String &input)
virtual ~G4AttValueFilterT()
const G4String & GetValue() const
G4VAttValueFilter(const G4String &name="G4AttValueFilter")
G4bool Convert(const G4String &myInput, Value &output)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments