23 #ifndef USSERVICEINTERFACE_H
24 #define USSERVICEINTERFACE_H
26 #include <usGlobalConfig.h>
56 template<>
inline std::string us_service_interface_iid<void>() {
return std::string(); }
104 #define US_DECLARE_SERVICE_INTERFACE(_service_interface_type, _service_interface_id) \
105 template<> inline std::string us_service_interface_iid<_service_interface_type>() \
106 { return _service_interface_id; } \
111 class ServiceFactory;
119 template<
class Interface>
144 if (us_service_interface_iid<I>().empty())
146 throw ServiceException(std::string(
"The interface class ") +
typeid(I).name() +
147 " uses an invalid id in its US_DECLARE_SERVICE_INTERFACE macro call.");
149 im.insert(std::make_pair(std::string(us_service_interface_iid<I>()),
150 static_cast<void*>(static_cast<I*>(i))));
178 template<
class I1,
class I2 =
void,
class I3 =
void>
195 , m_interface1(static_cast<I1*>(impl))
196 , m_interface2(static_cast<I2*>(impl))
197 , m_interface3(static_cast<I3*>(impl))
226 sim.insert(std::make_pair(std::string(
"org.cppmicroservices.factory"),
227 static_cast<void*>(m_factory)));
235 template<
class I1,
class I2>
236 struct MakeInterfaceMap<I1,I2,void>
238 ServiceFactory* m_factory;
243 MakeInterfaceMap(Impl* impl)
245 , m_interface1(static_cast<I1*>(impl))
246 , m_interface2(static_cast<I2*>(impl))
249 MakeInterfaceMap(ServiceFactory* factory)
256 throw ServiceException(
"The service factory argument must not be NULL.");
268 sim.insert(std::make_pair(std::string(
"org.cppmicroservices.factory"),
269 static_cast<void*>(m_factory)));
277 struct MakeInterfaceMap<I1,void,void>
279 ServiceFactory* m_factory;
283 MakeInterfaceMap(Impl* impl)
285 , m_interface1(static_cast<I1*>(impl))
288 MakeInterfaceMap(ServiceFactory* factory)
294 throw ServiceException(
"The service factory argument must not be NULL.");
305 sim.insert(std::make_pair(std::string(
"org.cppmicroservices.factory"),
306 static_cast<void*>(m_factory)));
314 struct MakeInterfaceMap<void,void,void>;
332 InterfaceMap::const_iterator iter = map.find(us_service_interface_iid<I1>());
333 if (iter != map.end())
335 return reinterpret_cast<I1*
>(iter->second);
343 #endif // USSERVICEINTERFACE_H
bool InsertInterfaceType(InterfaceMap &im, I *i)
MakeInterfaceMap(ServiceFactory *factory)
ServiceFactory * m_factory
std::string GetDemangledName(const std::type_info &typeInfo)
std::map< std::string, void * > InterfaceMap
I1 * ExtractInterface(const InterfaceMap &map)
std::string us_service_interface_iid()
MakeInterfaceMap(Impl *impl)
bool InsertInterfaceType< void >(InterfaceMap &, void *)