1 #ifndef GAUDIKERNEL_IINTERFACE_H 2 #define GAUDIKERNEL_IINTERFACE_H 13 #define DeclareInterfaceID( iface, major, minor ) \ 14 static const InterfaceID& interfaceID() { return iid::interfaceID(); } \ 15 using iid = Gaudi::InterfaceId<iface, major, minor>; \ 16 using ext_iids = iid::iids 31 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 34 : m_id( lid & 0xFFFF ), m_major_ver( ( lid & 0xFF000000 ) >> 24 ), m_minor_ver( ( lid & 0xFF0000 ) >> 16 ) {}
36 constexpr InterfaceID(
unsigned long id,
unsigned long major,
unsigned long minor = 0 )
38 : m_id(
id ), m_major_ver( major ), m_minor_ver( minor ) {}
41 : m_id( hash32( name ) ), m_major_ver( major ), m_minor_ver( minor ) {}
42 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 43 constexpr
operator unsigned long()
const {
return ( m_major_ver << 24 ) + ( m_minor_ver << 16 ) + m_id; }
46 constexpr
unsigned long id()
const {
return m_id; }
49 constexpr
unsigned long majorVersion()
const {
return m_major_ver; }
51 constexpr
unsigned long minorVersion()
const {
return m_minor_ver; }
59 constexpr
bool fullMatch(
const InterfaceID& iid )
const {
63 constexpr
bool operator==(
const InterfaceID& iid )
const {
return fullMatch( iid ); }
65 static unsigned int hash32(
const char* key ) {
66 unsigned int hash = 0;
67 for (
const char* k = key; *k; ++k ) {
69 hash += ( hash << 10 );
70 hash ^= ( hash >> 6 );
72 hash += ( hash << 3 );
73 hash ^= ( hash >> 11 );
74 hash += ( hash << 15 );
86 template <
typename... I>
97 template <
typename... Is>
100 template <
typename List,
typename I>
105 template <
typename... Is,
typename I>
107 :
id_<typename std::conditional<std::is_base_of<id_<I>, inherit_from<id_<Is>...>>::value,
108 interface_list<Is...>, interface_list<Is..., I>>::type> {};
110 template <
typename,
typename>
113 template <
typename State>
116 template <
typename... Is,
typename I,
typename List>
121 template <
typename... Is>
126 template <
typename... I>
130 template <
typename... I>
134 template <
typename... I1,
typename... I2>
139 template <
typename... I1,
typename... I2,
typename... Others>
144 template <
typename... I>
147 template <
typename... Is,
typename I>
152 namespace iid_cast_details {
153 template <
typename I>
155 return const_cast<I*
>( i );
158 template <
typename... Is>
163 template <
typename P>
169 template <
typename I,
typename... Is>
171 template <
typename P>
179 template <
typename... Is>
184 template <
typename... Is,
typename P>
187 return iid_cast_( tid, ptr );
193 template <
typename INTERFACE,
unsigned long majVers,
unsigned long minVers>
213 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
214 unsigned long minor2>
218 template <
typename IFACE,
unsigned long major,
unsigned long minor>
225 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
226 unsigned long minor2>
230 template <
typename IFACE,
unsigned long major,
unsigned long minor1,
unsigned long minor2>
257 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 267 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 276 virtual unsigned long addRef() = 0;
279 virtual unsigned long release() = 0;
282 virtual unsigned long refCount()
const 283 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NEW_INTERFACES ) 318 template <
typename TARGET>
320 return reinterpret_cast<TARGET*
>( i->
i_cast( TARGET::interfaceID() ) );
324 template <
typename TARGET>
326 return reinterpret_cast<const TARGET*
>( i->
i_cast( TARGET::interfaceID() ) );
344 StatusCode sc = i->queryInterface( I::interfaceID(), &ii );
351 s <<
"IID_" <<
id.id();
366 template <
class DEST,
class SRC>
368 return reinterpret_cast<DEST**
>( ptr );
375 #endif // GAUDIKERNEL_IINTERFACE_H
std::ostream & operator<<(std::ostream &s, const InterfaceID &id)
ostream operator for InterfaceID. Needed by PluginSvc
constexpr bool operator()(InterfaceId< IFACE, major, minor1 >, InterfaceId< IFACE, major, minor2 >) const
constexpr bool operator()(InterfaceId< IFACE1, major1, minor1 >, InterfaceId< IFACE2, major2, minor2 >) const
constexpr void * operator()(const InterfaceID &, P *) const
const TARGET * Cast(const IInterface *i)
Cast a IInterface pointer to an IInterface specialization (TARGET).
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.
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
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, Service, AlgTool).
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...
DEST ** pp_cast(SRC **ptr)
Small function to be used instead of the construct (void**)&pointer, which produces, on gcc 4.1 optimized, the warning warning: dereferencing type-punned pointer will break strict-aliasing rules The assempler code produced is equivalent to the one with the direct cast.
virtual void * i_cast(const InterfaceID &) const =0
main cast function
unsigned long m_minor_ver
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
constexpr bool operator()(InterfaceId< IFACE, major, minor >, InterfaceId< IFACE, major, minor >) const
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
constexpr unsigned long minorVersion() const
get the minor version of the interface
constexpr bool versionMatch(const InterfaceID &iid) const
check compatibility.
static std::string name()
static constexpr unsigned long minorVersion()
unsigned long m_major_ver
virtual unsigned long release()=0
Release Interface instance.
constexpr bool operator()(InterfaceId< IFACE1, major1, minor1 >, InterfaceId< IFACE2, major2, minor2 >) const
void * operator()(const InterfaceID &tid, P *ptr) const
static const InterfaceID & interfaceID()
constexpr unsigned long id() const
get the interface identifier
constexpr bool operator==(const InterfaceID &iid) const
compare operator
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 majorVersion() const
get the major version of the interface
StatusCode queryInterface(const InterfaceID &iid, void **pinterface) override
constexpr bool fullMatch(const InterfaceID &iid) const
check full compatibility.
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)
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.
Helper functions to set/get the application return code.
unsigned long code_t
type of StatusCode value
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
static const std::type_info & TypeInfo()