Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
usServiceObjects.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CppMicroServices
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 #ifndef USSERVICEOBJECTS_H
23 #define USSERVICEOBJECTS_H
24 
25 #include <usCoreExport.h>
26 
27 #include <usModuleContext.h>
29 #include <usServiceReference.h>
30 #include <usServiceProperties.h>
31 
32 US_BEGIN_NAMESPACE
33 
34 class ServiceObjectsBasePrivate;
35 
36 class US_Core_EXPORT ServiceObjectsBase
37 {
38 
39 private:
40 
41  ServiceObjectsBasePrivate* d;
42 
43 protected:
44 
45  ServiceObjectsBase(ModuleContext* context, const ServiceReferenceBase& reference);
46 
48 
50 
51  ServiceObjectsBase& operator=(const ServiceObjectsBase& other);
52 
53  // Called by ServiceObjects<S> with S != void
54  void* GetService() const;
55 
56  // Called by the ServiceObjects<void> specialization
57  InterfaceMap GetServiceInterfaceMap() const;
58 
59  // Called by ServiceObjects<S> with S != void
60  void UngetService(void* service);
61 
62  // Called by the ServiceObjects<void> specialization
63  void UngetService(const InterfaceMap& interfaceMap);
64 
65  ServiceReferenceBase GetReference() const;
66 
67 };
68 
85 template<class S>
87 {
88 
89 public:
90 
127  S* GetService() const
128  {
129  return reinterpret_cast<S*>(this->ServiceObjectsBase::GetService());
130  }
131 
163  void UngetService(S* service)
164  {
165  this->ServiceObjectsBase::UngetService(service);
166  }
167 
174  {
175  return this->ServiceObjectsBase::GetReference();
176  }
177 
178 private:
179 
180  friend class ModuleContext;
181 
182  ServiceObjects(ModuleContext* context, const ServiceReference<S>& reference)
183  : ServiceObjectsBase(context, reference)
184  {}
185 
186 };
187 
198 template<>
199 class US_Core_EXPORT ServiceObjects<void> : private ServiceObjectsBase
200 {
201 
202 public:
203 
222  InterfaceMap GetService() const;
223 
240  void UngetService(const InterfaceMap& service);
241 
247  ServiceReferenceU GetServiceReference() const;
248 
249 private:
250 
251  friend class ModuleContext;
252 
253  ServiceObjects(ModuleContext* context, const ServiceReferenceU& reference);
254 
255 };
256 
257 US_END_NAMESPACE
258 
259 #endif // USSERVICEOBJECTS_H
S * GetService() const
void UngetService(void *service)
std::map< std::string, void * > InterfaceMap
void UngetService(S *service)
void * GetService() const
ServiceReference< S > GetServiceReference() const