CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataElement.cc
Go to the documentation of this file.
1 #include "DataElement.h"
2 #include <stddef.h> /* offsetof */
3 
5  m_parent(0),
6  m_children(),
7  m_declaringScopeOffset(0),
8  /*m_offsetFunction(0)*/ m_offset(0){
9 }
10 
11 ora::DataElement::DataElement( size_t declaringScopeOffset,
12  size_t /*offsetFunc*/ offset ):
13  m_parent(0),
14  m_children(),
15  m_declaringScopeOffset(declaringScopeOffset),
16  /*m_offsetFunction(offsetFunc)*/ m_offset(offset){
17 }
18 
20  for(std::vector<DataElement*>::const_iterator iEl = m_children.begin();
21  iEl != m_children.end(); ++iEl ){
22  delete *iEl;
23  }
24 }
25 
27 ora::DataElement::addChild( size_t declaringScopeOffset,
28  size_t /*offsetFunction*/ offset ){
29  DataElement* child = new DataElement( declaringScopeOffset, /*offsetFunction*/ offset );
30  child->m_parent = this;
31  m_children.push_back(child);
32  return *child;
33 }
34 
35 size_t ora::DataElement::offset( const void* topLevelAddress ) const {
36  //const void* address = topLevelAddress;
37  size_t offset = m_declaringScopeOffset;
38  if(m_parent){
39  size_t parentOffset = m_parent->offset( topLevelAddress );
40  offset += parentOffset;
41  //address = static_cast<char*>(const_cast<void*>(topLevelAddress))+parentOffset;
42  }
43  if(/*m_offsetFunction*/ m_offset){
44  offset += /*m_offsetFunction( const_cast<void*>(address))*/ m_offset;
45  }
46  return offset;
47 }
48 
49 void* ora::DataElement::address( const void* topLevelAddress ) const {
50  void* elementAddress = static_cast< char* >( const_cast<void*>(topLevelAddress)) + offset( topLevelAddress );
51  return elementAddress;
52 }
53 
55 {
56  return m_declaringScopeOffset;
57 }
58 
60  for(std::vector<DataElement*>::const_iterator iEl = m_children.begin();
61  iEl != m_children.end(); ++iEl ){
62  delete *iEl;
63  }
64  m_children.clear();
65 }
66 
void * address(const void *topLevelAddress) const
Definition: DataElement.cc:49
virtual ~DataElement()
Definition: DataElement.cc:19
size_t declaringScopeOffset() const
Definition: DataElement.cc:54
size_t offset(const void *topLevelAddress) const
Definition: DataElement.cc:35
DataElement & addChild(size_t declaringScopeOffset, size_toffset)
Definition: DataElement.cc:27
const DataElement * m_parent
Definition: DataElement.h:26