Source

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

// $Id: DataObject.cpp,v 1.11 2008/11/13 15:30:27 marcocle Exp $

// Experiment specific include files
#include "GaudiKernel/StreamBuffer.h"
#include "GaudiKernel/LinkManager.h"
#include "GaudiKernel/DataObject.h"
#include "GaudiKernel/IInspector.h"
#include "GaudiKernel/IRegistry.h"
#include <vector>
#include <memory>

static std::string _sDataObjectCppNotRegistered("NotRegistered");

/// Standard Constructor
DataObject::DataObject()
 : m_refCount(0),
   m_version(0),
   m_pRegistry(0)
{
  m_pLinkMgr = LinkManager::newInstance();
}

/// Standard Constructor
DataObject::DataObject(const DataObject&)
 : m_refCount(0),
   m_version(0),
   m_pRegistry(0)
{
  m_pLinkMgr = LinkManager::newInstance();
}

/// Standard Destructor
DataObject::~DataObject()   {
  // Issue a warning if the object is being deleted and the reference
  // count is non-zero.
  if ( m_refCount > 0 ) {
    // Insert warning here
  }
  if ( m_pLinkMgr ) delete m_pLinkMgr;
  m_pLinkMgr = 0;
}

/// Decrease reference count
unsigned long DataObject::release()  {
  unsigned long cnt = --m_refCount;
  if ( 0 == m_refCount )   {
    delete this;
  }
  return cnt;
}

/// Add reference to object
unsigned long DataObject::addRef()  {
  return ++m_refCount;
}

/// Retrieve Pointer to class definition structure
const CLID& DataObject::clID() const   {
  return CLID_DataObject;
}

/// Retrieve Pointer to class definition structure
const CLID& DataObject::classID()    {
  return CLID_DataObject;
}

/// Retrieve DataObject name. It is the name when included in the store.
const std::string& DataObject::name() const {
  if( m_pRegistry != 0) {
    return m_pRegistry->name();
  }
  else {
    return _sDataObjectCppNotRegistered;
  }
}

/// Provide empty placeholder for internal object reconfiguration callback
StatusCode DataObject::update() {
  return StatusCode::SUCCESS;
}

static DataObject*       s_objPtr = 0;
static DataObject**      s_currObj = &s_objPtr;

static std::vector<DataObject**>& objectStack() {
  static std::auto_ptr<std::vector<DataObject**> > s_current;
  if ( 0 == s_current.get() )  {
    s_current = std::auto_ptr<std::vector<DataObject**> >(new std::vector<DataObject**>());
  }
  return *(s_current.get());
}

DataObject* Gaudi::getCurrentDataObject() {
  return *s_currObj;
}

void Gaudi::pushCurrentDataObject(DataObject** pobjAddr) {
  static std::vector<DataObject**>& c = objectStack();
  c.push_back(pobjAddr);
  s_currObj = pobjAddr ? pobjAddr : &s_objPtr;
}


void Gaudi::popCurrentDataObject() {
  static std::vector<DataObject**>& c = objectStack();
  switch(c.size())  {
  case 0:
    s_currObj = c.back();
    c.pop_back();
    break;
  default:
    s_currObj = &s_objPtr;
    break;
  }
}
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.