Go to the documentation of this file.
18 #include <type_traits>
22 #define DeclareInterfaceID( iface, major, minor ) \
23 static const InterfaceID& interfaceID() { return iid::interfaceID(); } \
24 using iid = Gaudi::InterfaceId<iface, major, minor>; \
25 using ext_iids = typename iid::iids
41 constexpr
InterfaceID(
unsigned long id,
unsigned long major,
unsigned long minor = 0 )
42 : m_id(
id ), m_major_ver( major ), m_minor_ver( minor ) {}
45 : m_id( hash32(
name ) ), m_major_ver( major ), m_minor_ver( minor ) {}
47 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; }
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 );
80 s <<
"IID_" <<
id.id();
92 template <
typename... I>
103 template <
typename... Is>
106 template <
typename List,
typename I>
111 template <
typename... Is,
typename I>
113 :
id_<std::conditional_t<std::is_base_of_v<id_<I>, inherit_from<id_<Is>...>>, interface_list<Is...>,
114 interface_list<Is..., I>>> {};
116 template <
typename,
typename>
119 template <
typename State>
122 template <
typename... Is,
typename I,
typename List>
127 template <
typename... Is>
132 template <
typename... I>
136 template <
typename... I>
140 template <
typename... I1,
typename... I2>
145 template <
typename... I1,
typename... I2,
typename... Others>
150 template <
typename... I>
153 template <
typename... Is,
typename I>
157 template <
typename... Is>
162 template <
typename... Is,
typename P>
164 const void*
target =
nullptr;
166 (
target =
static_cast<typename Is::interface_type const*
>( ptr ),
true ) ) ||
168 return const_cast<void*
>(
target );
174 template <
typename INTERFACE,
unsigned long majVers,
unsigned long minVers>
194 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
195 unsigned long minor2>
199 template <
typename IFACE,
unsigned long major,
unsigned long minor>
206 template <
typename IFACE1,
typename IFACE2,
unsigned long major1,
unsigned long major2,
unsigned long minor1,
207 unsigned long minor2>
211 template <
typename IFACE,
unsigned long major,
unsigned long minor1,
unsigned long minor2>
236 template <Gaudi::IsInterface TARGET>
238 if (
auto output = i_cast( TARGET::interfaceID() ) ) {
return reinterpret_cast<TARGET*
>(
output ); }
239 if constexpr ( Gaudi::IsInterface<TARGET> ) {
241 queryInterface( TARGET::interfaceID(), &tgt ).ignore();
244 auto*
target =
reinterpret_cast<TARGET*
>( tgt );
254 template <Gaudi::IsInterface TARGET>
256 if (
auto output = i_cast( TARGET::interfaceID() ) ) {
return reinterpret_cast<TARGET const*
>(
output ); }
257 if constexpr ( Gaudi::IsInterface<TARGET> ) {
259 const_cast<IInterface*
>( this )->queryInterface( TARGET::interfaceID(), &tgt ).ignore();
262 auto*
target =
reinterpret_cast<const TARGET*
>( tgt );
272 template <
typename TARGET>
275 return dynamic_cast<TARGET*
>( this );
278 template <
typename TARGET>
280 TARGET
const* cast()
const {
281 return dynamic_cast<TARGET const*
>( this );
288 virtual unsigned long addRef()
const = 0;
321 return const_cast<void*
>(
const_cast<const IInterface*
>( this )->i_cast(
iid ) );
326 virtual unsigned long decRef()
const = 0;
332 template <
typename TARGET>
334 return i ? i->
cast<TARGET>() :
nullptr;
337 template <
typename TARGET>
339 return i ? i->
cast<
const TARGET>() :
nullptr;
353 template <
class IFace>
356 return i->queryInterface( IFace::interfaceID(), &ii ).isSuccess();
369 template <
class DEST,
class SRC>
371 return reinterpret_cast<DEST**
>( ptr );
Class to handle automatically the versioning of the interfaces when they are inheriting from other in...
constexpr bool fullMatch(const InterfaceID &iid) const
check full compatibility.
constexpr struct Gaudi::fullMatch_t fullMatch
requires(!Gaudi::IsInterface< TARGET >) TARGET const *cast() const
static constexpr unsigned long majorVersion()
constexpr InterfaceID(unsigned long id, unsigned long major, unsigned long minor=0)
constructor from components
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
static constexpr unsigned long minorVersion()
virtual void const * i_cast(const InterfaceID &) const =0
unsigned long code_t
type of StatusCode value
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
virtual unsigned long addRef() const =0
Increment the reference count of Interface instance.
constexpr unsigned long id() const
get the interface identifier
virtual ~IInterface()=default
Virtual destructor.
static const InterfaceID & interfaceID()
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
unsigned long m_minor_ver
constexpr unsigned long majorVersion() const
get the major version of the interface
INTERFACE interface_type
interface type
void * i_cast(const InterfaceID &iid)
unsigned long m_major_ver
constexpr bool operator==(const InterfaceID &iid) const
compare operator
constexpr bool operator()(InterfaceId< IFACE, major, minor >, InterfaceId< IFACE, major, minor >) const
static std::string name()
constexpr struct Gaudi::majorMatch_t majorMatch
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
DEST ** pp_cast(SRC **ptr)
Small function to be used instead of the construct (void**)&pointer, which produces,...
constexpr unsigned long minorVersion() const
get the minor version of the interface
static const std::type_info & TypeInfo()
constexpr bool operator()(InterfaceId< IFACE1, major1, minor1 >, InterfaceId< IFACE2, major2, minor2 >) const
#define STATUSCODE_ENUM_DECL(ENUM)
Declare an enum to be used as StatusCode value.
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is... >, P *ptr)
requires(!Gaudi::IsInterface< TARGET >) TARGET *cast()
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is... >)
constexpr bool versionMatch(const InterfaceID &iid) const
check compatibility.
static unsigned int hash32(const char *key)
Jenkins one-at-time hash function – see https://en.wikipedia.org/wiki/Jenkins_hash_function.
virtual std::vector< std::string > getInterfaceNames() const =0
Returns a vector of strings containing the names of all the implemented interfaces.
bool isValidInterface(IFace *i)
Templated function that throws an exception if the version if the interface implemented by the object...
typename Gaudi::interface_list_append< typename interface_type::ext_iids, InterfaceId >::type iids
List of interfaces.
constexpr bool operator()(InterfaceId< IFACE1, major1, minor1 >, InterfaceId< IFACE2, major2, minor2 >) const
virtual unsigned long decRef() const =0
Decrement reference count and return the new reference count.
constexpr bool operator()(InterfaceId< IFACE, major, minor1 >, InterfaceId< IFACE, major, minor2 >) const
InterfaceID(const char *name, unsigned long major, unsigned long minor=0)
constructor from components
virtual unsigned long refCount() const =0
Current reference count.
friend std::ostream & operator<<(std::ostream &s, const InterfaceID &id)
ostream operator for InterfaceID. Needed by PluginSvc
TARGET * Cast(IInterface *i)
virtual unsigned long release() const =0
Release Interface instance.
TARGET const * cast() const