|
ATLAS Offline Software
|
Go to the documentation of this file.
17 #include "GaudiKernel/System.h"
20 #include <unordered_map>
35 bool is_virtual =
false);
70 typedef std::pair<const std::type_info*, const CopyConversionBase*>
88 typedef std::unordered_multimap<
const std::type_info*,
122 if (
i.first == &tinfo)
129 if (strcmp (
i.first->name(), tinfo.name()) == 0)
170 return this->
cast (p, *ti);
186 return converter (
p);
205 return this->
castTo (p, *ti);
222 return converterTo (
p);
240 return this->
castfn (*ti);
259 return i->m_converter;
295 return i->m_converterTo;
310 v.reserve (map.size());
311 for (
const auto&
p : map) {
313 if (
clid != CLID_NULL)
330 std::vector<const std::type_info*>
v;
331 v.reserve (map.size());
332 for (
const auto&
i : map)
333 v.push_back (
i.first);
393 return i->m_is_virtual;
409 if (
p.first == &tinfo)
458 std::vector<CLID>
out;
462 if (
clid != CLID_NULL)
481 castfn_t* converterTo,
493 auto i = BaseInfoBaseImpl::s_bi_by_ti->find (&tinfo);
494 if (
i != BaseInfoBaseImpl::s_bi_by_ti->
end()) {
496 if (
impl.m_clid == CLID_NULL)
517 : m_converter (converter),
518 m_converterTo (converterTo),
519 m_is_virtual (is_virtual)
536 if (!BaseInfoBaseImpl::s_bi_by_ti)
538 if (!BaseInfoBaseImpl::s_ti_by_name)
542 (*BaseInfoBaseImpl::s_bi_by_ti)[&tinfo] =
this;
543 (*BaseInfoBaseImpl::s_ti_by_name)[tinfo.name()] = &tinfo;
590 if (!BaseInfoBaseImpl::s_bi_by_ti)
return 0;
592 BaseInfoBaseImpl::s_bi_by_ti->find (&tinfo);
593 if (
i != BaseInfoBaseImpl::s_bi_by_ti->
end()) {
607 if (!BaseInfoBaseImpl::s_init_list)
break;
609 BaseInfoBaseImpl::s_bi_by_ti->find (&tinfo);
610 if (
i != BaseInfoBaseImpl::s_bi_by_ti->
end())
613 BaseInfoBaseImpl::s_init_list->find (&tinfo);
614 if (
it == BaseInfoBaseImpl::s_init_list->
end())
break;
616 BaseInfoBaseImpl::s_init_list->erase (
it);
640 const std::type_info* tinfo2 =
nullptr;
643 if (BaseInfoBaseImpl::s_ti_by_name) {
645 BaseInfoBaseImpl::s_ti_by_name->find (tinfo.name());
646 if (
i != BaseInfoBaseImpl::s_ti_by_name->
end() &&
i->second != &tinfo) {
652 bib =
find1 (*tinfo2);
659 if (
impl.m_clid == CLID_NULL)
673 init_func_t* init_func)
676 if (!BaseInfoBaseImpl::s_init_list)
677 BaseInfoBaseImpl::s_init_list =
679 BaseInfoBaseImpl::s_init_list->insert (std::make_pair (tinfo, init_func));
681 if (BaseInfoBaseImpl::s_bi_by_ti) {
682 auto i = BaseInfoBaseImpl::s_bi_by_ti->find (tinfo);
683 if (
i != BaseInfoBaseImpl::s_bi_by_ti->
end()) {
686 impl.m_needs_init =
true;
687 if (
impl.m_clid == CLID_NULL)
704 bool needs_init =
false;
705 const std::type_info* ti =
nullptr;
738 std::cout <<
"map:\n";
739 if (BaseInfoBaseImpl::s_bi_by_ti) {
740 std::vector<const std::type_info*>
vv;
741 for (
const auto&
x : *BaseInfoBaseImpl::s_bi_by_ti)
742 vv.push_back (
x.first);
743 std::sort (
vv.begin(),
vv.end());
744 for (
const std::type_info* ti :
vv)
746 const BaseInfoBase* bib = (*BaseInfoBaseImpl::s_bi_by_ti)[ti];
752 std::cout <<
"\ninitlist:\n";
753 if (BaseInfoBaseImpl::s_init_list) {
754 for (
const auto&
x : *BaseInfoBaseImpl::s_init_list)
755 std::cout <<
x.first <<
" " <<
x.second <<
" ["
JetConstituentVector::iterator iterator
static BaseInfoBase * find1(const std::type_info &tinfo)
Helper for find.
std::pair< const std::type_info *, const CopyConversionBase * > ti_copyconversion_pair_type
Hold copy conversion information indexed by @ type_info.
std::vector< ti_copyconversion_pair_type > ti_copyconversion_type
std::mutex mutex_t
For thread-safety.
const T * ptr() const
Return a pointer to the cached value.
static CLID typeinfoToCLID(const std::type_info &ti)
Return the CLID corresponding to a type_info.
CxxUtils::CachedValue< std::vector< CLID > > m_bases
CLIDs of known bases, including the class itself.
bool isValid() const
Test to see if the value is valid.
std::unordered_multimap< const std::type_info *, BaseInfoBase::init_func_t * > init_list_t
Holds BaseInfo classes awaiting initialization.
~BaseInfoBase()
Destructor.
void maybeInit()
Run initializations for this class, if needed.
static ti_by_name_map_type *s_ti_by_name ATLAS_THREAD_SAFE
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
void init_func_t(BaseInfoBase *bib)
Type for an initialization function.
std::vector< const std::type_info * > get_ti_bases() const
Return the type_info's of all known bases of T.
castfn_t * castfnTo(CLID clid) const
Return a function for casting to a derived pointer.
ti_copyconversion_type m_ti_copyconversion_map
const std::vector< CLID > & get_bases() const
Return the class IDs of all known bases of T (that have class IDs).
static void addInit(const std::type_info *tinfo, init_func_t *init_func)
Register an initialization function.
void * cast(void *p, CLID clid) const
Cast to a base pointer.
BaseInfoBaseImpl * m_impl
Pointer to internal state.
std::string typeinfoName(const std::type_info &ti)
Convert a type_info to a demangled string.
std::unordered_map< const std::type_info *, BaseInfoBase * > bi_by_ti_map_type
Map of all type_info pointers to BaseInfoBase instances.
Base class for copy conversions.
Provide an interface for finding inheritance information at run time.
BaseInfoBase::castfn_t * m_converter
Converter function.
const std::type_info * m_typeinfo
std::type_info of this class.
BaseInfoBase::castfn_t * m_converterTo
Converter function.
Cached value with atomic update.
std::vector< CLID > get_copy_conversions() const
Return known copy conversions.
const CopyConversionBase * copy_conversion(const std::type_info &tinfo) const
Search for a copy conversion to tinfo.
static bi_by_ti_map_type *s_bi_by_ti ATLAS_THREAD_SAFE
void * castTo(void *p, CLID clid) const
Cast to a derived pointer.
std::vector< ti_map_pair_type > ti_map_type
uint32_t CLID
The Class ID type.
std::unordered_map< std::string, const std::type_info * > ti_by_name_map_type
Used to canonicalize type_info instances.
void * castfn_t(void *p)
Type of a pointer conversion function.
info(BaseInfoBase::castfn_t *converter=0, BaseInfoBase::castfn_t *converterTo=0, bool is_virtual=false)
Constructor. converter* and is_virtual are as for add_info.
BaseInfoBase(const std::type_info &tinfo)
Constructor.
CLID clid() const
Return the CLID for this class.
Cached value with atomic update.
static const BaseInfoBase * find(CLID clid)
Find the BaseInfoBase instance for clid.
static mutex_t s_mutex ATLAS_THREAD_SAFE
void set(const T &val) const
Set the value, assuming it is currently invalid.
def init(v_theApp, v_rootStream=None)
Structure to hold information about one base.
a static registry of CLID->typeName entries. NOT for general use. Use ClassIDSvc instead.
bool m_is_virtual
True if the derivation from this base to T is via virtual derivation.
The non-template portion of the BaseInfo implementation.
bool is_virtual(CLID clid) const
Return true if clid is the ID of a class that is known to be a virtual base of T.
static init_list_t *s_init_list ATLAS_THREAD_SAFE
const info * findInfo(const std::type_info &tinfo) const
Find a base by type_info.
const std::type_info & typeinfo() const
Return the std::type_info for this class.
castfn_t * castfn(CLID clid) const
Return a function for casting to a base pointer.
CLID m_clid
CLID of this class.
std::pair< const std::type_info *, info > ti_map_pair_type
Hold base information indexed by type_info.
void add_info(const std::type_info &tinfo, castfn_t *converter, castfn_t *converterTo, bool is_virtual)
Add information about one base class.
void add_copy_conversion(const std::type_info &tinfo, const CopyConversionBase *cnv)
Add a new copy conversion.
std::lock_guard< mutex_t > lock_t
bool m_needs_init
Set to true when first created.
bool is_base(CLID clid) const
Return true if clid is the ID of a class that is known to be a base of T.