23 #ifndef USSERVICEINTERFACE_H
24 #define USSERVICEINTERFACE_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))
207 , m_interface1(nullptr)
208 , m_interface2(nullptr)
209 , m_interface3(nullptr)
211 if (factory ==
nullptr)
213 throw ServiceException(
"The service factory argument must not be nullptr.");
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)
251 , m_interface1(nullptr)
252 , m_interface2(nullptr)
254 if (factory ==
nullptr)
256 throw ServiceException(
"The service factory argument must not be nullptr.");
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)
290 , m_interface1(nullptr)
292 if (factory ==
nullptr)
294 throw ServiceException(
"The service factory argument must not be nullptr.");
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