fw4spl
Get.hxx
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-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_OP_GET_HXX__
8 #define __FWSERVICES_OP_GET_HXX__
9 
10 #include "fwServices/IService.hpp"
11 #include "fwServices/op/Add.hpp"
12 #include "fwServices/registry/ObjectService.hpp"
13 
14 namespace fwServices
15 {
16 
17 //------------------------------------------------------------------------------
18 
19 template<class SERVICE>
20 SPTR(SERVICE) get( ::fwData::Object::sptr obj )
21 {
22  auto services = ::fwServices::OSR::getServices< SERVICE >( obj );
23  std::string serviceType = ::fwCore::TypeDemangler< SERVICE >().getClassname();
24  OSLM_ASSERT("Service "<<serviceType<<" not unique, registered "<<services.size()<<" time", services.size() == 1);
25  return *services.begin();
26 }
27 
28 //------------------------------------------------------------------------------
29 
30 }
31 
32 #endif /*__FWSERVICES_OP_GET_HXX__*/
#define SPTR(_cls_)
FWSERVICES_API::fwServices::IService::sptr get(::fwData::Object::sptr obj, std::string serviceType)
Get the first service of type serviceType which is attached to obj.
Definition: Get.cpp:18
#define OSLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:310
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
Type demangler. Use Demangler class to get a demangled string for the type T.
Definition: Demangler.hpp:95
Contains the representation of the data objects used in the framework.