1 #ifndef GAUDIKERNEL_IINTERFACE_H
2 #define GAUDIKERNEL_IINTERFACE_H
5 #include "GaudiKernel/Kernel.h"
6 #include "GaudiKernel/System.h"
7 #include "GaudiKernel/StatusCode.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 ) { }
42 InterfaceID(
const char*
name,
unsigned long major,
unsigned long minor = 0)
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; }
59 constexpr
bool versionMatch(
const InterfaceID& iid )
const {
60 return (
id() == iid.
id() &&
65 constexpr
bool fullMatch(
const InterfaceID& iid )
const {
66 return (
id() == iid.
id() &&
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);
84 unsigned long m_major_ver;
85 unsigned long m_minor_ver;
90 template <
typename... I>
struct interface_list { };
94 template <
typename T>
struct id_
99 template <
typename... Is>
100 struct inherit_from : Is... { };
102 template <
typename List,
typename I>
107 template <
typename... Is,
typename I>
108 struct append1<interface_list<Is...>, 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>
117 struct appendN<interface_list<>,
State >
120 template <
typename... Is,
typename I,
typename List>
121 struct appendN<interface_list<I,Is...>, List>
122 : appendN<interface_list<Is... >, typename append1<List, I>::type> { };
125 template <
typename... Is>
130 template <
typename... I>
struct interface_list_cat;
133 template <
typename... I>
134 struct interface_list_cat<interface_list<I...>>
138 template <
typename... I1,
typename... I2>
139 struct interface_list_cat<interface_list<I1...>,interface_list<I2...>>
143 template <
typename... I1,
typename... I2,
typename... Others>
144 struct interface_list_cat<interface_list<I1...>,interface_list<I2...>, Others...>
145 : interface_list_cat< interface_list<I1...,I2...>, Others... > { };
148 template <
typename... I>
struct interface_list_append;
150 template <
typename... Is,
typename I>
151 struct interface_list_append<interface_list<Is...>,I>
152 : interface_list_cat< interface_list<Is...>, interface_list<I> > { };
155 namespace iid_cast_details {
156 template <
typename I>
158 {
return const_cast<I*
>(
i); }
160 template <
typename ... Is>
struct iid_cast_t;
162 template <>
struct iid_cast_t<> {
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 {
171 : iid_cast_t<Is...>{}(tid,ptr);
176 template <
typename... Is>
181 template <
typename...Is,
typename P>
183 constexpr
auto iid_cast_ = iid_cast_details::iid_cast_t<Is...>{};
184 return iid_cast_(tid,ptr);
190 template <
typename INTERFACE,
unsigned long majVers,
unsigned long minVers>
191 struct InterfaceId final {
198 static constexpr
unsigned long majorVersion() {
return majVers; }
199 static constexpr
unsigned long minorVersion() {
return minVers; }
201 static inline const std::type_info &
TypeInfo() {
211 constexpr
struct fullMatch_t {
212 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
unsigned long minor2>
213 constexpr
bool operator()(InterfaceId<IFACE1,major1,minor1>, InterfaceId<IFACE2,major2,minor2>)
const {
return false; }
214 template <
typename IFACE,
unsigned long major,
unsigned long minor>
215 constexpr
bool operator()(InterfaceId<IFACE,major,minor>, InterfaceId<IFACE,major,minor>)
const {
return true; }
218 constexpr
struct majorMatch_t {
219 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
unsigned long minor2>
220 constexpr
bool operator()(InterfaceId<IFACE1,major1,minor1>, InterfaceId<IFACE2,major2,minor2>)
const {
return false; }
221 template <
typename IFACE,
unsigned long major,
unsigned long minor1,
unsigned long minor2>
222 constexpr
bool operator()(InterfaceId<IFACE,major,minor1>, InterfaceId<IFACE,major,minor2>)
const {
return true; }
244 return iid::interfaceID();
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)
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>
348 inline DEST**
pp_cast(SRC** ptr){
349 return reinterpret_cast<DEST**
>(ptr);
352 #include "GaudiKernel/extend_interfaces.h"
353 #include "GaudiKernel/implements.h"
354 #include "GaudiKernel/extends.h"
356 #endif // GAUDIKERNEL_IINTERFACE_H
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
constexpr bool operator()(InterfaceId< IFACE1, major1, minor1 >, InterfaceId< IFACE2, major2, minor2 >) const
constexpr struct Gaudi::majorMatch_t majorMatch
bool isSuccess() const
Test for a status code of SUCCESS.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
bool operator==(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is...>)
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.
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...
virtual void * i_cast(const InterfaceID &) const =0
main cast function
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
constexpr void * void_cast(const I *i)
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.
static std::string name()
static constexpr unsigned long minorVersion()
std::ostream & operator<<(std::ostream &s, const InterfaceID &id)
ostream operator for InterfaceID. Needed by PluginSvc
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
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
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).
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()