14 #ifndef USSERVICEINTERFACE_H
15 #define USSERVICEINTERFACE_H
55 template<>
inline std::string us_service_interface_iid<void>() {
return std::string(); }
103 #define US_DECLARE_SERVICE_INTERFACE(_service_interface_type, _service_interface_id) \
104 template<> inline std::string us_service_interface_iid<_service_interface_type>() \
105 { return _service_interface_id; } \
110 class ServiceFactory;
118 template<
class Interface>
145 if (us_service_interface_iid<I>().empty())
147 throw ServiceException(std::string(
"The interface class ") +
typeid(I).name() +
148 " uses an invalid id in its US_DECLARE_SERVICE_INTERFACE macro call.");
150 im.insert(std::make_pair(std::string(us_service_interface_iid<I>()),
151 static_cast<void*
>(
static_cast<I*
>(i))));
179 template<
class I1,
class I2 =
void,
class I3 =
void>
212 if (factory ==
nullptr)
214 throw ServiceException(
"The service factory argument must not be nullptr.");
228 sim.insert(std::make_pair(std::string(
"org.cppmicroservices.factory"),
237 template<
class I1,
class I2>
238 struct MakeInterfaceMap<I1,I2,void>
256 if (factory ==
nullptr)
258 throw ServiceException(
"The service factory argument must not be nullptr.");
270 sim.insert(std::make_pair(std::string(
"org.cppmicroservices.factory"),
279 struct MakeInterfaceMap<I1,void,void>
294 if (factory ==
nullptr)
296 throw ServiceException(
"The service factory argument must not be nullptr.");
307 sim.insert(std::make_pair(std::string(
"org.cppmicroservices.factory"),
316 struct MakeInterfaceMap<void,void,void>;
334 InterfaceMap::const_iterator iter =
map.find(us_service_interface_iid<I1>());
335 if (iter !=
map.end())
337 return reinterpret_cast<I1*
>(iter->second);
I1 * ExtractInterface(const InterfaceMap &map)
Extract a service interface pointer from a given InterfaceMap instance.
std::map< std::string, void * > InterfaceMap
A map containing interfaces ids and their corresponding service object pointers.
std::string GetDemangledName(const std::type_info &typeInfo)
Returns the demangled name for the given type_info.
std::string us_service_interface_iid()
Returns a unique id for a given type. By default, the demangled name of T is returned.
bool InsertInterfaceType< void >(InterfaceMap &, void *)
bool InsertInterfaceType(InterfaceMap &im, I *i)
A helper type used in several methods to get proper method overload resolutions.
Helper class for constructing InterfaceMap instances based on service implementations or service fact...
ServiceFactory * m_factory
MakeInterfaceMap(ServiceFactory *factory)
Constructor taking a service factory.
MakeInterfaceMap(Impl *impl)
Constructor taking a service implementation pointer.