Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

DataObject.cpp

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GaudiKernel/src/Lib/DataObject.cpp,v 1.1.1.1 2001/04/18 18:14:18 tlindner Exp $
00002 
00003 // Experiment specific include files
00004 #include "GaudiKernel/DataObject.h"
00005 #include "GaudiKernel/StreamBuffer.h"
00006 #include "GaudiKernel/IInspector.h"
00007 
00008 static std::string _sDataObjectCppNotRegistered("NotRegistered");
00009 
00011 IOpaqueAddress* DataObject::Link::address() {
00012   if ( 0 != m_pObject )   {
00013     if ( 0 != m_pObject->directory() )    {
00014       return m_pObject->directory()->address();
00015     }
00016   }
00017   return 0;
00018 }
00019 
00021 DataObject::DataObject(const std::string&)
00022  : m_pDirectory(0),
00023    m_refCount(0),
00024    m_version(0),
00025    m_isLocked( false )
00026 {
00027 }
00028 
00030 DataObject::~DataObject()   {
00031 
00032   // Issue a warning if the object is being deleted and the reference
00033   // count is non-zero.
00034   if ( m_refCount > 0 ) {
00035     // Insert warning here
00036   }
00037   clearLinks();
00038 }
00039 
00041 unsigned long DataObject::release()  {
00042   unsigned long cnt = --m_refCount;
00043   if ( 0 == m_refCount )   {
00044     delete this;
00045   }
00046   return cnt;
00047 }
00048 
00050 unsigned long DataObject::addRef()  {
00051   return ++m_refCount;
00052 }
00053 
00055 unsigned long DataObject::refCount()    const   {
00056   return m_refCount;
00057 }
00058 
00060 void DataObject::setDirectory(IDataDirectory* dir)    {
00061   m_pDirectory = dir;
00062 }
00063 
00065 IDataDirectory* DataObject::directory()   {
00066   return m_pDirectory;
00067 }
00068 
00070 const IDataDirectory* DataObject::directory()  const  {
00071   return m_pDirectory;
00072 }
00073 
00075 TransientStore* DataObject::store()   {
00076   return (0 == m_pDirectory) ? 0 : m_pDirectory->store();  
00077 }
00078 
00080 const TransientStore* DataObject::store()   const {
00081   return (0 == m_pDirectory) ? 0 : m_pDirectory->store();  
00082 }
00083 
00085 IOpaqueAddress* DataObject::address()   {
00086   return (0 == m_pDirectory) ? 0 : m_pDirectory->address();  
00087 }
00088 
00090 const IOpaqueAddress* DataObject::address()  const    {
00091   return (0 == m_pDirectory) ? 0 : m_pDirectory->address();
00092 }
00093 
00095 DataObject::DirIterator DataObject::dirBegin()   {
00096   return (0 == m_pDirectory) ? 0 : m_pDirectory->begin();
00097 }
00098 
00100 DataObject::ConstDirIterator DataObject::dirBegin()    const  {
00101   return (0 == m_pDirectory) ? 0 : m_pDirectory->begin();
00102 }
00103 
00105 DataObject::DirIterator DataObject::dirEnd()   {
00106   return (0 == m_pDirectory) ? 0 : m_pDirectory->end();
00107 }
00108 
00110 DataObject::ConstDirIterator DataObject::dirEnd()      const  {
00111   return (0 == m_pDirectory) ? 0 : m_pDirectory->end();
00112 }
00113 
00115 DataObject::LinkIterator DataObject::linkBegin()   {
00116   return m_linkVector.begin();
00117 }
00118 
00120 DataObject::ConstLinkIterator DataObject::linkBegin()    const  {
00121   return m_linkVector.begin();
00122 }
00123 
00125 DataObject::LinkIterator DataObject::linkEnd()   {
00126   return m_linkVector.end();
00127 }
00128 
00130 DataObject::ConstLinkIterator DataObject::linkEnd()      const  {
00131   return m_linkVector.end();
00132 }
00133 
00135 size_t DataObject::linkSize()    const   {
00136   return m_linkVector.size();
00137 }
00138 
00140 DataObject::Link* DataObject::symLink(long id)    {
00141   return (0<=id && (unsigned)id < m_linkVector.size()) ? m_linkVector[id] : 0;
00142 }
00143 
00145 DataObject::Link* DataObject::symLink(DataObject* pObject)  {
00146   if ( 0 != pObject )   {
00147     for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
00148       if ( (*i)->object() == pObject )    {
00149         return (*i);
00150       }
00151     }
00152   }
00153   return 0;
00154 }
00155 
00157 DataObject::Link* DataObject::symLink(const std::string& path)  {
00158   if ( 0 != path.length() )   {
00159     for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
00160       if ( (*i)->path() == path )    {
00161         return (*i);
00162       }
00163     }
00164   }
00165   return 0;
00166 }
00167 
00169 DataObject* DataObject::parent()    {
00170   if ( m_pDirectory != 0)   {
00171     IDataDirectory* pDirectory = m_pDirectory->parent();
00172     if ( 0 != pDirectory )    {
00173       return pDirectory->object();
00174     }
00175   }
00176   return 0;
00177 }
00178 
00180 const DataObject* DataObject::parent()   const  {
00181   if ( m_pDirectory != 0)   {
00182     const IDataDirectory* pDirectory = m_pDirectory->parent();
00183     if ( 0 != pDirectory )    {
00184       return pDirectory->object();
00185     }
00186   }
00187   return 0;
00188 }
00189 
00191 DataObject* DataObject::find(const std::string& path)    {
00192   if ( m_pDirectory != 0)   {
00193     IDataDirectory* pDirectory = (path.length() == 0) ? m_pDirectory->find(path) : m_pDirectory;
00194     if ( 0 != pDirectory )    {
00195       return pDirectory->object();
00196     }
00197   }
00198   return 0;
00199 }
00200 
00202 const DataObject* DataObject::find(const std::string& path)  const   {
00203   if ( m_pDirectory != 0)   {
00204     const IDataDirectory* pDirectory = (path.length() == 0) ? m_pDirectory->find(path) : m_pDirectory;
00205     if ( 0 != pDirectory )    {
00206       return pDirectory->object();
00207     }
00208   }
00209   return 0;
00210 }
00211 
00213 IDataDirectory* DataObject::leaf(const std::string& path)    {
00214   if ( m_pDirectory != 0)   {
00215     IDataDirectory* pDirectory = (path.length() == 0) ? m_pDirectory->find(path) : m_pDirectory;
00216     return pDirectory;
00217   }
00218   return 0;
00219 }
00220 
00222 const IDataDirectory* DataObject::leaf(const std::string& path)   const  {
00223   if ( m_pDirectory != 0)   {
00224     IDataDirectory* pDirectory = (path.length() == 0) ? m_pDirectory->find(path) : m_pDirectory;
00225     return pDirectory;
00226   }
00227   return 0;
00228 }
00229 
00231 const CLID& DataObject::clID() const   {
00232   return CLID_DataObject;
00233 }
00234 
00236 const CLID& DataObject::classID()    {
00237   return CLID_DataObject;
00238 }
00239 
00241 const unsigned char DataObject::version()    const   {
00242   return m_version;
00243 }
00244 
00246 void DataObject::setVersion(unsigned char vsn)   {
00247   m_version = vsn;
00248 }
00249 
00251 const std::string& DataObject::localPath() const {
00252   if( m_pDirectory != 0) {
00253     return m_pDirectory->name();
00254   }
00255   else {
00256     return _sDataObjectCppNotRegistered;
00257   }
00258 }
00259 
00261 const std::string& DataObject::location() const {
00262   if( m_pDirectory != 0) {
00263     return m_pDirectory->location();
00264   }
00265   else {
00266     return _sDataObjectCppNotRegistered;
00267   }
00268 }
00269 
00271 const std::string& DataObject::fullpath() const {
00272   if( m_pDirectory != 0) {
00273     return m_pDirectory->fullpath();
00274   }
00275   else {
00276     return _sDataObjectCppNotRegistered;
00277   }
00278 }
00279 
00281 long DataObject::addLink(const std::string& path, const DataObject* pObject)   const   {
00282   long n = 0;
00283   for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
00284     const DataObject* pO = (*i)->object();
00285     if ( 0 != pO && pO == pObject )   {
00286       return n;
00287     }
00288     else if ( 0 != pObject && pObject != pO && (*i)->path() == path )   {
00289       (*i)->set(pObject);
00290       return n;
00291     }
00292     else if ( (*i)->path() == path )  {
00293       return n;
00294     }
00295     n++;
00296   }
00297   // Link is completely unknown
00298   Link* link = new Link(m_linkVector.size(), path, pObject);
00299   m_linkVector.push_back( link );
00300   return link->ID();
00301 }
00302 
00303 // Remove a link by object reference
00304 long DataObject::removeLink(const DataObject* pObject)  const  {
00305   long n = 0;
00306   for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
00307     if ( (*i)->object() == pObject )    {
00308       delete (*i);
00309       m_linkVector.erase(i);
00310       return n;
00311     }
00312     n++;
00313   }
00314   return INVALID;
00315 }
00316 
00317 // Remove a link by object reference
00318 long DataObject::removeLink(const std::string& path)  const  {
00319   long n = 0;
00320   for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
00321     if ( (*i)->path() == path )    {
00322       delete (*i);
00323       m_linkVector.erase(i);
00324       return n;
00325     }
00326     n++;
00327   }
00328   return INVALID;
00329 }
00330 
00331 // Remove a link by object reference
00332 long DataObject::removeLink(long id)  const  {
00333   LinkVector::iterator i = m_linkVector.begin();
00334   i += id;
00335   delete (*i);
00336   m_linkVector.erase(i);
00337   return id;
00338   return INVALID;
00339 }
00340 
00342 void DataObject::clearLinks()  {
00343   for ( LinkVector::iterator i = m_linkVector.begin(); i != m_linkVector.end(); i++ )   {
00344     delete (*i);
00345   }
00346   m_linkVector.erase(m_linkVector.begin(), m_linkVector.end());
00347 }
00348 
00350 StreamBuffer& DataObject::serialize(StreamBuffer& s)   {
00351   return s >> m_version;
00352 }
00353 
00355 StreamBuffer& DataObject::serialize(StreamBuffer& s)  const    {
00356   return s << m_version;
00357 }
00358 
00360 bool DataObject::acceptInspector(IInspector* /* pInspector */ )    {
00361   /*
00362   pInspector->inspectByValue (clID(),     this, "clID");
00363   pInspector->inspectByRef(&m_version,    this, "version");
00364   pInspector->inspectByRef(&m_refCount,   this, "refCount");
00365   pInspector->inspectByRef(m_pDirectory,  this, "directory");
00366   pInspector->inspectContByRef(&m_linkVector, this, ".linkVector");
00367   */
00368   return true;
00369 }
00370 
00372 bool DataObject::acceptInspector(IInspector* /* pInspector */ )  const  {
00373   /*
00374   pInspector->inspectByValue (clID(),     this, "clID");
00375   pInspector->inspectByRef(&m_version,    this, "version");
00376   pInspector->inspectByRef(&m_refCount,   this, "refCount");
00377   pInspector->inspectByRef(m_pDirectory,  this, "directory");
00378   pInspector->inspectContByRef(&m_linkVector, this, ".linkVector");
00379   */
00380   return true;
00381 }
00382 
00383 bool DataObject::isLocked( ) const
00384 {
00385     return m_isLocked;
00386 }
00387 
00388 StatusCode DataObject::setLocked( )
00389 {
00390     m_isLocked = true;
00391     return StatusCode::SUCCESS;
00392 }
00393 
00394 StatusCode DataObject::setUnlocked( )
00395 {
00396     m_isLocked = false;
00397     return StatusCode::SUCCESS;
00398 }

Generated at Wed Nov 21 12:22:03 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000