1 #ifndef GAUDIKERNEL_IINTERFACE_H
2 #define GAUDIKERNEL_IINTERFACE_H
14 #define DeclareInterfaceID(iface, major, minor) \
15 static const InterfaceID &interfaceID() { return iid::interfaceID(); } \
16 using iid = Gaudi::InterfaceId< iface , major , minor > ; \
17 using ext_iids = iid::iids
32 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
33 constexpr
InterfaceID(
unsigned long lid ) : m_id( lid & 0xFFFF ),
35 m_major_ver( (lid & 0xFF000000)>>24 ),
36 m_minor_ver( (lid & 0xFF0000)>> 16 ) { }
38 constexpr InterfaceID(
unsigned long id,
unsigned long major,
unsigned long minor = 0)
40 : m_id(
id ), m_major_ver( major ), m_minor_ver( minor ) { }
43 : m_id( hash32(name) ), m_major_ver( major ), m_minor_ver( minor ) { }
44 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
45 constexpr
operator unsigned long()
const {
47 return (m_major_ver << 24) + (m_minor_ver << 16) + m_id;
50 constexpr
unsigned long id()
const {
return m_id; }
53 constexpr
unsigned long majorVersion()
const {
return m_major_ver; }
55 constexpr
unsigned long minorVersion()
const {
return m_minor_ver; }
60 return (
id() == iid.
id() &&
65 constexpr
bool fullMatch(
const InterfaceID& iid )
const {
66 return (
id() == iid.
id() &&
71 constexpr
bool operator == (
const InterfaceID& iid )
const {
return fullMatch(iid); }
73 static unsigned int hash32(
const char* key) {
74 unsigned int hash = 0;
75 for (
const char* k = key; *k; ++k) {
76 hash += *k; hash += (hash << 10); hash ^= (hash >> 6);
78 hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15);
94 template <
typename T>
struct id_
99 template <
typename... Is>
102 template <
typename List,
typename I>
107 template <
typename... Is,
typename I>
109 :
id_<typename std::conditional<std::is_base_of< id_<I>, inherit_from<id_<Is>...> >::value,
110 interface_list<Is...>,
111 interface_list<Is...,I> >::type> { };
113 template <
typename,
typename>
116 template <
typename State>
120 template <
typename... Is,
typename I,
typename List>
122 :
appendN<interface_list<Is... >, typename append1<List, I>::type> { };
125 template <
typename... Is>
133 template <
typename... I>
138 template <
typename... I1,
typename... I2>
143 template <
typename... I1,
typename... I2,
typename... Others>
150 template <
typename... Is,
typename I>
155 namespace iid_cast_details {
156 template <
typename I>
158 {
return const_cast<I*
>(
i); }
163 template <
typename P>
164 constexpr
void*
operator()(
const InterfaceID&, P*)
const {
return nullptr ; }
167 template <
typename I,
typename... Is>
struct iid_cast_t<I,Is...> {
168 template <
typename P>
169 inline void*
operator()(
const InterfaceID& tid, P* ptr)
const {
176 template <
typename... Is>
181 template <
typename...Is,
typename P>
184 return iid_cast_(tid,ptr);
190 template <
typename INTERFACE,
unsigned long majVers,
unsigned long minVers>
206 static const InterfaceID s_iid(
name().c_str(),majVers,minVers);
212 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
unsigned long minor2>
214 template <
typename IFACE,
unsigned long major,
unsigned long minor>
219 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
unsigned long minor2>
221 template <
typename IFACE,
unsigned long major,
unsigned long minor1,
unsigned long minor2>
244 return iid::interfaceID();
248 virtual void *i_cast(
const InterfaceID &) const
249 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
257 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
264 virtual unsigned long addRef() = 0;
267 virtual unsigned long release() = 0;
270 virtual unsigned long refCount() const
271 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
280 virtual StatusCode queryInterface(
const InterfaceID &ti,
void**
pp) = 0;
300 template <
typename TARGET>
302 return reinterpret_cast<TARGET*
>(i->
i_cast(TARGET::interfaceID()));
306 template <
typename TARGET>
308 return reinterpret_cast<const TARGET*
>(i->
i_cast(TARGET::interfaceID()));
325 StatusCode sc = i->queryInterface( I::interfaceID(), &ii );
332 s <<
"IID_" <<
id.id();
347 template <
class DEST,
class SRC>
349 return reinterpret_cast<DEST**
>(ptr);
356 #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
Requested interface is not available.
constexpr void * operator()(const InterfaceID &, P *) const
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
bool isSuccess() const
Test for a status code of SUCCESS.
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
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is...>)
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
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
bool operator==(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
constexpr struct Gaudi::fullMatch_t fullMatch
constexpr unsigned long minorVersion() const
get the minor version of the interface
constexpr bool versionMatch(const InterfaceID &iid) const
check compatibility.
Requested interface version is incompatible.
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
static const InterfaceID & interfaceID()
constexpr unsigned long id() const
get the interface identifier
void * operator()(const InterfaceID &tid, P *ptr) const
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
Gaudi::interface_list< iid > ext_iids
Extra interfaces.
constexpr void * void_cast(const I *i)
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
constexpr unsigned long majorVersion() const
get the major version of the interface
TARGET * Cast(IInterface *i)
Cast a IInterface pointer to an IInterface specialization (TARGET).
constexpr bool fullMatch(const InterfaceID &iid) const
check full compatibility.
State
Execution states of the algorithms.
InterfaceID(const char *name, unsigned long major, unsigned long minor=0)
constructor from components
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is...>, P *ptr)
Helper functions to set/get the application return code.
typename Gaudi::interface_list_append< typename interface_type::ext_iids, InterfaceId >::type iids
List of interfaces.
static const std::type_info & TypeInfo()