32 #ifndef G4ATTVALUEFILTERT_HH
33 #define G4ATTVALUEFILTERT_HH
46 IsEqual(
const T&
value): fValue(value) {};
47 bool operator()(
const std::pair<const G4String, T>& myPair)
const
49 return myPair.second == fValue;
58 InInterval(
const T&
value): fValue(value) {};
59 bool operator()(
const std::pair<
const G4String, std::pair<T, T> >& myPair)
const
61 T
min = myPair.second.first;
62 T
max = myPair.second.second;
63 return ((fValue > min || fValue == min) && (fValue < max));
71 template <
typename T,
typename ConversionErrorPolicy = G4ConversionFatalError>
86 virtual void PrintAll(std::ostream& ostr)
const;
96 typedef std::pair<T, T>
Pair;
107 template <
typename T,
typename ConversionErrorPolicy>
110 template <
typename T,
typename ConversionErrorPolicy>
113 template <
typename T,
typename ConversionErrorPolicy>
120 if (!
G4ConversionUtils::Convert(input, value)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
122 typename SingleValueMap::const_iterator iterValues =
123 std::find_if(fSingleValueMap.begin(), fSingleValueMap.end(), IsEqual<T>(
value));
125 if (iterValues != fSingleValueMap.end()) {
126 element = iterValues->
first;
130 typename IntervalMap::const_iterator iterIntervals =
131 std::find_if(fIntervalMap.begin(), fIntervalMap.end(), InInterval<T>(
value));
133 if (iterIntervals != fIntervalMap.end()) {
134 element = iterIntervals->
first;
141 template <
typename T,
typename ConversionErrorPolicy>
148 if (!
G4ConversionUtils::Convert(input, value)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
150 typename SingleValueMap::const_iterator iterValues =
151 std::find_if(fSingleValueMap.begin(), fSingleValueMap.end(), IsEqual<T>(
value));
153 if (iterValues != fSingleValueMap.end())
return true;
155 typename IntervalMap::const_iterator iterIntervals =
156 std::find_if(fIntervalMap.begin(), fIntervalMap.end(), InInterval<T>(
value));
158 if (iterIntervals != fIntervalMap.end())
return true;
163 template <
typename T,
typename ConversionErrorPolicy>
170 if (!
G4ConversionUtils::Convert(input, min, max)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
172 std::pair<T, T> myPair(min, max);
173 fIntervalMap[input] = myPair;
176 template <
typename T,
typename ConversionErrorPolicy>
182 if (!
G4ConversionUtils::Convert(input, output)) ConversionErrorPolicy::ReportError(input,
"Invalid format. Was the input data formatted correctly ?");
184 fSingleValueMap[input] = output;
187 template <
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;
212 template <
typename T,
typename ConversionErrorPolicy>
216 fIntervalMap.clear();
217 fSingleValueMap.clear();
T max(const T t1, const T t2)
brief Return the largest of the two arguments
std::map< G4String, Pair > IntervalMap
G4bool Convert(const G4String &myInput, Value &output)
SingleValueMap fSingleValueMap
virtual ~G4AttValueFilterT()
const XML_Char int const XML_Char * value
void LoadSingleValueElement(const G4String &input)
virtual void PrintAll(std::ostream &ostr) const
G4bool GetValidElement(const G4AttValue &input, G4String &interval) const
std::map< G4String, T > SingleValueMap
G4bool Accept(const G4AttValue &attVal) const
void LoadIntervalElement(const G4String &input)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
const G4String & GetValue() const