Go to the documentation of this file.00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "PVectorHandler.h"
00003 #include "ClassUtils.h"
00004
00005 #include "RVersion.h"
00006
00007 ora::PVectorIteratorHandler::PVectorIteratorHandler( const Reflex::Environ<long>& collEnv,
00008 Reflex::CollFuncTable& collProxy,
00009 const Reflex::Type& iteratorReturnType,
00010 size_t startElement):
00011 m_returnType(iteratorReturnType),
00012 m_collEnv(collEnv),
00013 m_collProxy(collProxy),
00014 m_currentElement(0),
00015 m_startElement(startElement){
00016
00017 m_currentElement = m_collProxy.first_func(&m_collEnv);
00018
00019 if(startElement){
00020 size_t i = 0;
00021 while(i<startElement){
00022 increment();
00023 i++;
00024 }
00025 }
00026 }
00027
00028 ora::PVectorIteratorHandler::~PVectorIteratorHandler(){
00029 }
00030
00031 void
00032 ora::PVectorIteratorHandler::increment(){
00033
00034 m_collEnv.fIdx = 1;
00035 m_currentElement = m_collProxy.next_func(&m_collEnv);
00036 }
00037
00038 void*
00039 ora::PVectorIteratorHandler::object(){
00040 return m_currentElement;
00041 }
00042
00043 Reflex::Type&
00044 ora::PVectorIteratorHandler::returnType(){
00045 return m_returnType;
00046 }
00047
00048 ora::PVectorHandler::PVectorHandler( const Reflex::Type& dictionary ):
00049 m_type( dictionary ),
00050 m_iteratorReturnType(),
00051 m_isAssociative( false ),
00052 m_collEnv(),
00053 m_collProxy(),
00054 m_persistentSizeAttributeOffset(0),
00055 m_vecAttributeOffset(0)
00056 {
00057 Reflex::Member privateVectorAttribute = m_type.DataMemberByName("m_vec");
00058 if(privateVectorAttribute){
00059 m_vecAttributeOffset = privateVectorAttribute.Offset();
00060 Reflex::Member method = privateVectorAttribute.TypeOf().MemberByName("createCollFuncTable");
00061 if(method){
00062 Reflex::CollFuncTable* collProxyPtr;
00063 method.Invoke(collProxyPtr);
00064 m_collProxy.reset( collProxyPtr );
00065 }
00066 if(! m_collProxy.get() ){
00067 throwException( "Cannot find \"createCollFuncTable\" function for type \""+m_type.Name(Reflex::SCOPED)+"\"",
00068 "PVectorHandler::PVectorHandler");
00069 }
00070 }
00071
00072 Reflex::Member persistentSizeAttribute = m_type.DataMemberByName("m_persistentSize");
00073 if( persistentSizeAttribute ){
00074 m_persistentSizeAttributeOffset = persistentSizeAttribute.Offset();
00075 }
00076
00077
00078 Reflex::Type valueType = ClassUtils::containerValueType( m_type );
00079 m_iteratorReturnType = ClassUtils::resolvedType( valueType );
00080 }
00081
00082 ora::PVectorHandler::~PVectorHandler(){
00083 }
00084
00085 size_t
00086 ora::PVectorHandler::size( const void* address ){
00087 m_collEnv.fObject = static_cast<char*>(const_cast<void*>(address))+m_vecAttributeOffset;
00088 size_t transientSize = *(static_cast<size_t*>(m_collProxy->size_func(&m_collEnv)));
00089 return transientSize;
00090 }
00091
00092 size_t
00093 ora::PVectorHandler::startElementIndex( const void* address ){
00094 const void* persistentSizeAddress = static_cast<const char *>(address) + m_persistentSizeAttributeOffset;
00095 size_t persistentSize = *static_cast<const size_t*>(persistentSizeAddress);
00096 size_t transientSize = *(static_cast<size_t*>(m_collProxy->size_func(&m_collEnv)));
00097 size_t startElement = 0;
00098 if(persistentSize < transientSize) startElement = persistentSize;
00099 return startElement;
00100 }
00101
00102 size_t* ora::PVectorHandler::persistentSize( const void* address ){
00103 void* persistentSizeAddress = static_cast<char*>(const_cast<void*>(address))+m_persistentSizeAttributeOffset;
00104 return static_cast<size_t*>(persistentSizeAddress);
00105 }
00106
00107 ora::IArrayIteratorHandler*
00108 ora::PVectorHandler::iterate( const void* address ){
00109 if ( ! m_iteratorReturnType ) {
00110 throwException( "Missing the dictionary information for the value_type member of the container \"" +
00111 m_type.Name(Reflex::SCOPED|Reflex::FINAL) + "\"",
00112 "PVectorHandler" );
00113 }
00114 m_collEnv.fObject = static_cast<char*>(const_cast<void*>(address))+m_vecAttributeOffset;
00115 return new PVectorIteratorHandler( m_collEnv,*m_collProxy,m_iteratorReturnType,startElementIndex(address) );
00116 }
00117
00118 void
00119 ora::PVectorHandler::appendNewElement( void* address, void* data ){
00120 void* dest_address = static_cast<char*>(address)+m_vecAttributeOffset;
00121 #if ROOT_VERSION_CODE < ROOT_VERSION(5,28,0)
00122 m_collEnv.fObject = dest_address;
00123 m_collEnv.fSize = 1;
00124 m_collEnv.fStart = data;
00125 m_collProxy->feed_func(&m_collEnv);
00126 #else
00127 m_collProxy->feed_func(data,dest_address,1);
00128 #endif
00129 }
00130
00131 void
00132 ora::PVectorHandler::clear( const void* address ){
00133 m_collEnv.fObject = static_cast<char*>(const_cast<void*>(address))+m_vecAttributeOffset;
00134 m_collProxy->clear_func(&m_collEnv);
00135 }
00136
00137 Reflex::Type&
00138 ora::PVectorHandler::iteratorReturnType() {
00139 return m_iteratorReturnType;
00140 }
00141
00142 void ora::PVectorHandler::finalize( void* address ){
00143 size_t transSize = size( address );
00144 void* persistentSizeAttributeAddress = static_cast<char*>(address)+m_persistentSizeAttributeOffset;
00145 *static_cast<size_t*>(persistentSizeAttributeAddress) = transSize;
00146 }
00147
00148
00149
00150