11 #ifndef GAUDIKERNEL_IINTERFACE_H 12 #define GAUDIKERNEL_IINTERFACE_H 19 #include <type_traits> 23 #define DeclareInterfaceID( iface, major, minor ) \ 24 static const InterfaceID& interfaceID() { return iid::interfaceID(); } \ 25 using iid = Gaudi::InterfaceId<iface, major, minor>; \ 26 using ext_iids = iid::iids 41 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 44 : m_id( lid & 0xFFFF ), m_major_ver( ( lid & 0xFF000000 ) >> 24 ), m_minor_ver( ( lid & 0xFF0000 ) >> 16 ) {}
46 constexpr
InterfaceID(
unsigned long id,
unsigned long major,
unsigned long minor = 0 )
48 : m_id(
id ), m_major_ver( major ), m_minor_ver( minor ) {}
51 : m_id( hash32(
name ) ), m_major_ver( major ), m_minor_ver( minor ) {}
52 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 53 constexpr
operator unsigned long()
const {
return ( m_major_ver << 24 ) + ( m_minor_ver << 16 ) + m_id; }
56 constexpr
unsigned long id()
const {
return m_id; }
59 constexpr
unsigned long majorVersion()
const {
return m_major_ver; }
61 constexpr
unsigned long minorVersion()
const {
return m_minor_ver; }
75 static unsigned int hash32(
const char* key ) {
76 unsigned int hash = 0;
77 for (
const char* k = key; *k; ++k ) {
79 hash += ( hash << 10 );
80 hash ^= ( hash >> 6 );
82 hash += ( hash << 3 );
83 hash ^= ( hash >> 11 );
84 hash += ( hash << 15 );
96 template <
typename... I>
101 template <
typename T>
107 template <
typename... Is>
110 template <
typename List,
typename I>
115 template <
typename... Is,
typename I>
117 :
id_<std::conditional_t<std::is_base_of_v<id_<I>, inherit_from<id_<Is>...>>, interface_list<Is...>,
118 interface_list<Is..., I>>> {};
120 template <
typename,
typename>
123 template <
typename State>
126 template <
typename... Is,
typename I,
typename List>
131 template <
typename... Is>
136 template <
typename... I>
140 template <
typename... I>
144 template <
typename... I1,
typename... I2>
149 template <
typename... I1,
typename... I2,
typename... Others>
154 template <
typename... I>
157 template <
typename... Is,
typename I>
162 namespace iid_cast_details {
163 template <
typename I>
165 return const_cast<I*>( i );
168 template <
typename... Is>
173 template <
typename P>
179 template <
typename I,
typename... Is>
181 template <
typename P>
183 return tid.
versionMatch( I::interfaceID() ) ? void_cast<typename I::interface_type>( ptr )
189 template <
typename... Is>
194 template <
typename... Is,
typename P>
197 return iid_cast_( tid, ptr );
203 template <
typename INTERFACE,
unsigned long majVers,
unsigned long minVers>
223 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
224 unsigned long minor2>
228 template <
typename IFACE,
unsigned long major,
unsigned long minor>
235 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
236 unsigned long minor2>
240 template <
typename IFACE,
unsigned long major,
unsigned long minor1,
unsigned long minor2>
267 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 277 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 286 virtual unsigned long addRef() = 0;
289 virtual unsigned long release() = 0;
292 virtual unsigned long refCount() const
293 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 295 IInterface* ths = const_cast<IInterface*>(
this );
328 template <
typename TARGET>
330 return reinterpret_cast<TARGET*>( i->
i_cast( TARGET::interfaceID() ) );
334 template <
typename TARGET>
336 return reinterpret_cast<const TARGET*>( i->
i_cast( TARGET::interfaceID() ) );
354 StatusCode sc = i->queryInterface( I::interfaceID(), &ii );
361 s <<
"IID_" <<
id.id();
376 template <
class DEST,
class SRC>
378 return reinterpret_cast<DEST**>( ptr );
385 #endif // GAUDIKERNEL_IINTERFACE_H
std::ostream & operator<<(std::ostream &s, const InterfaceID &id)
ostream operator for InterfaceID. Needed by PluginSvc
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
static unsigned int hash32(const char *key)
Jenkins one-at-time hash function – see https://en.wikipedia.org/wiki/Jenkins_hash_function.
constexpr struct Gaudi::majorMatch_t majorMatch
constexpr bool fullMatch(const InterfaceID &iid) const
check full compatibility.
void * operator()(const InterfaceID &tid, P *ptr) const
constexpr unsigned long id() const
get the interface identifier
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm,...
INTERFACE interface_type
interface type
static constexpr unsigned long majorVersion()
Class to handle automatically the versioning of the interfaces when they are inheriting from other in...
constexpr void * operator()(const InterfaceID &, P *) const
DEST ** pp_cast(SRC **ptr)
Small function to be used instead of the construct (void**)&pointer, which produces,...
constexpr unsigned long majorVersion() const
get the major version of the interface
constexpr bool versionMatch(const InterfaceID &iid) const
check compatibility.
virtual void * i_cast(const InterfaceID &) const =0
main cast function
unsigned long m_minor_ver
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
constexpr bool operator()(InterfaceId< IFACE1, major1, minor1 >, InterfaceId< IFACE2, major2, minor2 >) const
constexpr struct Gaudi::fullMatch_t fullMatch
static std::string name()
constexpr bool operator()(InterfaceId< IFACE, major, minor >, InterfaceId< IFACE, major, minor >) const
static constexpr unsigned long minorVersion()
unsigned long m_major_ver
virtual unsigned long release()=0
Release Interface instance.
constexpr bool operator==(const InterfaceID &iid) const
compare operator
static const InterfaceID & interfaceID()
constexpr bool operator()(InterfaceId< IFACE, major, minor1 >, InterfaceId< IFACE, major, minor2 >) const
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
Gaudi::interface_list< iid > ext_iids
Extra interfaces.
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is... >)
constexpr void * void_cast(const I *i)
constexpr unsigned long minorVersion() const
get the minor version of the interface
TARGET * Cast(IInterface *i)
Cast a IInterface pointer to an IInterface specialization (TARGET).
InterfaceID(const char *name, unsigned long major, unsigned long minor=0)
constructor from components
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is... >, P *ptr)
constexpr bool operator()(InterfaceId< IFACE1, major1, minor1 >, InterfaceId< IFACE2, major2, minor2 >) const
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
typename Gaudi::interface_list_append< typename interface_type::ext_iids, InterfaceId >::type iids
List of interfaces.
Header file for std:chrono::duration-based Counters.
unsigned long code_t
type of StatusCode value
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
static const std::type_info & TypeInfo()