Concrete implementation of the IPersistenceService interface.
More...
#include <mitkPersistenceService.h>
Concrete implementation of the IPersistenceService interface.
This service manages a collection of named PropertyList objects that can be persisted to and restored from files. It supports both XML-based storage (via PropertyListsXmlFileReaderAndWriter) and MITK scene file storage (via SceneIO). The service is registered as a micro service and can be retrieved via the module context.
On first use, the service lazily initializes itself by loading the default persistence file. If auto-load-and-save is enabled, property lists are automatically saved when Unitialize() is called (typically at application shutdown).
- See also
- IPersistenceService
-
IPersistable
-
PropertyListsXmlFileReaderAndWriter
Definition at line 40 of file mitkPersistenceService.h.
◆ PersistenceService()
| mitk::PersistenceService::PersistenceService |
( |
| ) |
|
◆ ~PersistenceService()
| mitk::PersistenceService::~PersistenceService |
( |
| ) |
|
|
override |
◆ AddPropertyListReplacedObserver()
◆ Clear()
| void mitk::PersistenceService::Clear |
( |
| ) |
|
Clear all stored property lists and file modification time records.
◆ GetAutoLoadAndSave()
| bool mitk::PersistenceService::GetAutoLoadAndSave |
( |
| ) |
|
|
overridevirtual |
Query whether automatic loading and saving is enabled.
- Returns
- True if auto-load-and-save is enabled, false otherwise.
Implements mitk::IPersistenceService.
◆ GetDataNodes()
| DataStorage::SetOfObjects::Pointer mitk::PersistenceService::GetDataNodes |
( |
DataStorage * |
ds = nullptr | ) |
|
|
overridevirtual |
◆ GetDefaultPersistenceFile()
| std::string mitk::PersistenceService::GetDefaultPersistenceFile |
( |
| ) |
|
|
overridevirtual |
Get the default file path used for persisting property lists.
Returns "PersistentData.xml" located in the module's persistent data directory, or just "PersistentData.xml" in the working directory if no data directory is available.
- Returns
- The absolute or relative path to the default persistence file.
Implements mitk::IPersistenceService.
◆ GetModuleContext()
Get the micro services module context for this module.
- Returns
- Pointer to the us::ModuleContext.
◆ GetPersistenceNodePropertyName()
| std::string mitk::PersistenceService::GetPersistenceNodePropertyName |
( |
| ) |
|
|
overridevirtual |
◆ GetPersistencePropertyListName()
| static std::string mitk::PersistenceService::GetPersistencePropertyListName |
( |
| ) |
|
|
static |
Get the property list name used for internal persistence service settings.
- Returns
- The string "PersistenceService".
◆ GetPersistencePropertyName()
| static std::string mitk::PersistenceService::GetPersistencePropertyName |
( |
| ) |
|
|
static |
Get the property name used to mark DataNodes as persistence nodes.
- Returns
- The string "PersistenceNode".
◆ GetPropertyList()
| mitk::PropertyList::Pointer mitk::PersistenceService::GetPropertyList |
( |
std::string & |
id, |
|
|
bool * |
existed = nullptr |
|
) |
| |
|
overridevirtual |
Retrieve or create a PropertyList identified by the given id.
If the id is empty, a new UUID is generated and assigned to the id parameter. If a PropertyList with the given id already exists, it is returned; otherwise a new empty PropertyList is created and stored.
- Parameters
-
| [in,out] | id | The identifier string. If empty, a UUID will be generated and written back. |
| [out] | existed | Optional output flag; set to true if the PropertyList already existed, false if newly created. |
- Returns
- A valid PropertyList associated with the given id.
Implements mitk::IPersistenceService.
◆ Load()
| bool mitk::PersistenceService::Load |
( |
const std::string & |
fileName = "", |
|
|
bool |
enforeReload = true |
|
) |
| |
|
overridevirtual |
Load property lists from a file.
If the file has an ".xml" extension, property lists are read as XML via PropertyListsXmlFileReaderAndWriter. Otherwise, the MITK SceneIO format is used. If enforceReload is false, the file is only reloaded when its modification time has changed since the last load.
- Parameters
-
| [in] | fileName | Path to the input file. If empty, the default persistence file is used. |
| [in] | enforeReload | If true, always reload; if false, skip reloading unchanged files. |
- Returns
- True on success, false if an error occurred (e.g., file not found or parse error).
- Note
- Existing PropertyLists with matching ids will be overwritten.
- See also
- AddPropertyListReplacedObserver()
Implements mitk::IPersistenceService.
◆ LoadModule()
| static void mitk::PersistenceService::LoadModule |
( |
| ) |
|
|
static |
Trigger loading of the persistence module.
This is a no-op beyond logging; it exists so that the module is loaded by the micro services framework on demand.
◆ RemovePropertyList()
| bool mitk::PersistenceService::RemovePropertyList |
( |
std::string & |
id | ) |
|
|
overridevirtual |
◆ RemovePropertyListReplacedObserver()
◆ RestorePropertyListsFromPersistentDataNodes()
| bool mitk::PersistenceService::RestorePropertyListsFromPersistentDataNodes |
( |
const DataStorage * |
storage | ) |
|
|
overridevirtual |
Restore property lists from persistence-tagged DataNodes in a DataStorage.
Scans all DataNodes in the given storage for ones marked with the persistence property. For each such node, its properties are cloned into the corresponding PropertyList managed by this service. Registered PropertyListReplacedObservers are notified before and after replacement.
- Parameters
-
| [in] | storage | The DataStorage to scan for persistence nodes. Must not be nullptr. |
- Returns
- True if at least one persistence node was found and restored, false otherwise.
Implements mitk::IPersistenceService.
◆ Save()
| bool mitk::PersistenceService::Save |
( |
const std::string & |
fileName = "", |
|
|
bool |
appendChanges = false |
|
) |
| |
|
overridevirtual |
Save all property lists to a file.
If the file has an ".xml" extension, property lists are written as XML via PropertyListsXmlFileReaderAndWriter. Otherwise, the MITK SceneIO format is used. Directories are created as needed.
- Parameters
-
| [in] | fileName | Path to the output file. If empty, the default persistence file is used. |
| [in] | appendChanges | If true, existing data in the file is loaded first and merged before saving. |
- Returns
- True on success, false if an error occurred (e.g., cannot write to file).
Implements mitk::IPersistenceService.
◆ SetAutoLoadAndSave()
| void mitk::PersistenceService::SetAutoLoadAndSave |
( |
bool |
autoLoadAndSave | ) |
|
|
overridevirtual |
Enable or disable automatic loading and saving of property lists.
When enabled, property lists are automatically loaded at initialization and saved at shutdown (via Unitialize()).
- Parameters
-
| [in] | autoLoadAndSave | True to enable auto-load-and-save, false to disable. |
Implements mitk::IPersistenceService.
◆ Unitialize()
| void mitk::PersistenceService::Unitialize |
( |
| ) |
|
Shut down the persistence service.
If auto-load-and-save is enabled, all property lists are saved to the default file before shutdown.
The documentation for this class was generated from the following file: