![]() |
|
|
Generated: 24 Nov 2008 |
00001 // $Id: DataObject.cpp,v 1.11 2008/11/13 15:30:27 marcocle Exp $ 00002 00003 // Experiment specific include files 00004 #include "GaudiKernel/StreamBuffer.h" 00005 #include "GaudiKernel/LinkManager.h" 00006 #include "GaudiKernel/DataObject.h" 00007 #include "GaudiKernel/IInspector.h" 00008 #include "GaudiKernel/IRegistry.h" 00009 #include <vector> 00010 #include <memory> 00011 00012 static std::string _sDataObjectCppNotRegistered("NotRegistered"); 00013 00015 DataObject::DataObject() 00016 : m_refCount(0), 00017 m_version(0), 00018 m_pRegistry(0) 00019 { 00020 m_pLinkMgr = LinkManager::newInstance(); 00021 } 00022 00024 DataObject::DataObject(const DataObject&) 00025 : m_refCount(0), 00026 m_version(0), 00027 m_pRegistry(0) 00028 { 00029 m_pLinkMgr = LinkManager::newInstance(); 00030 } 00031 00033 DataObject::~DataObject() { 00034 // Issue a warning if the object is being deleted and the reference 00035 // count is non-zero. 00036 if ( m_refCount > 0 ) { 00037 // Insert warning here 00038 } 00039 if ( m_pLinkMgr ) delete m_pLinkMgr; 00040 m_pLinkMgr = 0; 00041 } 00042 00044 unsigned long DataObject::release() { 00045 unsigned long cnt = --m_refCount; 00046 if ( 0 == m_refCount ) { 00047 delete this; 00048 } 00049 return cnt; 00050 } 00051 00053 unsigned long DataObject::addRef() { 00054 return ++m_refCount; 00055 } 00056 00058 const CLID& DataObject::clID() const { 00059 return CLID_DataObject; 00060 } 00061 00063 const CLID& DataObject::classID() { 00064 return CLID_DataObject; 00065 } 00066 00068 const std::string& DataObject::name() const { 00069 if( m_pRegistry != 0) { 00070 return m_pRegistry->name(); 00071 } 00072 else { 00073 return _sDataObjectCppNotRegistered; 00074 } 00075 } 00076 00078 StreamBuffer& DataObject::serialize(StreamBuffer& s) { 00079 return s >> m_version; 00080 } 00081 00083 StreamBuffer& DataObject::serialize(StreamBuffer& s) const { 00084 return s << m_version; 00085 } 00086 00087 00088 static DataObject* s_objPtr = 0; 00089 static DataObject** s_currObj = &s_objPtr; 00090 00091 static std::vector<DataObject**>& objectStack() { 00092 static std::auto_ptr<std::vector<DataObject**> > s_current; 00093 if ( 0 == s_current.get() ) { 00094 s_current = std::auto_ptr<std::vector<DataObject**> >(new std::vector<DataObject**>()); 00095 } 00096 return *(s_current.get()); 00097 } 00098 00099 DataObject* Gaudi::getCurrentDataObject() { 00100 return *s_currObj; 00101 } 00102 00103 void Gaudi::pushCurrentDataObject(DataObject** pobjAddr) { 00104 static std::vector<DataObject**>& c = objectStack(); 00105 c.push_back(pobjAddr); 00106 s_currObj = pobjAddr ? pobjAddr : &s_objPtr; 00107 } 00108 00109 00110 void Gaudi::popCurrentDataObject() { 00111 static std::vector<DataObject**>& c = objectStack(); 00112 switch(c.size()) { 00113 case 0: 00114 s_currObj = c.back(); 00115 c.pop_back(); 00116 break; 00117 default: 00118 s_currObj = &s_objPtr; 00119 break; 00120 } 00121 }