Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::NodeUidMapper Class Reference

Maintains transient UID-to-DataNode mappings for the REST API. More...

#include <mitkNodeUidMapper.h>

Public Member Functions

 NodeUidMapper ()
 Default constructor. More...
 
 ~NodeUidMapper ()
 Destructor. Disconnects from the DataStorage if connected. More...
 
 NodeUidMapper (const NodeUidMapper &)=delete
 
NodeUidMapper & operator= (const NodeUidMapper &)=delete
 
 NodeUidMapper (NodeUidMapper &&)=delete
 
NodeUidMapper & operator= (NodeUidMapper &&)=delete
 
void SetDataStorage (DataStorage *dataStorage)
 Connect to a DataStorage and start tracking nodes. More...
 
void ClearDataStorage ()
 Disconnect from the current DataStorage. More...
 
std::string GetOrCreateUid (DataNode *node)
 Get or create a UID for the given node. More...
 
DataNode::Pointer FindNodeByUid (const std::string &uid) const
 Find a node by its UID. More...
 
std::optional< std::string > GetUid (const DataNode *node) const
 Get the UID for a node without creating one. More...
 
bool HasUid (const std::string &uid) const
 Check whether a UID exists in the mapping. More...
 
void RestoreUid (const DataNode *node, const std::string &uid)
 Restore a previously assigned UID mapping for a node. More...
 

Static Public Attributes

static constexpr const char * UID_PROPERTY_KEY
 Property key for storing the UID on nodes (for debugging visibility). More...
 

Detailed Description

Maintains transient UID-to-DataNode mappings for the REST API.

This class provides a bidirectional mapping between string UIDs and DataNode pointers. UIDs are:

  • Generated on first access (format: "node_<counter>")
  • Stored as a node property under the key "restapi.uid" for debugging visibility
  • Cleared from the cache when the node is removed from the DataStorage
  • Never reused during a session lifetime
  • NOT persisted when a scene is saved (transient property)

All public methods are thread-safe.

See also
DataStorageBridge

Definition at line 44 of file mitkNodeUidMapper.h.

Constructor & Destructor Documentation

◆ NodeUidMapper() [1/3]

mitk::NodeUidMapper::NodeUidMapper ( )

Default constructor.

◆ ~NodeUidMapper()

mitk::NodeUidMapper::~NodeUidMapper ( )

Destructor. Disconnects from the DataStorage if connected.

◆ NodeUidMapper() [2/3]

mitk::NodeUidMapper::NodeUidMapper ( const NodeUidMapper &  )
delete

◆ NodeUidMapper() [3/3]

mitk::NodeUidMapper::NodeUidMapper ( NodeUidMapper &&  )
delete

Member Function Documentation

◆ ClearDataStorage()

void mitk::NodeUidMapper::ClearDataStorage ( )

Disconnect from the current DataStorage.

Equivalent to calling SetDataStorage(nullptr).

◆ FindNodeByUid()

DataNode::Pointer mitk::NodeUidMapper::FindNodeByUid ( const std::string &  uid) const

Find a node by its UID.

Returns a strong SmartPointer reference to guarantee the node stays alive after the internal lock is released.

Parameters
[in]uidThe UID to look up.
Returns
A SmartPointer to the node, or a null pointer if not found or if the node has already been destroyed.

◆ GetOrCreateUid()

std::string mitk::NodeUidMapper::GetOrCreateUid ( DataNode *  node)

Get or create a UID for the given node.

If the node already has a cached UID, it is returned. Otherwise a new unique UID is generated, stored in the cache, and set as a property on the node.

Parameters
[in]nodeThe node to get or create a UID for. Must not be nullptr.
Returns
The UID string for this node.
Exceptions
std::invalid_argumentif node is nullptr.

◆ GetUid()

std::optional<std::string> mitk::NodeUidMapper::GetUid ( const DataNode *  node) const

Get the UID for a node without creating one.

Parameters
[in]nodeThe node to look up.
Returns
The UID if it exists, or std::nullopt if the node has no UID or node is nullptr.

◆ HasUid()

bool mitk::NodeUidMapper::HasUid ( const std::string &  uid) const

Check whether a UID exists in the mapping.

Parameters
[in]uidThe UID string to check.
Returns
true if the UID is registered in the mapping.

◆ operator=() [1/2]

NodeUidMapper& mitk::NodeUidMapper::operator= ( const NodeUidMapper &  )
delete

◆ operator=() [2/2]

NodeUidMapper& mitk::NodeUidMapper::operator= ( NodeUidMapper &&  )
delete

◆ RestoreUid()

void mitk::NodeUidMapper::RestoreUid ( const DataNode *  node,
const std::string &  uid 
)

Restore a previously assigned UID mapping for a node.

Used to preserve UIDs across operations that temporarily remove and re-add nodes to the DataStorage (e.g., reparenting). The node's previous UID is re-registered in the cache and stored as a property.

Parameters
[in]nodeThe node to restore the UID for. Must not be nullptr.
[in]uidThe UID to restore.
Exceptions
std::invalid_argumentif node is nullptr.

◆ SetDataStorage()

void mitk::NodeUidMapper::SetDataStorage ( DataStorage *  dataStorage)

Connect to a DataStorage and start tracking nodes.

Subscribes to AddNodeEvent and RemoveNodeEvent. Clears all existing mappings and removes any stale "restapi.uid" properties from all nodes in the DataStorage (fresh start).

Parameters
[in]dataStorageThe DataStorage to track, or nullptr to disconnect.

Member Data Documentation

◆ UID_PROPERTY_KEY

constexpr const char* mitk::NodeUidMapper::UID_PROPERTY_KEY
staticconstexpr

Property key for storing the UID on nodes (for debugging visibility).

Definition at line 48 of file mitkNodeUidMapper.h.


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