13 #ifndef XACC_SERVICE_SERVICEAPI_HPP_ 14 #define XACC_SERVICE_SERVICEAPI_HPP_ 16 #include "ServiceRegistry.hpp" 21 extern std::shared_ptr<ServiceRegistry> serviceRegistry;
22 extern bool serviceAPIInitialized;
24 void ServiceAPI_Initialize(
int argc,
char **argv);
25 void ServiceAPI_Finalize();
27 void contributeService(
const std::string name, ContributableService& service);
28 void contributeService(
const std::string name, ContributableService&& service);
30 template <
class Service>
31 std::shared_ptr<Service> getService(
const std::string &serviceName,
bool failIfNotFound =
true) {
32 if (!xacc::serviceAPIInitialized) {
33 XACCLogger::instance()->error(
34 "XACC not initialized before use. Please execute " 35 "xacc::Initialize() before using API.");
37 auto service = serviceRegistry->getService<Service>(serviceName);
38 if (!service && failIfNotFound) {
39 XACCLogger::instance()->error(
"Invalid XACC Service. Could not find " +
40 serviceName +
" in Service Registry.");
45 template <
typename Service>
bool hasService(
const std::string &serviceName) {
46 if (!xacc::serviceAPIInitialized) {
47 XACCLogger::instance()->error(
48 "XACC not initialized before use. Please execute " 49 "xacc::Initialize() before using API.");
51 return serviceRegistry->hasService<Service>(serviceName);
55 template <
class Service>
56 std::shared_ptr<Service> getContributedService(
const std::string &serviceName,
bool failIfNotFound =
true) {
57 if (!xacc::serviceAPIInitialized) {
58 XACCLogger::instance()->error(
59 "XACC not initialized before use. Please execute " 60 "xacc::Initialize() before using API.");
62 auto service = serviceRegistry->getContributedService<Service>(serviceName);
63 if (!service && failIfNotFound) {
64 XACCLogger::instance()->error(
"Invalid XACC Service. Could not find " +
65 serviceName +
" in Service Registry.");
70 template<
typename Service>
71 bool hasContributedService(
const std::string &serviceName) {
72 if (!xacc::serviceAPIInitialized) {
73 XACCLogger::instance()->error(
74 "XACC not initialized before use. Please execute " 75 "xacc::Initialize() before using API.");
77 return serviceRegistry->hasContributedService<Service>(serviceName);
80 template <
typename ServiceInterface>
81 std::vector<std::string> getRegisteredIds() {
82 return serviceRegistry->getRegisteredIds<ServiceInterface>();
85 template <
typename ServiceInterface>
86 std::vector<std::shared_ptr<ServiceInterface>> getServices() {
87 return serviceRegistry->getServices<ServiceInterface>();
90 std::vector<OptionPairs> getRegisteredOptions();
91 bool handleOptions(
const std::map<std::string, std::string> &map);
93 std::string getRootPathString();
Definition: Accelerator.hpp:25