| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

# KeyedObject.cpp

Go to the documentation of this file.

    00001 // $Id $
    00002 // Include files
    00003 #include "GaudiKernel/Kernel.h"
    00004 #include "GaudiKernel/IRegistry.h"
    00005 #include "GaudiKernel/LinkManager.h"
    00006 #include "GaudiKernel/GaudiException.h"
    00007 #include "GaudiKernel/IDataProviderSvc.h"
    00008 #include "GaudiKernel/ObjectContainerBase.h"
    00009 #include "GaudiKernel/ContainedObject.h"
    00010
    00016 namespace Objects    {
    00017   bool access(const ContainedObject* from, ContainedObject** to);
    00018   bool access(const DataObject* from, DataObject** to);
    00019
    00020   template <class TO, class FROM>
    00021   TO* reference(FROM* from)    {
    00022     ContainedObject* to = 0;
    00023     if ( access(from, &to) )    {
    00024       return dynamic_cast<TO*>(to);
    00025     }
    00026     return 0;
    00027   }
    00028 }
    00029
    00030 bool Objects::access(const DataObject* from, DataObject** to)
    00031 {
    00032   DataObject* src  = const_cast<DataObject*>(from);
    00033   DataObject* tar = 0;
    00034   if ( src != 0 )
    00035   {
    00036     LinkManager* mgr = src->linkMgr();
    00037     if ( 0 != mgr )
    00038     {
    00039       LinkManager::Link* link = mgr->link(long(0));
    00040       if ( 0 != link )
    00041       {
    00042         tar = link->object();
    00043         if ( 0 == tar )
    00044         {
    00045           IRegistry* reg = src->registry();
    00046           if ( 0 != reg )
    00047           {
    00048             IDataProviderSvc* ds = reg->dataSvc();
    00049             if ( 0 != ds )
    00050             {
    00051               if ( ds->retrieveObject(link->path(), tar).isSuccess() )
    00052               {
    00053                 link->setObject(tar);
    00054               }
    00055             }
    00056           }
    00057         }
    00058       }
    00059     }
    00060   }
    00061   *to = tar;
    00062   return tar != 0;
    00063 }
    00064
    00065 // Load on demand: ContainedObject type references
    00066 bool Objects::access(const ContainedObject* from, ContainedObject** to)
    00067 {
    00068   *to = 0;
    00069   if ( from )
    00070   {
    00071     DataObject *tar = 0;
    00072     if ( access(from->parent(), &tar) )
    00073     {
    00074       ObjectContainerBase* cnt = dynamic_cast<ObjectContainerBase*>(tar);
    00075       if ( cnt )
    00076       {
    00077         *to = cnt->containedObject(from->index());
    00078       }
    00079     }
    00080   }
    00081   return (*to) != 0;
    00082 }
    00083

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines