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;
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;
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>
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
std::map< G4String, Pair > IntervalMap
G4bool Accept(const G4AttValue &attVal) const
void LoadSingleValueElement(const G4String &input)
void LoadIntervalElement(const G4String &input)
virtual ~G4AttValueFilterT()
SingleValueMap fSingleValueMap
std::map< G4String, T > SingleValueMap
const G4String & GetValue() const
bool operator()(const std::pair< const G4String, std::pair< T, T > > &myPair) const
InInterval(const T &value)
bool operator()(const std::pair< const G4String, T > &myPair) const
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