fw4spl
IHasServices.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWSERVICES_IHASSERVICES_HPP__
8 #define __FWSERVICES_IHASSERVICES_HPP__
9 
10 #include "fwServices/config.hpp"
11 #include <fwServices/op/Add.hpp>
12 
13 #include <fwCore/macros.hpp>
14 
15 #include <vector>
16 
17 namespace fwServices
18 {
19 class IService;
20 
24 class FWSERVICES_CLASS_API IHasServices
25 {
26 public:
27 
28  typedef std::vector < WPTR(::fwServices::IService) > ServiceVector;
29 
34  const ServiceVector& getRegisteredServices() const;
35 
40  FWSERVICES_API CSPTR( ::fwServices::IService) getRegisteredService(const ::fwTools::fwID::IDType& _id) const;
41 
42 protected:
43 
45  FWSERVICES_API IHasServices() noexcept;
46 
48  FWSERVICES_API virtual ~IHasServices() noexcept;
49 
55  FWSERVICES_API SPTR(::fwServices::IService) registerService(const std::string& _implType,
56  const std::string& _id = "" );
57 
63  template <class T>
64  SPTR(T) registerService(const std::string& _implType, const std::string& _id = "" );
65 
70  FWSERVICES_API void unregisterService(const ::fwTools::fwID::IDType& _id);
71 
76  FWSERVICES_API void unregisterService(const ::fwServices::IService::sptr& _service);
77 
82  FWSERVICES_API void unregisterServices(const std::string& _implType = "");
83 
84 private:
85 
87  ServiceVector m_subServices;
88 };
89 
90 //------------------------------------------------------------------------------
91 
92 inline const IHasServices::ServiceVector& IHasServices::getRegisteredServices() const
93 {
94  return m_subServices;
95 }
96 
97 //------------------------------------------------------------------------------
98 
99 template <class T>
100 SPTR(T) IHasServices::registerService(const std::string& _implType, const std::string& _id)
101 {
102  auto srv = ::fwServices::add<T>(_implType, _id);
103  m_subServices.push_back(srv);
104 
105  return srv;
106 }
107 
108 //------------------------------------------------------------------------------
109 
110 } //namespace fwServices
111 
112 #endif /*__FWSERVICES_IHASSERVICES_HPP__*/
Base class for all services.
Definition: IService.hpp:61
#define SPTR(_cls_)
#define CSPTR(_cls_)
Interface for objects that need to manage services.
STL namespace.
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
This file defines fwCore base macros.
const ServiceVector & getRegisteredServices() const
Get all subservices linked to this service.