ExaTN
exatn_service.hpp
1 #ifndef EXATN_SERVICE_HPP_
2 #define EXATN_SERVICE_HPP_
3 
4 #include "ServiceRegistry.hpp"
5 
6 #include <iostream>
7 #include <memory>
8 
9 #include <cassert>
10 
11 namespace exatn {
12 
13 extern bool exatnFrameworkInitialized;
14 extern std::shared_ptr<ServiceRegistry> serviceRegistry;
15 
16 template <typename Service>
17 std::shared_ptr<Service> getService(const std::string &serviceName) {
18  if(!exatn::exatnFrameworkInitialized) {
19  std::cerr << "#FATAL(exatn::service): Unable to get service " << serviceName << std::endl
20  << "ExaTN is not initialized: Please execute "
21  "exatn::initialize() before using its API.\n";
22  assert(false);
23  }
24  auto service = serviceRegistry->getService<Service>(serviceName);
25  if(!service) {
26  std::cerr << "#ERROR(exatn::service): Invalid ExaTN service: " << serviceName
27  << " in the Service Registry.\n";
28  assert(false);
29  }
30  return service;
31 }
32 
33 template <typename Service>
34 bool hasService(const std::string &serviceName) {
35  if(!exatn::exatnFrameworkInitialized) {
36  std::cerr << "#FATAL(exatn::service): Unable to check service "+serviceName << std::endl <<
37  "ExaTN is not initialized: Please execute "
38  "exatn::initialize() before using its API.\n";
39  assert(false);
40  }
41  return serviceRegistry->hasService<Service>(serviceName);
42 }
43 
44 } // namespace exatn
45 
46 #endif //EXATN_SERVICE_HPP_
exatn
Definition: DriverClient.hpp:10