00001 // $Id: GetAlg.h,v 1.2 2007/11/20 13:01:06 marcocle Exp $ 00002 // ============================================================================ 00003 #ifndef GAUDIALG_GETALG_H 00004 #define GAUDIALG_GETALG_H 1 00005 // ============================================================================ 00006 // Include files 00007 // ============================================================================ 00008 // GaudiKernnel 00009 // ============================================================================ 00010 #include "GaudiKernel/IAlgorithm.h" 00011 // ============================================================================ 00012 // forward declarations 00013 // ============================================================================ 00014 class IAlgContextSvc ; 00015 // ============================================================================ 00016 namespace Gaudi 00017 { 00018 namespace Utils 00019 { 00020 // ======================================================================== 00026 class AlgSelector 00027 { 00028 public: 00030 virtual bool operator() ( const IAlgorithm* ) const = 0 ; 00031 // virtual destructor 00032 virtual ~AlgSelector () ; 00033 }; 00034 // ======================================================================== 00041 template <class TYPE> 00042 class AlgTypeSelector : public AlgSelector 00043 { 00044 public: 00046 virtual bool operator() ( const IAlgorithm* a ) const 00047 { return dynamic_cast<const TYPE*>( a ) != 0; } 00048 } ; 00049 // ======================================================================== 00050 template <class TYPE> 00051 class AlgTypeSelector<TYPE*> : public AlgTypeSelector<TYPE> {} ; 00052 // ======================================================================== 00053 template <class TYPE> 00054 class AlgTypeSelector<const TYPE*> : public AlgTypeSelector<TYPE> {} ; 00055 // ======================================================================== 00056 template <class TYPE> 00057 class AlgTypeSelector<TYPE&> : public AlgTypeSelector<TYPE> {} ; 00058 // ======================================================================== 00059 template <class TYPE> 00060 class AlgTypeSelector<const TYPE&> : public AlgTypeSelector<TYPE> {} ; 00061 // ======================================================================== 00062 template <class TYPE> 00063 class AlgTypeSelector<const TYPE> : public AlgTypeSelector<TYPE> {} ; 00064 // ======================================================================== 00071 class AlgNameSelector : public AlgSelector 00072 { 00073 public: 00075 AlgNameSelector ( const std::string& name ) : m_name ( name ) {} ; 00077 virtual bool operator() ( const IAlgorithm* a ) const 00078 { return 0 != a ? a->name() == m_name : false ; } 00079 private: 00080 // the default constructor is disabled 00081 AlgNameSelector() ; 00082 private: 00083 // algorithm name 00084 std::string m_name ; 00085 } ; 00086 // ======================================================================== 00087 } // end of namespace Gaudi::Utils 00088 } // end of namespace Gaudi 00089 // ============================================================================ 00090 namespace Gaudi 00091 { 00092 namespace Utils 00093 { 00094 // ======================================================================== 00117 IAlgorithm* getAlgorithm 00118 ( const IAlgContextSvc* svc , 00119 const AlgSelector& sel ) ; 00120 // ======================================================================== 00143 IAlgorithm* getAlgorithm 00144 ( const std::vector<IAlgorithm*>& lst , 00145 const AlgSelector& sel ) ; 00146 // ======================================================================== 00147 } // end of namespace Gaudi::Utils 00148 } // end of namespace Gaudi 00149 // ============================================================================ 00150 // The END 00151 // ============================================================================ 00152 #endif // GAUDIALG_GETALG_H 00153 // ============================================================================