12 #ifndef mitkIPersistenceService_h
13 #define mitkIPersistenceService_h
58 virtual mitk::PropertyList::Pointer
GetPropertyList(std::string &
id,
bool *existed =
nullptr) = 0;
116 virtual bool Save(
const std::string &fileName =
"",
bool appendChanges =
false) = 0;
134 virtual bool Load(
const std::string &fileName =
"",
bool enforeReload =
true) = 0;
170 #define PERSISTENCE_GET_MODULE_CONTEXT_FUNCTION us::GetModuleContext()
172 #define PERSISTENCE_GET_SERVICE_MACRO \
173 mitk::IPersistenceService *persistenceService = 0; \
174 us::ModuleContext *context = PERSISTENCE_GET_MODULE_CONTEXT_FUNCTION; \
177 us::ServiceReference<mitk::IPersistenceService> persistenceServiceRef = \
178 context->GetServiceReference<mitk::IPersistenceService>(); \
179 if (persistenceServiceRef) \
181 persistenceService = dynamic_cast<mitk::IPersistenceService *>( \
182 context->GetService<mitk::IPersistenceService>(persistenceServiceRef)); \
186 #define PERSISTENCE_GET_SERVICE_METHOD_MACRO \
187 mitk::IPersistenceService *GetPersistenceService() const \
189 PERSISTENCE_GET_SERVICE_MACRO \
190 return persistenceService; \
193 #define PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
196 bool Save(const std::string &fileName = "", bool appendChanges = false) \
198 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
199 bool noError = persistenceService != 0; \
201 this->ToPropertyList(); \
203 noError = persistenceService->Save(fileName, appendChanges); \
206 bool Load(const std::string &fileName = "", bool enforeReload = true) \
208 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
209 bool noError = persistenceService != 0 && persistenceService->Load(fileName, enforeReload); \
212 this->FromPropertyList(); \
216 void ToPropertyList() \
218 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
219 this->InitializePropertyListReplacedObserver(persistenceService); \
220 if (!persistenceService) \
222 mitk::PropertyList::Pointer propList = persistenceService->GetPropertyList(ID_MEMBER_NAME);
224 #define PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
226 void FromPropertyList() \
228 mitk::IPersistenceService *persistenceService = this->GetPersistenceService(); \
229 this->InitializePropertyListReplacedObserver(persistenceService); \
230 if (!persistenceService) \
232 mitk::PropertyList::Pointer propList = persistenceService->GetPropertyList(ID_MEMBER_NAME);
234 #define PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME) \
237 std::string GetId() const { return ID_MEMBER_NAME; } \
239 PERSISTENCE_GET_SERVICE_METHOD_MACRO \
240 struct MyPropertyListReplacedObserver : public mitk::PropertyListReplacedObserver \
242 MyPropertyListReplacedObserver() : m_##THE_CLASS_NAME(0), m_PersistenceService(0) {} \
243 ~MyPropertyListReplacedObserver() \
245 if (m_PersistenceService) \
246 m_PersistenceService->RemovePropertyListReplacedObserver(this); \
248 void AfterPropertyListReplaced(const std::string &id, mitk::PropertyList *) \
250 if (m_##THE_CLASS_NAME && m_##THE_CLASS_NAME->GetId() == id) \
251 m_##THE_CLASS_NAME->FromPropertyList(); \
253 void Initialize(THE_CLASS_NAME *_##THE_CLASS_NAME, mitk::IPersistenceService *persistenceService) \
255 m_##THE_CLASS_NAME = _##THE_CLASS_NAME; \
256 m_PersistenceService = persistenceService; \
257 if (m_PersistenceService) \
258 m_PersistenceService->AddPropertyListReplacedObserver(this); \
262 THE_CLASS_NAME *m_##THE_CLASS_NAME; \
263 mitk::IPersistenceService *m_PersistenceService; \
265 MyPropertyListReplacedObserver m_MyPropertyListReplacedObserver; \
266 void InitializePropertyListReplacedObserver(mitk::IPersistenceService *persistenceService) \
268 static bool observerInitialized = false; \
269 if (observerInitialized == false && persistenceService) \
271 m_MyPropertyListReplacedObserver.Initialize(this, persistenceService); \
272 observerInitialized = true; \
276 #define PERSISTENCE_CREATE(THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME) \
277 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
278 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
279 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
280 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
281 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
283 #define PERSISTENCE_CREATE2(THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME, PARAM2_MEMBER_NAME) \
284 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
285 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
286 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
287 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
288 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
289 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
290 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
292 #define PERSISTENCE_CREATE3(THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME, PARAM2_MEMBER_NAME, PARAM3_MEMBER_NAME) \
293 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
294 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
295 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
296 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
297 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
298 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
299 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
300 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
301 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
303 #define PERSISTENCE_CREATE4( \
304 THE_CLASS_NAME, ID_MEMBER_NAME, PARAM_MEMBER_NAME, PARAM2_MEMBER_NAME, PARAM3_MEMBER_NAME, PARAM4_MEMBER_NAME) \
305 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
306 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
307 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
308 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
309 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
310 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
311 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
312 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
313 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
314 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
315 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
317 #define PERSISTENCE_CREATE5(THE_CLASS_NAME, \
320 PARAM2_MEMBER_NAME, \
321 PARAM3_MEMBER_NAME, \
322 PARAM4_MEMBER_NAME, \
323 PARAM5_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 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
331 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
332 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
333 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
334 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
335 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
336 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
338 #define PERSISTENCE_CREATE6(THE_CLASS_NAME, \
341 PARAM2_MEMBER_NAME, \
342 PARAM3_MEMBER_NAME, \
343 PARAM4_MEMBER_NAME, \
344 PARAM5_MEMBER_NAME, \
345 PARAM6_MEMBER_NAME) \
346 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
347 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
348 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
349 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
350 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
351 propList->Set(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
352 propList->Set(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
353 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
354 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
355 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
356 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
357 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
358 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
359 propList->Get(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
360 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
362 #define PERSISTENCE_CREATE7(THE_CLASS_NAME, \
365 PARAM2_MEMBER_NAME, \
366 PARAM3_MEMBER_NAME, \
367 PARAM4_MEMBER_NAME, \
368 PARAM5_MEMBER_NAME, \
369 PARAM6_MEMBER_NAME, \
370 PARAM7_MEMBER_NAME) \
371 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
372 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
373 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
374 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
375 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
376 propList->Set(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
377 propList->Set(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
378 propList->Set(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
379 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
380 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
381 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
382 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
383 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
384 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
385 propList->Get(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
386 propList->Get(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
387 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
389 #define PERSISTENCE_CREATE8(THE_CLASS_NAME, \
392 PARAM2_MEMBER_NAME, \
393 PARAM3_MEMBER_NAME, \
394 PARAM4_MEMBER_NAME, \
395 PARAM5_MEMBER_NAME, \
396 PARAM6_MEMBER_NAME, \
397 PARAM7_MEMBER_NAME, \
398 PARAM8_MEMBER_NAME) \
399 PERSISTENCE_MACRO_START_PART(ID_MEMBER_NAME) \
400 propList->Set(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
401 propList->Set(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
402 propList->Set(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
403 propList->Set(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
404 propList->Set(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
405 propList->Set(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
406 propList->Set(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
407 propList->Set(#PARAM8_MEMBER_NAME, PARAM8_MEMBER_NAME); \
408 PERSISTENCE_MACRO_MIDDLE_PART(ID_MEMBER_NAME) \
409 propList->Get(#PARAM_MEMBER_NAME, PARAM_MEMBER_NAME); \
410 propList->Get(#PARAM2_MEMBER_NAME, PARAM2_MEMBER_NAME); \
411 propList->Get(#PARAM3_MEMBER_NAME, PARAM3_MEMBER_NAME); \
412 propList->Get(#PARAM4_MEMBER_NAME, PARAM4_MEMBER_NAME); \
413 propList->Get(#PARAM5_MEMBER_NAME, PARAM5_MEMBER_NAME); \
414 propList->Get(#PARAM6_MEMBER_NAME, PARAM6_MEMBER_NAME); \
415 propList->Get(#PARAM7_MEMBER_NAME, PARAM7_MEMBER_NAME); \
416 propList->Get(#PARAM8_MEMBER_NAME, PARAM8_MEMBER_NAME); \
417 PERSISTENCE_MACRO_END_PART(THE_CLASS_NAME, ID_MEMBER_NAME)
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
The central service for the persistence module.
virtual void SetAutoLoadAndSave(bool autoLoadAndSave)=0
Enable or disable automatic loading/saving of PropertyLists at application start/stop.
virtual bool RemovePropertyList(std::string &id)=0
Remove the PropertyList with the given id.
virtual bool GetAutoLoadAndSave()=0
Check whether automatic loading/saving is activated.
virtual ~IPersistenceService()
Destructor.
virtual std::string GetPersistenceNodePropertyName()=0
Get the name of the BoolProperty that marks persistence DataNodes.
virtual mitk::PropertyList::Pointer GetPropertyList(std::string &id, bool *existed=nullptr)=0
Get or create a PropertyList with the given id.
virtual void RemovePropertyListReplacedObserver(PropertyListReplacedObserver *observer)=0
Remove a previously added PropertyList replacement observer.
virtual std::string GetDefaultPersistenceFile()=0
Get the default name of the persistence file (the one that is loaded at startup).
virtual bool Save(const std::string &fileName="", bool appendChanges=false)=0
Save the current PropertyLists to a file.
virtual bool Load(const std::string &fileName="", bool enforeReload=true)=0
Load PropertyLists from a file.
virtual void AddPropertyListReplacedObserver(PropertyListReplacedObserver *observer)=0
Add an observer that is notified when a PropertyList is replaced during Load().
virtual bool RestorePropertyListsFromPersistentDataNodes(const DataStorage *storage)=0
Restore PropertyLists from persistent DataNodes in the given storage.
virtual DataStorage::SetOfObjects::Pointer GetDataNodes(DataStorage *ds=nullptr)=0
Create DataNodes containing all PropertyLists.
Observer that gets informed when a PropertyList with a given id is replaced during a Load() process.
Provides the MITK_DECLARE_SERVICE_INTERFACE macro for registering C++ interfaces with both the CppMic...
#define MITK_DECLARE_SERVICE_INTERFACE(IFace, IId)
Declare a C++ interface for use with CppMicroServices (Qt not available).
Find image slices visible on a given plane.