mana-core-gaudikernel / src / Lib / KeyedObject.cpp

// $Id $
// Include files
#include "GaudiKernel/Kernel.h"
#include "GaudiKernel/IRegistry.h"
#include "GaudiKernel/LinkManager.h"
#include "GaudiKernel/GaudiException.h"
#include "GaudiKernel/IDataProviderSvc.h"
#include "GaudiKernel/ObjectContainerBase.h"
#include "GaudiKernel/ContainedObject.h"

/**

  Namespace for basic object handling within container classes

*/
namespace Objects    {
  bool access(const ContainedObject* from, ContainedObject** to);
  bool access(const DataObject* from, DataObject** to);

  template <class TO, class FROM>
  TO* reference(FROM* from)    {
    ContainedObject* to = 0;
    if ( access(from, &to) )    {
      return dynamic_cast<TO*>(to);
    }
    return 0;
  }
}

bool Objects::access(const DataObject* from, DataObject** to)
{
  DataObject* src  = const_cast<DataObject*>(from);
  DataObject* tar = 0;
  if ( src != 0 )
  {
    LinkManager* mgr = src->linkMgr();
    if ( 0 != mgr )
    {
      LinkManager::Link* link = mgr->link(long(0));
      if ( 0 != link )
      {
        tar = link->object();
        if ( 0 == tar )
        {
          IRegistry* reg = src->registry();
          if ( 0 != reg )
          {
            IDataProviderSvc* ds = reg->dataSvc();
            if ( 0 != ds )
            {
              if ( ds->retrieveObject(link->path(), tar).isSuccess() )
              {
                link->setObject(tar);
              }
            }
          }
        }
      }
    }
  }
  *to = tar;
  return tar != 0;
}

// Load on demand: ContainedObject type references
bool Objects::access(const ContainedObject* from, ContainedObject** to)
{
  *to = 0;
  if ( from )
  {
    DataObject *tar = 0;
    if ( access(from->parent(), &tar) )
    {
      ObjectContainerBase* cnt = dynamic_cast<ObjectContainerBase*>(tar);
      if ( cnt )
      {
        *to = cnt->containedObject(from->index());
      }
    }
  }
  return (*to) != 0;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.