ATLAS Offline Software
Loading...
Searching...
No Matches
TPTools/TPTools/ITPConverter.h
Go to the documentation of this file.
1// -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef ATHENAPOOLCNVSVC_ITPConverter_H
8#define ATHENAPOOLCNVSVC_ITPConverter_H 1
9
16
19
20#include <typeinfo>
21#include <typeindex>
22#include <string>
23
24
25class MsgStream;
27
32{
33protected:
35public:
36 virtual ~ITPConverter() = default;
37
45 const TPObjRef::typeID_t& TPtypeID ) = 0;
46
53
57 virtual TopLevelTPCnvBase* topConverter() { return 0; }
58 virtual const TopLevelTPCnvBase* topConverter() const { return 0; }
59
63 virtual const TPObjRef::typeID_t& typeID() const = 0;
64
69 virtual const std::type_info& transBaseTInfo() const = 0;
70
72 virtual void reservePStorage( size_t size ) = 0;
73
82 virtual void converterNotFound( const std::type_info& converterType,
83 ITPConverter *c,
84 const std::string& typeName,
85 MsgStream& log ) const;
86
95 virtual void converterNotFound( unsigned typeID,
96 ITPConverter *c,
97 const std::string& typeName,
98 MsgStream& log ) const;
99};
100
101
102
103
104//-------------- TPConverterTypeMap<CONVERTER_BASE> -------------
105#include <map>
106
111template<class CONVERTER_BASE>
113public:
114 typedef std::map<const std::type_index, CONVERTER_BASE*> TId_Map_t;
115 typedef typename TId_Map_t::iterator iterator;
116
118
123 CONVERTER_BASE * findConverter(const std::type_info &objTypeInfo) const;
124
129 void addConverter(CONVERTER_BASE *converter,
130 const std::type_info &objTypeInfo);
131
133 iterator begin() { return m_cnvRegistry.begin(); }
134
136 iterator end() { return m_cnvRegistry.end(); }
137
138protected:
140};
141
142
143
144
145
146template<class CONVERTER_BASE>
147inline
148CONVERTER_BASE *
150::findConverter(const std::type_info &objTypeInfo) const
151{
152 typename TId_Map_t::const_iterator iter = m_cnvRegistry.find( std::type_index(objTypeInfo) );
153 return (iter == m_cnvRegistry.end())?
154 0 : iter->second;
155}
156
157
158template<class CONVERTER_BASE>
159inline
160void
162::addConverter(CONVERTER_BASE *converter, const std::type_info &objTypeInfo)
163{
164 m_cnvRegistry[std::type_index(objTypeInfo)] = converter;
165}
166
167
168
169#endif
virtual void reservePStorage(size_t size)=0
Reserve 'size' elements for persistent storage.
virtual const TopLevelTPCnvBase * topConverter() const
virtual const std::type_info & transBaseTInfo() const =0
return C++ type id of the common base transient type for all converters for a group of polymorphic ty...
virtual void converterNotFound(const std::type_info &converterType, ITPConverter *c, const std::string &typeName, MsgStream &log) const
method called when the right TP converter was not found during writing
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 TopLevelTPCnvBase * topConverter()
return the top-level converter for this elemental TP 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...
virtual ~ITPConverter()=default
class TPConverterTypeMap Converter registry template: a map from type_info to the appropriate convert...
TId_Map_t m_cnvRegistry
map of the converters, indexed by type_index
void addConverter(CONVERTER_BASE *converter, const std::type_info &objTypeInfo)
Add a new converter to the map.
CONVERTER_BASE * findConverter(const std::type_info &objTypeInfo) const
Find converter for a given C++ type info.
std::map< const std::type_index, CONVERTER_BASE * > TId_Map_t
Base class for top-level TP converters.
This structure holds an ID of a persistent type.
Definition TPObjRef.h:31