CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/CondCore/ORA/src/DataElement.cc

Go to the documentation of this file.
00001 #include "DataElement.h"
00002 
00003 ora::DataElement::DataElement():
00004   m_parent(0),
00005   m_children(),
00006   m_declaringScopeOffset(0),
00007   m_offsetFunction(0){
00008 }
00009 
00010 ora::DataElement::DataElement( size_t declaringScopeOffset,
00011                                Reflex::OffsetFunction offsetFunc ):
00012   m_parent(0),
00013   m_children(),
00014   m_declaringScopeOffset(declaringScopeOffset),
00015   m_offsetFunction(offsetFunc){
00016 }
00017 
00018 ora::DataElement::~DataElement(){
00019   for(std::vector<DataElement*>::const_iterator iEl = m_children.begin();
00020       iEl != m_children.end(); ++iEl ){
00021     delete *iEl;
00022   }
00023 }
00024 
00025 ora::DataElement&
00026 ora::DataElement::addChild( size_t declaringScopeOffset,
00027                             Reflex::OffsetFunction offsetFunction ){
00028   DataElement* child = new DataElement( declaringScopeOffset, offsetFunction );
00029   child->m_parent = this;
00030   m_children.push_back(child);
00031   return *child;
00032 }
00033 
00034 size_t ora::DataElement::offset( const void* topLevelAddress ) const {
00035   const void* address = topLevelAddress;
00036   size_t offset = m_declaringScopeOffset;
00037   if(m_parent){
00038     size_t parentOffset = m_parent->offset( topLevelAddress );
00039     offset += parentOffset;
00040     address = static_cast<char*>(const_cast<void*>(topLevelAddress))+parentOffset;
00041   }
00042   if(m_offsetFunction){
00043     offset += m_offsetFunction( const_cast<void*>(address));
00044   }
00045   return offset;  
00046 }
00047 
00048 void* ora::DataElement::address( const void* topLevelAddress ) const {
00049   void* elementAddress = static_cast< char* >( const_cast<void*>(topLevelAddress)) + offset( topLevelAddress );
00050   return elementAddress;
00051 }
00052 
00053 size_t ora::DataElement::declaringScopeOffset() const 
00054 {
00055   return m_declaringScopeOffset;
00056 }
00057 
00058 void ora::DataElement::clear(){
00059   for(std::vector<DataElement*>::const_iterator iEl = m_children.begin();
00060       iEl != m_children.end(); ++iEl ){
00061     delete *iEl;
00062   }
00063   m_children.clear();
00064 }
00065