Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

ObjectManager.cpp

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiSvc/src/ApplicationMgr/ObjectManager.cpp,v 1.1.1.2 2001/04/18 18:32:48 tlindner Exp $
00002 
00003 // Framework Include files
00004 #include "GaudiKernel/IFactory.h"
00005 #include "GaudiKernel/IObjManager.h"
00006 #include "GaudiKernel/ISvcLocator.h"
00007 #include "GaudiKernel/MsgStream.h"
00008 #include "ObjectManager.h"
00009 
00010 // STL Include files
00011 #include <iostream>
00012 
00013 // constructor
00014 ObjectManager::ObjectManager(ISvcLocator* svclocator) {
00015   m_objects = new Container();
00016   m_svclocator = svclocator;
00017   m_refcount   = 1;
00018   m_msgsvc     = 0;
00019 }
00020 
00021 // destructor
00022 ObjectManager::~ObjectManager()   {
00023   delete m_objects;
00024 }
00025 
00026 // addRef
00027 unsigned long ObjectManager::addRef() {
00028   m_refcount++;
00029         return m_refcount;
00030 }
00031 
00032 // release
00033 unsigned long ObjectManager::release() {
00034   m_refcount--;
00035   if( m_refcount <= 0) {
00036     delete this;
00037   }
00038   return m_refcount;
00039 }
00040 
00041 // queryInterface
00042 StatusCode ObjectManager::queryInterface(const IID& iid, void** pinterface) {
00043   if( iid == IID_IInterface ) {  
00044     *pinterface = (IInterface*)this;
00045     addRef();
00046     return StatusCode::SUCCESS;
00047   } 
00048   else if ( iid == IID_IObjManager ) {
00049     *pinterface = (IObjManager*)this;
00050     addRef();
00051     return StatusCode::SUCCESS;
00052   } 
00053   else {
00054     return StatusCode::FAILURE;
00055   }
00056   return StatusCode::SUCCESS;
00057 }
00058 
00059 // Declare an abastract Converter factory to be used to create instances of a given Converter type
00060 StatusCode ObjectManager::declareObjFactory( const IFactory& factory )   {
00061   // Access the message service if not yet done already
00062   if( m_msgsvc == 0 ) {
00063     m_svclocator->getService( "MessageSvc", IID_IMessageSvc, (IInterface*&)m_msgsvc );
00064   }
00065   MsgStream log(m_msgsvc, "ObjectManager");
00066 
00067   const std::string& objtype = factory.ident(); // Factory identifier.
00068   for ( Container::iterator i = m_objects->begin(); i != m_objects->end(); i++ )    {
00069     if ( objtype == (*i)->ident() )   {
00070       log << MSG::WARNING << "Factory for class:" << factory.ident() 
00071                           << " already exists." << endreq;
00072       m_objects->erase(i);
00073       break;
00074     }
00075   }
00076 
00077   log << MSG::DEBUG << "Added object factory for class:" << factory.ident() << endreq;
00078 
00079   m_objects->push_back( & factory );
00080   return StatusCode::SUCCESS;
00081 }
00082 
00083 // Check the existance of an Converter with a given name in the list of known Converters
00084 bool ObjectManager::existsObjFactory(const std::string& objtype             // Factory's object type
00085                               ) const   {
00086   for ( Container::const_iterator i = m_objects->begin(); i != m_objects->end(); i++ )    {
00087     if ( objtype == (*i)->ident() )   {
00088       return true;
00089     }
00090   }
00091   return false;
00092 }
00093 
00094 // Check the existance of an Converter with a given name in the list of known Converters
00095 const IFactory* ObjectManager::objFactory(const std::string& objtype             // Factory's object type
00096                                          ) const
00097 {
00098   for ( Container::const_iterator i = m_objects->begin(); i != m_objects->end(); i++ )    {
00099     if ( objtype == (*i)->ident() )   {
00100       return (*i);
00101     }
00102   }
00103   return 0;
00104 }

Generated at Wed Nov 21 12:22:30 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000