// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // $Id: G4AttributeFilterT.hh,v 1.6 2006/12/13 15:50:02 gunter Exp $ // GEANT4 tag $Name: $ // // Generic attribute filter. // // Jane Tinslay, May 2006 // #ifndef G4ATTRIBUTEFILTERT_HH #define G4ATTRIBUTEFILTERT_HH #include "G4AttDef.hh" #include "G4AttFilterUtils.hh" #include "G4AttUtils.hh" #include "G4AttValue.hh" #include "G4SmartFilter.hh" #include "G4VAttValueFilter.hh" #include #include template class G4AttributeFilterT : public G4SmartFilter { public: // Construct with filter name G4AttributeFilterT(const G4String& name = "Unspecified"); // Destructor virtual ~G4AttributeFilterT(); // Evaluate virtual bool Evaluate(const T&) const; // Print configuration virtual void Print(std::ostream& ostr) const; // Clear filter virtual void Clear(); // Configuration functions void Set(const G4String& name); void AddInterval(const G4String&); void AddValue(const G4String&); private: enum Config {Interval, SingleValue}; typedef std::pair Pair; typedef std::vector ConfigVect; // Data members G4String fAttName; ConfigVect fConfigVect; // Caching mutable G4bool fFirst; mutable G4bool fWarnedMissingAttribute; mutable G4VAttValueFilter* filter; }; template G4AttributeFilterT::G4AttributeFilterT(const G4String& name) :G4SmartFilter(name) ,fAttName("") ,fFirst(true) ,fWarnedMissingAttribute(false) ,filter(0) {} template G4AttributeFilterT::~G4AttributeFilterT() { delete filter; } template G4bool G4AttributeFilterT::Evaluate(const T& object) const { // Return false if attribute name has not been set. Just print one warning. if (fAttName.isNull()) { if (!fWarnedMissingAttribute) { std::ostringstream o; o<<"Null attribute name"; G4Exception("G4AttributeFilterT::Evaluate", "NullAttributeName", JustWarning, o.str().c_str()); fWarnedMissingAttribute = true; } return false; } if (fFirst) { fFirst = false; // Get attribute definition G4AttDef attDef; // Expect definition to exist if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) { std::ostringstream o; o <<"Unable to extract attribute definition named "<second == G4AttributeFilterT::Interval) {filter->LoadIntervalElement(iter->first);} else if (iter->second == G4AttributeFilterT::SingleValue) {filter->LoadSingleValueElement(iter->first);} iter++; } } // Get attribute value G4AttValue attVal; // Expect value to exist if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) { std::ostringstream o; o <<"Unable to extract attribute value named "<::GetVerbose()) { G4cout<<"G4AttributeFilterT processing attribute named "<Accept(attVal)); } template void G4AttributeFilterT::Clear() { fConfigVect.clear(); if (0 != filter) filter->Reset(); } template void G4AttributeFilterT::Print(std::ostream& ostr) const { ostr<<"Printing data for G4Attribute filter named: "<::Name()<PrintAll(ostr); } template void G4AttributeFilterT::Set(const G4String& name) { fAttName = name; } template void G4AttributeFilterT::AddInterval(const G4String& interval) { std::pair myPair(interval, G4AttributeFilterT::Interval); typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair); if (iter != fConfigVect.end()) { std::ostringstream o; o <<"Interval "<< interval <<" already exists"< void G4AttributeFilterT::AddValue(const G4String& value) { std::pair myPair(value, G4AttributeFilterT::SingleValue); typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair); if (iter != fConfigVect.end()) { std::ostringstream o; o <<"Single value "<< value <<" already exists"<