ATLAS Offline Software
TypeConverter.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
6 /**
7  * @file D3PDMakerUtils/TypeConverter.icc
8  * @author scott snyder <snyder@bnl.gov>
9  * @date Aug, 2009
10  * @brief Template and inline definitions for TypeConverter.
11  */
12 
13 
14 namespace D3PD {
15 
16 
17 /**
18  * @brief Alternate form of @c init, passing the destination
19  * type as a template argument.
20  * @param src_ti The source type for the conversion.
21  *
22  * The types should be for the pointer value types.
23  * I.e, if we want to convert from T* to U*,
24  * pass typeid(T) as @c src_ti and @c U as the template argument.
25  *
26  * Returns @c FAILURE if the conversion is not allowable.
27  * Either derived -> base or base -> derived conversions are allowed.
28  */
29 template <typename T>
30 StatusCode TypeConverter::init (const std::type_info& src_ti)
31 {
32  return this->init (src_ti, typeid(T));
33 }
34 
35 
36 /**
37  * @brief Convert pointer.
38  * @param The pointer to convert, as a pointer to the source type.
39  * @return The converted pointer, as a @c T*.
40  *
41  * @c T must be the same as the previously configured destination type.
42  *
43  * Will return 0 if the converter isn't properly initialized, or if
44  * the conversion fails (for a base -> derived conversion).
45  */
46 template <class T>
47 const T* TypeConverter::convert (const void* p) const
48 {
49  assert (typeid(T) == *m_dstTypeinfo);
50  return reinterpret_cast<const T*> (convertUntyped (p));
51 }
52 
53 
54 /**
55  * @brief Test to see if this converter has been properly initialized.
56  */
57 inline
58 bool TypeConverter::isValid() const
59 {
60  return m_strategy != INVALID;
61 }
62 
63 
64 /**
65  * @brief Return the configured source type.
66  */
67 inline
68 const std::type_info& TypeConverter::srcTypeinfo() const
69 {
70  return *m_srcTypeinfo;
71 }
72 
73 
74 /**
75  * @brief Return the configured destination type.
76  */
77 inline
78 const std::type_info& TypeConverter::dstTypeinfo() const
79 {
80  return *m_dstTypeinfo;
81 }
82 
83 
84 } // namespace D3PD