Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::IPersistenceService Class Referenceabstract

The central service for the persistence module. More...

#include <mitkIPersistenceService.h>

Inheritance diagram for mitk::IPersistenceService:

Public Member Functions

virtual mitk::PropertyList::Pointer GetPropertyList (std::string &id, bool *existed=nullptr)=0
 Get or create a PropertyList with the given id. More...
 
virtual bool RemovePropertyList (std::string &id)=0
 Remove the PropertyList with the given id. More...
 
virtual std::string GetDefaultPersistenceFile ()=0
 Get the default name of the persistence file (the one that is loaded at startup). More...
 
virtual std::string GetPersistenceNodePropertyName ()=0
 Get the name of the BoolProperty that marks persistence DataNodes. More...
 
virtual DataStorage::SetOfObjects::Pointer GetDataNodes (DataStorage *ds=nullptr)=0
 Create DataNodes containing all PropertyLists. More...
 
virtual bool RestorePropertyListsFromPersistentDataNodes (const DataStorage *storage)=0
 Restore PropertyLists from persistent DataNodes in the given storage. More...
 
virtual bool Save (const std::string &fileName="", bool appendChanges=false)=0
 Save the current PropertyLists to a file. More...
 
virtual bool Load (const std::string &fileName="", bool enforeReload=true)=0
 Load PropertyLists from a file. More...
 
virtual void SetAutoLoadAndSave (bool autoLoadAndSave)=0
 Enable or disable automatic loading/saving of PropertyLists at application start/stop. More...
 
virtual bool GetAutoLoadAndSave ()=0
 Check whether automatic loading/saving is activated. More...
 
virtual void AddPropertyListReplacedObserver (PropertyListReplacedObserver *observer)=0
 Add an observer that is notified when a PropertyList is replaced during Load(). More...
 
virtual void RemovePropertyListReplacedObserver (PropertyListReplacedObserver *observer)=0
 Remove a previously added PropertyList replacement observer. More...
 
virtual ~IPersistenceService ()
 Destructor. More...
 

Detailed Description

The central service for the persistence module.

Basic idea is to create PropertyLists with a unique id using GetPropertyList(). A consumer of this interface can write arbitrary information into this PropertyList. Calling Save() and Load() will cause the service to save and load the current set of PropertyLists from a file in the user directory. Using SetAutoLoadAndSave(true) will cause the service to load/save the PropertyLists at application start/stop. Moreover, depending on the backend type, the service is connected to the SceneSerialization module, i.e. the user will be asked whether to save/load the PropertyLists in/from the current ".mitk" file that is selected by the user.

See also
PropertyList
PropertyListReplacedObserver

Definition at line 44 of file mitkIPersistenceService.h.

Constructor & Destructor Documentation

◆ ~IPersistenceService()

virtual mitk::IPersistenceService::~IPersistenceService ( )
virtual

Destructor.

Member Function Documentation

◆ AddPropertyListReplacedObserver()

virtual void mitk::IPersistenceService::AddPropertyListReplacedObserver ( PropertyListReplacedObserver *  observer)
pure virtual

Add an observer that is notified when a PropertyList is replaced during Load().

Parameters
observerThe observer to add.

Implemented in mitk::PersistenceService.

◆ GetAutoLoadAndSave()

virtual bool mitk::IPersistenceService::GetAutoLoadAndSave ( )
pure virtual

Check whether automatic loading/saving is activated.

Returns
true if auto-load and auto-save are enabled, false otherwise.

Implemented in mitk::PersistenceService.

◆ GetDataNodes()

virtual DataStorage::SetOfObjects::Pointer mitk::IPersistenceService::GetDataNodes ( DataStorage *  ds = nullptr)
pure virtual

Create DataNodes containing all PropertyLists.

The DataNodes will have the property name set to the PropertyList's id and a BoolProperty equal to GetPersistenceNodePropertyName() set to true. If ds is set, the returned DataNodes will also be added to that DataStorage.

Parameters
dsOptional DataStorage to add the nodes to.
Returns
A set of DataNodes with the described attributes.

Implemented in mitk::PersistenceService.

◆ GetDefaultPersistenceFile()

