32#ifndef G4ATTVALUEFILTERT_HH
33#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));
70template <
typename T,
typename ConversionErrorPolicy = G4ConversionFatalError>
85 virtual void PrintAll(std::ostream& ostr)
const;
95 typedef std::pair<T, T> Pair;
96 typedef typename std::map<G4String, Pair> IntervalMap;
97 typedef std::map<G4String, T> SingleValueMap;
101 IntervalMap fIntervalMap;
102 SingleValueMap fSingleValueMap;
106template <
typename T,
typename ConversionErrorPolicy>
109template <
typename T,
typename ConversionErrorPolicy>
112template <
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;
140template <
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;
162template <
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;
175template <
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;
186template <
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;
211template <
typename T,
typename ConversionErrorPolicy>
215 fIntervalMap.clear();
216 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
G4bool Convert(const G4String &myInput, Value &output)