1 #ifndef GAUDIKERNEL_IINTERFACE_H
2 #define GAUDIKERNEL_IINTERFACE_H
12 #include <boost/mpl/set.hpp>
13 #include <boost/mpl/insert.hpp>
14 #include <boost/mpl/fold.hpp>
15 #include <boost/mpl/for_each.hpp>
16 namespace mpl = boost::mpl;
22 #define DeclareInterfaceID(name, major, minor) \
24 static const InterfaceID &interfaceID(){ return iid::interfaceID(); } \
25 typedef Gaudi::InterfaceId< name , major , minor > iid; \
26 typedef iid::iids::type ext_iids
29 #define DeclareInterfaceID(name, major, minor) \
30 static const InterfaceID &interfaceID(){ static InterfaceID xx(0UL,0UL,0UL); return xx; }
34 #define DeclareInterfaceIDMultiBase(name, major, minor) \
36 static const InterfaceID &interfaceID(){ return iid::interfaceID(); } \
37 typedef Gaudi::InterfaceId< name , major , minor > iid
40 #define DeclareInterfaceIDMultiBase(name, major, minor) \
41 static const InterfaceID &interfaceID(){ static InterfaceID xx(0UL,0UL,0UL); return xx; }
57 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
58 InterfaceID(
unsigned long lid ) : m_id( lid & 0xFFFF ),
60 m_major_ver( (lid & 0xFF000000)>>24 ),
61 m_minor_ver( (lid & 0xFF0000)>> 16 ) { }
63 InterfaceID(
unsigned long id,
unsigned long major,
unsigned long minor = 0)
65 : m_id(
id ), m_major_ver( major ), m_minor_ver( minor ) { }
67 InterfaceID(
const char* name,
unsigned long major,
unsigned long minor = 0)
68 : m_id( hash32(name) ), m_major_ver( major ), m_minor_ver( minor ) { }
71 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
72 operator unsigned long()
const {
74 return (m_major_ver << 24) + (m_minor_ver << 16) + m_id;
77 unsigned long id()
const {
return m_id; }
87 return (
id() == iid.
id() &&
93 return (
id() == iid.
id() &&
100 static unsigned int hash32(
const char* key) {
103 for (hash = 0, k = key; *k; k++) {
104 hash += *k; hash += (hash << 10); hash ^= (hash >> 6);
106 hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15);
120 template <
typename INTERFACE,
unsigned long majVers,
unsigned long minVers>
127 typedef mpl::insert<typename iface_type::ext_iids, InterfaceId>
iids;
140 return typeid(INTERFACE);
173 return iid::interfaceID();
183 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
190 virtual std::vector<std::string> getInterfaceNames() const
191 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
192 {
return std::vector<std::string>();}
198 virtual unsigned long addRef() = 0;
201 virtual unsigned long release() = 0;
204 virtual unsigned long refCount() const
205 #if defined(GAUDI_V20_COMPAT) && !defined(G21_NEW_INTERFACES)
234 template <
typename TARGET>
236 return reinterpret_cast<TARGET*
>(i->
i_cast(TARGET::interfaceID()));
240 template <
typename TARGET>
242 return reinterpret_cast<const TARGET*
>(i->
i_cast(TARGET::interfaceID()));
259 StatusCode sc = i->queryInterface( I::interfaceID(), &ii);
266 s <<
"IID_" <<
id.id();
281 template <
class DEST,
class SRC>
283 return reinterpret_cast<DEST**
>(ptr);
290 #endif // GAUDIKERNEL_IINTERFACE_H
mpl::set1< iid > ext_iids
Extra interfaces.
std::ostream & operator<<(std::ostream &s, const InterfaceID &id)
ostream operator for InterfaceID. Needed by PluginSvc
INTERFACE iface_type
Interface type.
Requested interface is not available.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
unsigned long id() const
get the interface identifier
bool isSuccess() const
Test for a status code of SUCCESS.
static unsigned int hash32(const char *key)
one-at-time hash function
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
unsigned long majorVersion() const
get the major version of the interface
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.
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
virtual void * i_cast(const InterfaceID &) const =0
main cast function
static const InterfaceID & interfaceID()
unsigned long m_minor_ver
bool operator==(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
This class is used for returning status codes from appropriate routines.
unsigned long minorVersion() const
get the minor version of the interface
virtual ~IInterface()
Virtual destructor.
Definition of the basic interface.
bool versionMatch(const InterfaceID &iid) const
check compatibility.
Requested interface version is incompatible.
unsigned long m_major_ver
virtual unsigned long release()=0
Release Interface instance.
static std::string name()
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
TARGET * Cast(IInterface *i)
Cast a IInterface pointer to an IInterface specialization (TARGET).
static const std::type_info & TypeInfo()
This is a number of static methods for bootstrapping the Gaudi framework.
static unsigned long majorVersion()
InterfaceID(const char *name, unsigned long major, unsigned long minor=0)
constructor from components
Class to handle automatically the versioning of the interfaces when they are inheriting from other in...
mpl::insert< typename iface_type::ext_iids, InterfaceId > iids
List of interfaces.
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
bool fullMatch(const InterfaceID &iid) const
check full compatibility.
static unsigned long minorVersion()