16 #ifndef mitkIPersistenceService_h
17 #define mitkIPersistenceService_h
58 virtual bool RemovePropertyList(std::string &
id) = 0;
62 virtual std::string GetDefaultPersistenceFile() = 0;
67 virtual std::string GetPersistenceNodePropertyName() = 0;
79 virtual bool RestorePropertyListsFromPersistentDataNodes(
const DataStorage *storage) = 0;
87 virtual bool Save(
const std::string &fileName =
"",
bool appendChanges =
false) = 0;
97 virtual bool Load(
const std::string &fileName =
"",
bool enforeReload =
true) = 0;
102 virtual void SetAutoLoadAndSave(
bool autoLoadAndSave) = 0;
106 virtual bool GetAutoLoadAndSave() = 0;
123 #define PERSISTENCE_GET_MODULE_CONTEXT_FUNCTION us::GetModuleContext()
125 #define PERSISTENCE_GET_SERVICE_MACRO \
126 mitk::IPersistenceService *persistenceService = 0; \
127 us::ModuleContext *context = PERSISTENCE_GET_MODULE_CONTEXT_FUNCTION; \
130 us::ServiceReference<mitk::IPersistenceService> persistenceServiceRef = \
131 context->GetServiceReference<mitk::IPersistenceService>(); \
132 if (persistenceServiceRef) \
134 persistenceService = dynamic_cast<mitk::IPersistenceService *>( \
135 context->GetService<mitk::IPersistenceService>(persistenceServiceRef)); \
139 #define PERSISTENCE_GET_SERVICE_METHOD_MACRO \
140 mitk::IPersistenceService *GetPersistenceService() const \
142 PERSISTENCE_GET_SERVICE_MACRO \
143 return persistenceService; \
146 #define PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
149 bool Save(const std::string &fileName = "", bool appendChanges = false) \
151 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
152 bool noError = persistenceService != 0; \
154 this->ToPropertyList(); \
156 noError = persistenceService->Save(fileName, appendChanges); \
159 bool Load(const std::string &fileName = "", bool enforeReload = true) \
161 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
162 bool noError = persistenceService != 0 && persistenceService->Load(fileName, enforeReload); \
165 this->FromPropertyList(); \
169 void ToPropertyList() \
171 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
172 this->InitializePropertyListReplacedObserver(persistenceService); \
173 if (!persistenceService) \
175 mitk::PropertyList::Pointer propList = persistenceService->GetPropertyList(ID_MEMBER_NAME);
177 #define PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
179 void FromPropertyList() \
181 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
182 this->InitializePropertyListReplacedObserver(persistenceService); \
183 if (!persistenceService) \
185 mitk::PropertyList::Pointer propList = persistenceService->GetPropertyList(ID_MEMBER_NAME);
187 #define PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME) \
190 std::string GetId() const { return ID_MEMBER_NAME; } \
192 PERSISTENCE_GET_SERVICE_METHOD_MACRO \
193 struct MyPropertyListReplacedObserver : public mitk::PropertyListReplacedObserver \
195 MyPropertyListReplacedObserver() : m_##THE_CLASS_NAME(0), m_PersistenceService(0) {} \
196 ~MyPropertyListReplacedObserver() \
198 if (m_PersistenceService) \
199 m_PersistenceService->RemovePropertyListReplacedObserver(this); \
201 void AfterPropertyListReplaced(const std::string &id, mitk::PropertyList *propertyList) \
203 if (m_##THE_CLASS_NAME && m_##THE_CLASS_NAME->GetId() == id) \
204 m_##THE_CLASS_NAME->FromPropertyList(); \
206 void Initialize(THE_CLASS_NAME *_##THE_CLASS_NAME, mitk::IPersistenceService *persistenceService) \
208 m_##THE_CLASS_NAME = _##THE_CLASS_NAME; \
209 m_PersistenceService = persistenceService; \
210 if (m_PersistenceService) \
211 m_PersistenceService->AddPropertyListReplacedObserver(this); \
215 THE_CLASS_NAME *m_##THE_CLASS_NAME; \
216 mitk::IPersistenceService *m_PersistenceService; \
218 MyPropertyListReplacedObserver m_MyPropertyListReplacedObserver; \
219 void InitializePropertyListReplacedObserver(mitk::IPersistenceService *persistenceService) \
221 static bool observerInitialized = false; \
222 if (observerInitialized == false && persistenceService) \
224 m_MyPropertyListReplacedObserver.Initialize(this, persistenceService); \
225 observerInitialized = true; \
229 #define PERSISTENCE_CREATE(THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME) \
230 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
231 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
232 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
233 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
234 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
236 #define PERSISTENCE_CREATE2(THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME, PARAM2_MEMBER_NAME) \
237 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
238 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
239 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
240 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
241 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
242 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
243 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
245 #define PERSISTENCE_CREATE3(THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME, PARAM2_MEMBER_NAME, PARAM3_MEMBER_NAME) \
246 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
247 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
248 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
249 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
250 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
251 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
252 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
253 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
254 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
256 #define PERSISTENCE_CREATE4( \
257 THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME, PARAM2_MEMBER_NAME, PARAM3_MEMBER_NAME, PARAM4_MEMBER_NAME) \
258 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
259 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
260 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
261 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
262 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
263 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
264 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
265 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
266 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
267 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
268 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
270 #define PERSISTENCE_CREATE5(THE_CLASS_NAME, \
273 PARAM2_MEMBER_NAME, \
274 PARAM3_MEMBER_NAME, \
275 PARAM4_MEMBER_NAME, \
276 PARAM5_MEMBER_NAME) \
277 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
278 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
279 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
280 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
281 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
282 propList->Set(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
283 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
284 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
285 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
286 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
287 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
288 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
289 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
291 #define PERSISTENCE_CREATE6(THE_CLASS_NAME, \
294 PARAM2_MEMBER_NAME, \
295 PARAM3_MEMBER_NAME, \
296 PARAM4_MEMBER_NAME, \
297 PARAM5_MEMBER_NAME, \
298 PARAM6_MEMBER_NAME) \
299 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
300 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
301 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
302 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
303 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
304 propList->Set(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
305 propList->Set(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
306 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
307 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
308 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
309 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
310 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
311 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
312 propList->Get(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
313 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
315 #define PERSISTENCE_CREATE7(THE_CLASS_NAME, \
318 PARAM2_MEMBER_NAME, \
319 PARAM3_MEMBER_NAME, \
320 PARAM4_MEMBER_NAME, \
321 PARAM5_MEMBER_NAME, \
322 PARAM6_MEMBER_NAME, \
323 PARAM7_MEMBER_NAME) \
324 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
325 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
326 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
327 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
328 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
329 propList->Set(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
330 propList->Set(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
331 propList->Set(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
332 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
333 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
334 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
335 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
336 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
337 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
338 propList->Get(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
339 propList->Get(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
340 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
342 #define PERSISTENCE_CREATE8(THE_CLASS_NAME, \
345 PARAM2_MEMBER_NAME, \
346 PARAM3_MEMBER_NAME, \
347 PARAM4_MEMBER_NAME, \
348 PARAM5_MEMBER_NAME, \
349 PARAM6_MEMBER_NAME, \
350 PARAM7_MEMBER_NAME, \
351 PARAM8_MEMBER_NAME) \
352 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
353 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
354 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
355 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
356 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
357 propList->Set(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
358 propList->Set(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
359 propList->Set(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
360 propList->Set(#PARAM8_MEMBER_NAME, PARAM8_MEMBER_NAME); \
361 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
362 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
363 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
364 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
365 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
366 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
367 propList->Get(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
368 propList->Get(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
369 propList->Get(#PARAM8_MEMBER_NAME, PARAM8_MEMBER_NAME); \
370 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
MITK_DECLARE_SERVICE_INTERFACE(mitk::ISimulationService,"org.mitk.ISimulationService")