ATLAS Offline Software
Loading...
Searching...
No Matches
TopLevelTPCnvBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
8#include <stdexcept>
9
10
12{
13 addTPConverterForWriting( converter );
14 addTPConverterForReading( converter );
15}
16
17
18
20{
21 // for reading, converters are selected based on their typeID value
22 // which comes from the Ref
23 // Ref contains top level converter ID + local type ID
25 m_convIdMap[ full_typeID.value() ] = converter;
26
27// std::cout << " **addTPConverter - adding converter for " << converter->transientTInfo().name() << " CnvID=" << full_typeID.value() << std::endl;
28 converter->setTopConverter( this, full_typeID );
29}
30
31
32
34{
35 // add converter to the map keyed by type_info
36 // this map is used to find a converter when writing
37 const std::type_info &info( converter->transientTInfo() );
38 if( m_converters.findConverter( info ) ) {
39 // adding a second converter for the same type will mess up things
40 const std::string error("Duplicate TP converter for class ");
41 throw std::runtime_error( error + info.name() );
42 }
43 m_converters.addConverter( converter, info );
44}
45
46
49 // for reading, converters are selected based on our own typeID value
50 // which comes from the Ref
51 // Ref contains top level converter ID + local type ID
52 m_convIdMap[ converter->typeID().value() ] = converter;
53
54// std::cout << " **addExtTPConverterForReading - adding converter for " << converter->transientTInfo().name() << " CnvID=" << converter->typeID().value() << std::endl;
55 converter->setRuntimeTopConverter( this );
56}
57
58
61{
62 // loop over all registered converters
63 for( convIdMap_t::const_iterator itr = m_convIdMap.begin();
64 itr != m_convIdMap.end(); ++itr ) {
65 // check if the converter is in the list of R/W converters
66 if( m_converters.findConverter( itr->second->transientTInfo() ) == itr->second ) {
67 // this is a R/W converter, add it for writing too
68 cnv->addTPConverterForWriting( itr->second );
69 }
70 // add the convterter for reading
71 cnv->addExtTPConverterForReading( itr->second );
72 }
73 // prevent adding of the same converter again
74 cnv->rememberConverter( this );
75}
76
77
79{
80 // check if we have done this already, and if so then exit
81 if( cnv->hasConvertersFrom( this ) ) {
82 return;
83 }
84 // copy all TP converters to another topLevel conveter
85 for( convIdMap_t::const_iterator itr = m_convIdMap.begin();
86 itr != m_convIdMap.end(); ++itr ) {
87 cnv->addExtTPConverterForReading( itr->second );
88 }
89 // prevent attempts to add the same converters again
90 cnv->rememberConverter( this );
91}
92
93
Defines the base class for top-level TP converters.
virtual const std::type_info & transientTInfo() const =0
return C++ type id of the transient class this converter is for
Base interface class for all TP converters - typeless.
virtual void setRuntimeTopConverter(TopLevelTPCnvBase *topConverter)=0
Set runtime top-level converter - usually it is the owning TL converter, but in case of extended obje...
virtual const TPObjRef::typeID_t & typeID() const =0
Return TP typeID for persistent objects produced by this converter.
virtual void setTopConverter(TopLevelTPCnvBase *topConverter, const TPObjRef::typeID_t &TPtypeID)=0
Set which top-level converter owns this elemental converter, and what TPtypeID was assigned to the pe...
void addConverter(CONVERTER_BASE *converter, const std::type_info &objTypeInfo)
Add a new converter to the map.
Base class for top-level TP converters.
virtual void addTPConverterForReading(ITPConverter *cnv)
Add a TP converter to this top level converter but only for reading.
virtual void addTPConvertersForReadingTo(TopLevelTPCnvBase *dest)
copy all extending converters from this top level converter to "dest" top level converter - for readi...
virtual void addExtTPConverterForReading(ITPConverter *cnv)
add extending TP converter to this top level converter - to the list consulted when reading only.
virtual void addTPConverter(ITPConverter *cnv)
Add a TP converter to this top level converter.
virtual void addTPConvertersTo(TopLevelTPCnvBase *dest)
copy all extending converters from this top level converter to "dest" top level converter
convIdMap_t m_convIdMap
Map of elemental TP converters indexed by their ID - used for reading.
virtual unsigned short getConverterID()=0
virtual void addTPConverterForWriting(ITPConverter *cnv)
add TP converter to the list of converters consulted when writing - internal method.
void rememberConverter(TopLevelTPCnvBase *cnv)
Remember that elemental TP converters from the given top-level converter are already registered.
bool hasConvertersFrom(TopLevelTPCnvBase *cnv)
Check if TP converters from a given top-level converter were already registered in this converter.
TPConverterTypeMap< ITPConverter > m_converters
Map of elemental TP converters indexed by transient typeid - used for writing.
unsigned m_typeIDCount
Counter used to create typed IDs used in the transient Ref.
This structure holds an ID of a persistent type.
Definition TPObjRef.h:31
unsigned value() const
Returns the type ID as an integer.
Definition TPObjRef.h:46