| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# ISvcLocator.h

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/ISvcLocator.h,v 1.15 2006/12/14 12:55:44 hmd Exp $
    00002 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
    00003 #define GAUDIKERNEL_ISVCLOCATOR_H 1
    00004
    00005 // Include files
    00006 #include "GaudiKernel/IInterface.h"
    00007 #include "GaudiKernel/ISvcManager.h"
    00008 #include <string>
    00009 #include <list>
    00010
    00011 // Forward class declaration
    00012 class IService;
    00013
    00014 // Declaration of the interface ID ( interface id, major version, minor version)
    00015 static const InterfaceID IID_ISvcLocator(11, 2 , 1);
    00016
    00027 class ISvcLocator : virtual public  IInterface  {
    00028 public:
    00030   static const InterfaceID& interfaceID() { return IID_ISvcLocator; }
    00035   virtual StatusCode getService( const std::string& name,
    00036                                  IService*&  svc ) = 0;
    00042   virtual StatusCode getService( const std::string& name,
    00043                                  const InterfaceID& iid,
    00044                                  IInterface*& pinterface ) = 0;
    00045
    00051   virtual StatusCode getService( const std::string& name,
    00052                                  IService*& svc,
    00053                                  bool createIf ) = 0;
    00054
    00056   //virtual void eraseService(const IService*) = 0;
    00057
    00059   virtual const std::list<IService*>& getServices( ) const = 0;
    00060
    00062   virtual bool existsService( const std::string& name ) const = 0;
    00063
    00065   template <class T>
    00066   StatusCode service( const std::string& name, T*& svc, bool createIf = true ) {
    00067     if( createIf ) {
    00068       IService* s;
    00069       StatusCode sc = getService( name, s, true);
    00070       if ( !sc.isSuccess() ) return sc;  // Must check if initialization was OK!
    00071     }
    00072     return getService( name, T::interfaceID(), (IInterface*&)svc );
    00073   }
    00074
    00076   template <class T>
    00077   StatusCode service( const std::string& type, const std::string& name,
    00078                       T*& svc, bool createIf = true ) {
    00079     try {
    00080       ISvcManager& theManager = dynamic_cast<ISvcManager&>(*this);
    00081       theManager.declareSvcType(name, type).ignore();
    00082     } catch(...) {}
    00083     //even if the above fails we may still find the service, so keep going
    00084     return service(name, svc, createIf);
    00085   }
    00086 };
    00087
    00088
    00089 #endif  // GAUDI_ISVCLOCATOR_H