virtual std::string mitk::IPersistenceService::GetDefaultPersistenceFile ( )
pure virtual

Get the default name of the persistence file (the one that is loaded at startup).

Returns
The default persistence file path.

Implemented in mitk::PersistenceService.

◆ GetPersistenceNodePropertyName()

virtual std::string mitk::IPersistenceService::GetPersistenceNodePropertyName ( )
pure virtual

Get the name of the BoolProperty that marks persistence DataNodes.

Returns
The property name string.

Implemented in mitk::PersistenceService.

◆ GetPropertyList()

virtual mitk::PropertyList::Pointer mitk::IPersistenceService::GetPropertyList ( std::string &  id,
bool *  existed = nullptr 
)
pure virtual

Get or create a PropertyList with the given id.

If a PropertyList with the given id exists, returns it. Otherwise creates a new one and returns it. If id is empty, a UUID will be created and set on the variable. If existed was passed, it is set to true if the PropertyList with that id existed, false otherwise.

Parameters
idThe unique identifier for the PropertyList. May be modified if empty.
existedOptional output parameter indicating whether the PropertyList already existed.
Returns
A valid PropertyList with a StringProperty "Id" containing the passed id.

Implemented in mitk::PersistenceService.

◆ Load()

virtual bool mitk::IPersistenceService::Load ( const std::string &  fileName = "",
bool  enforeReload = true 
)
pure virtual

Load PropertyLists from a file.

If fileName is empty, a special file in the user's home directory will be used. If enforeReload is false, the service will take care of modified time flags, i.e. it will not load a file that was loaded before and did not change in the meantime or that was modified by the service itself.

Warning
If there are PropertyLists with the same id contained in the file, existing PropertyLists will be overwritten!
Parameters
fileNameThe file path to load from. Empty for the default location.
enforeReloadIf true, reload regardless of modification timestamps.
Returns
false if an error occurred (cannot load from file), true otherwise.
See also
AddPropertyListReplacedObserver()

Implemented in mitk::PersistenceService.

◆ RemovePropertyList()

virtual bool mitk::IPersistenceService::RemovePropertyList ( std::string &  id)
pure virtual

Remove the PropertyList with the given id.

Parameters
idThe identifier of the PropertyList to remove.
Returns
true if the PropertyList existed and could be removed, false otherwise.

Implemented in mitk::PersistenceService.

◆ RemovePropertyListReplacedObserver()

virtual void mitk::IPersistenceService::RemovePropertyListReplacedObserver ( PropertyListReplacedObserver *  observer)
pure virtual

Remove a previously added PropertyList replacement observer.

Parameters
observerThe observer to remove.

Implemented in mitk::PersistenceService.

◆ RestorePropertyListsFromPersistentDataNodes()

virtual bool mitk::IPersistenceService::RestorePropertyListsFromPersistentDataNodes ( const DataStorage *  storage)
pure virtual

Restore PropertyLists from persistent DataNodes in the given storage.

Searches the storage for persistent DataNodes, extracts and inserts the appended PropertyLists to this service.

Parameters
storageThe DataStorage to search for persistent DataNodes.
Returns
true if at least one node was found from which a PropertyList could be restored.

Implemented in mitk::PersistenceService.

◆ Save()

virtual bool mitk::IPersistenceService::Save ( const std::string &  fileName = "",
bool  appendChanges = false 
)
pure virtual

Save the current PropertyLists to a file.

If fileName is empty, a special file in the user's home directory will be used. If appendChanges is true, the file will not be replaced but first loaded, then overwritten and then replaced.

Parameters
fileNameThe file path to save to. Empty for the default location.
appendChangesIf true, merge changes with the existing file contents.
Returns
false if an error occurred (cannot write to file), true otherwise.

Implemented in mitk::PersistenceService.

◆ SetAutoLoadAndSave()

virtual void mitk::IPersistenceService::SetAutoLoadAndSave ( bool  autoLoadAndSave)
pure virtual

Enable or disable automatic loading/saving of PropertyLists at application start/stop.

Parameters
autoLoadAndSaveIf true, enable automatic load and save.

Implemented in mitk::PersistenceService.


The documentation for this class was generated from the following file: