| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# LinkManager.cpp

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/LinkManager.cpp,v 1.3 2004/01/23 11:22:04 mato Exp $
    00002
    00003 // Experiment specific include files
    00004 #include "GaudiKernel/LinkManager.h"
    00005 #include "GaudiKernel/DataObject.h"
    00006 #include "GaudiKernel/IRegistry.h"
    00007
    00008 static LinkManager* (*s_newInstance)() = 0;
    00009
    00011 IOpaqueAddress* LinkManager::Link::address() {
    00012   if ( 0 != m_pObject )   {
    00013     IRegistry* pReg = m_pObject->registry();
    00014     if ( 0 != pReg )    {
    00015       return pReg->address();
    00016     }
    00017   }
    00018   return 0;
    00019 }
    00020
    00022 void LinkManager::setInstantiator( LinkManager* (*newInstance)() ) {
    00023   s_newInstance = newInstance;
    00024 }
    00025
    00027 LinkManager* LinkManager::newInstance()  {
    00028   return s_newInstance ? (*s_newInstance)() : new LinkManager();
    00029 }
    00030
    00032 LinkManager::LinkManager()  {
    00033 }
    00034
    00036 LinkManager::~LinkManager()    {
    00037   clearLinks();
    00038 }
    00039
    00041 LinkManager::Link* LinkManager::link(long id)    {
    00042   return (0<=id && (unsigned)id < m_linkVector.size()) ? m_linkVector[id] : 0;
    00043 }
    00044
    00046 LinkManager::Link* LinkManager::link(const DataObject* pObject)  {
    00047   if ( 0 != pObject )   {
    00048     for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
    00049       if ( (*i)->object() == pObject )    {
    00050         return (*i);
    00051       }
    00052     }
    00053   }
    00054   return 0;
    00055 }
    00056
    00058 LinkManager::Link* LinkManager::link(const std::string& path)  {
    00059   if ( 0 != path.length() )   {
    00060     for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
    00061       if ( (*i)->path() == path )    {
    00062         return (*i);
    00063       }
    00064     }
    00065   }
    00066   return 0;
    00067 }
    00068
    00070 long LinkManager::addLink(const std::string& path, const DataObject* pObject)   const   {
    00071   long n = 0;
    00072   for ( LinkVector::const_iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
    00073     Link* lnk = *i;
    00074     const DataObject* pO = lnk->object();
    00075     if ( 0 != pO && pO == pObject )   {
    00076       return n;
    00077     }
    00078     bool same_path = lnk->path() == path;
    00079     if ( same_path ) {
    00080       if ( 0 != pObject && pObject != pO )  {
    00081         lnk->setObject(pObject);
    00082       }
    00083       return n;
    00084     }
    00085     n++;
    00086   }
    00087   // Link is completely unknown
    00088   Link* link = new Link(m_linkVector.size(), path, pObject);
    00089   m_linkVector.push_back( link );
    00090   return link->ID();
    00091 }
    00092
    00093 // Remove a link by object reference
    00094 long LinkManager::removeLink(const DataObject* pObject)  const  {
    00095   long n = 0;
    00096   for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
    00097     if ( (*i)->object() == pObject )    {
    00098       delete (*i);
    00099       m_linkVector.erase(i);
    00100       return n;
    00101     }
    00102     n++;
    00103   }
    00104   return INVALID;
    00105 }
    00106
    00107 // Remove a link by object reference
    00108 long LinkManager::removeLink(const std::string& path)  const  {
    00109   long n = 0;
    00110   for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
    00111     if ( (*i)->path() == path )    {
    00112       delete (*i);
    00113       m_linkVector.erase(i);
    00114       return n;
    00115     }
    00116     n++;
    00117   }
    00118   return INVALID;
    00119 }
    00120
    00121 // Remove a link by object reference
    00122 long LinkManager::removeLink(long id)  const  {
    00123   LinkVector::iterator i = m_linkVector.begin();
    00124   i += id;
    00125   delete (*i);
    00126   m_linkVector.erase(i);
    00127   return id;
    00128   return INVALID;
    00129 }
    00130
    00132 void LinkManager::clearLinks()  {
    00133   for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
    00134     delete (*i);
    00135   }
    00136   m_linkVector.erase(m_linkVector.begin(), m_linkVector.end());
    00137 }