| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# SmartDataObjectPtr.cpp

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/SmartDataObjectPtr.cpp,v 1.5 2003/06/25 15:59:40 mato Exp $
    00002 //      ====================================================================
    00003 //      SmartDataObjectPtr.cpp
    00004 //      --------------------------------------------------------------------
    00005 //
    00006 //      Package   :
    00007 //
    00008 //      Author    : Markus Frank
    00009 //
    00010 //      ====================================================================
    00011 #define GAUDIKERNEL_SMARTDATAOBJECTPTR_CPP 1
    00012
    00013 // Framework include files
    00014 #include "GaudiKernel/DataObject.h"
    00015 #include "GaudiKernel/IDataProviderSvc.h"
    00016 #include "GaudiKernel/SmartDataObjectPtr.h"
    00017
    00018 SmartDataObjectPtr::AccessFunction SmartDataObjectPtr::ObjectLoader::access()   {
    00019   return &SmartDataObjectPtr::retrieve;
    00020 }
    00021
    00022 SmartDataObjectPtr::AccessFunction SmartDataObjectPtr::ObjectFinder::access()   {
    00023   return &SmartDataObjectPtr::find;
    00024 }
    00025
    00027 SmartDataObjectPtr& SmartDataObjectPtr::operator=(const SmartDataObjectPtr& copy)   {
    00028   m_path          = copy.m_path;
    00029   m_pRegistry     = copy.m_pRegistry;
    00030   m_dataProvider  = copy.m_dataProvider;
    00031   return *this;
    00032 }
    00033
    00035 StatusCode SmartDataObjectPtr::retrieve(IRegistry* pRegistry, const std::string& path, DataObject*& refpObject)    {
    00036   StatusCode status = StatusCode::FAILURE;
    00037   if ( 0 != m_dataProvider && 0 != pRegistry )    {
    00038     status = m_dataProvider->retrieveObject(pRegistry, path, refpObject);
    00039   }
    00040   return status;
    00041 }
    00042
    00044 StatusCode SmartDataObjectPtr::retrieve(const std::string& fullPath, DataObject*& refpObject)    {
    00045   StatusCode status = StatusCode::FAILURE;
    00046   if ( 0 != m_dataProvider )    {
    00047     status = m_dataProvider->retrieveObject(fullPath, refpObject);
    00048   }
    00049   return status;
    00050 }
    00051
    00053 StatusCode SmartDataObjectPtr::find(IRegistry* pDirectory, const std::string& path, DataObject*& refpObject)    {
    00054   StatusCode status = StatusCode::FAILURE;
    00055   if ( 0 != m_dataProvider && 0 != pDirectory )    {
    00056     status = m_dataProvider->findObject(pDirectory, path, refpObject);
    00057   }
    00058   return status;
    00059 }
    00060
    00062 StatusCode SmartDataObjectPtr::find(const std::string& fullPath, DataObject*& refpObject)    {
    00063   StatusCode status = StatusCode::FAILURE;
    00064   if ( 0 != m_dataProvider )    {
    00065     status = m_dataProvider->findObject(fullPath, refpObject);
    00066   }
    00067   return status;
    00068 }
    00069
    00070
    00072 StatusCode SmartDataObjectPtr::update(IRegistry* pRegistry)    {
    00073   StatusCode status = StatusCode::FAILURE;
    00074   if ( 0 != m_dataProvider && 0 != pRegistry )    {
    00075     status = m_dataProvider->updateObject(pRegistry);
    00076   }
    00077   return status;
    00078 }
    00079
    00081 StatusCode SmartDataObjectPtr::update(const std::string& fullPath)    {
    00082   StatusCode status = StatusCode::FAILURE;
    00083   if ( 0 != m_dataProvider )    {
    00084     status = m_dataProvider->updateObject(fullPath);
    00085   }
    00086   return status;
    00087 }
    00088
    00094 DataObject* SmartDataObjectPtr::retrieveObject()   {
    00095   DataObject* pObj = 0;
    00096   m_status = (0==m_pRegistry) ? retrieve(m_path,pObj) : retrieve(m_pRegistry,m_path,pObj);
    00097   if ( m_status.isSuccess() )   {
    00098     m_pRegistry = pObj->registry();
    00099     m_path = "";
    00100   }
    00101   return pObj;
    00102 }
    00103
    00109 DataObject* SmartDataObjectPtr::findObject()   {
    00110   DataObject* pObj = 0;
    00111   m_status = (0==m_pRegistry) ? find(m_path,pObj) : find(m_pRegistry,m_path,pObj);
    00112   if ( m_status.isSuccess() )   {
    00113     m_pRegistry = pObj->registry();
    00114     m_path = "";
    00115   }
    00116   return pObj;
    00117 }
    00118
    00124 DataObject* SmartDataObjectPtr::updateObject()   {
    00125   DataObject* pObj = accessData();    // Have to load AND update if not present.
    00126   if ( m_status.isSuccess() )   {
    00127     m_status = (0 == m_pRegistry) ? update(m_path) : update(m_pRegistry);
    00128     if ( !m_status.isSuccess() )  pObj = 0;
    00129   }
    00130   return pObj;
    00131 }
    00132
    00145 bool operator&& (SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2)  {
    00146   if ( 0 != object_1.accessData() )    {      // Test existence of the first object
    00147     if ( 0 != object_2.accessData() )    {    // Test existence of the second object
    00148       return true;                            // Fine: Both objects exist
    00149     }
    00150   }
    00151   return false;                               // Tough luck: One is missing.
    00152 }
    00153
    00170 bool operator|| (SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2)  {
    00171   if ( 0 != object_1.accessData() )    {      // Test existence of the first object
    00172     return true;
    00173   }
    00174   if ( 0 != object_2.accessData() )    {      // Test existence of the second object
    00175     return true;
    00176   }
    00177   return false;                               // Tough luck: Both are missing.
    00178 }
    00179