ImFusion SDK 4.3
DataComponentList Class Reference

#include <ImFusion/Base/DataComponentList.h>

Class for holding a collection of DataComponents. More...

+ Inheritance diagram for DataComponentList:

Detailed Description

Class for holding a collection of DataComponents.

DataComponents are uniquely identified by their type and DataComponentList will hold only a single instance of a specific DataComponent type.

DataComponents inheriting from LazyInstantiatedDataComponent can never be deleted from a DataComponentList due to their invariant that references remain valid over the lifetime of the parent Data. Therefore, the assign() and erase() may behave unexpected as they will not remove existing DataComponents of such types.

Example:

{
// store information at one place
SharedImageSet* image = ...;
// alternative 1:
adc->add(Anatomy::ABDOMEN);
image->components().add(std::move(adc));
// alternative 2:
image->components().getOrCreate<AnatomyDataComponent>().add(Anatomy::ABDOMEN);
}
{
// retrieve information at some other place
SharedImageSet* image = ...;
if (AnatomyDataComponent* adc = image->components().get<AnatomyDataComponent>()) {
if (adc->contains(Anatomy::ABDOMEN))
...
}
}
A data component storing information about anatomy contained in medical images or other data.
Definition AnatomyDataComponent.h:13
T * add(std::unique_ptr< T > component)
Adds the given DataComponent to the collection.
Definition DataComponentList.h:164
Set of images independent of their storage location.
Definition SharedImageSet.h:42
T make_unique(T... args)

Public Member Functions

 DataComponentList (const Data *parentData=nullptr)
 Constructor.
 
 DataComponentList (const DataComponentList &other)
 Copy constructor, cloning all DataComponents held by other.
 
 DataComponentList (DataComponentList &&other) noexcept
 Move constructor, taking ownership of all DataComponents held by other.
 
bool operator== (const DataComponentList &other) const
 Return true if all held components are the same, ignoring their order within the DataComponentList.
 
void assign (const DataComponentList &rhs)
 Copy assignment, removing all existing components where possible and cloning all DataComponents held by rhs.
 
template<typename T>
T * add (std::unique_ptr< T > component)
 Adds the given DataComponent to the collection.
 
void add (const DataComponentList &other)
 Adds all DataComponents in other to this one.
 
template<typename T>
T * get ()
 Returns the DataComponent exactly matching the given type.
 
template<typename T>
const T * get () const
 Returns the DataComponent exactly matching the given type.
 
template<typename T, typename... Args>
T & getOrCreate (Args &&... ctorArgs)
 Returns the DataComponent exactly matching the given type.
 
std::vector< DataComponentBase * > getAll ()
 Returns all DataComponents without requiring any specific type.
 
std::vector< const DataComponentBase * > getAll () const
 
template<typename T>
bool erase ()
 Will erase the DataComponent of the exact given type if possible.
 
bool erase (const std::string &id)
 Will erase the DataComponent of the exact given id if possible.
 
void clear ()
 Erases all data components in the list that are not persistent.
 
bool empty () const
 Returns whether the list contains any DataComponent.
 
int size () const
 Returns the total number of DataComponents.
 
void configuration (Properties *p) const override
 Writes the configuration of all DataComponents with non-empty string ID to the given properties.
 
void configure (const Properties *p) override
 Restores the collection of components and their state from the given properties configuration.
 
void swapWith (DataComponentList &other)
 Swaps the data component lists.
 
- Public Member Functions inherited from Configurable
virtual void configureDefaults ()
 Retrieve the properties of this object, replaces values with their defaults and sets it again.
 
void registerParameter (ParameterBase *param)
 Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration().
 
void unregisterParameter (const ParameterBase *param)
 Remove the given Parameter or SubProperty from the list of registered parameters.
 
 Configurable (const Configurable &rhs)
 
 Configurable (Configurable &&rhs) noexcept
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Public Attributes

Signal signalListChanged
 Emitted whenever the DataComponentList changes by a DataComponent being added or removed.
 
- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 

Protected Attributes

std::vector< std::unique_ptr< DataComponentBase > > m_components
 Collection of components of this list.
 
const Datam_parentData = nullptr
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Constructor & Destructor Documentation

◆ DataComponentList()

DataComponentList ( const Data * parentData = nullptr)
inline

Constructor.

Parameters
parentDataOptionally a parent data can be provided which will be set for any DataComponentWithParentInterface added to the DataComponentList

Member Function Documentation

◆ assign()

void assign ( const DataComponentList & rhs)

Copy assignment, removing all existing components where possible and cloning all DataComponents held by rhs.

Note
Due to certain DataComponent-invariants this list is not necessarily the same as rhs after assignment.

◆ add() [1/2]

template<typename T>
T * add ( std::unique_ptr< T > component)

Adds the given DataComponent to the collection.

Note
If the list already contains a DataComponent of the exact same type, its configuration will be overwritten with the one in component.
Do not store a pointer to component after calling this method since it may be deleted. Use the returned pointer in case you want to keep a reference to the added DataComponent (this may be a different instance)!

◆ add() [2/2]

void add ( const DataComponentList & other)

Adds all DataComponents in other to this one.

Any given DataComponent of the exact same type will be overwritten.

◆ get() [1/2]

template<typename T>
T * get ( )

Returns the DataComponent exactly matching the given type.

Returns 0 if this object does not have a component of the given type.

Examples
DicomExtensionExample3.cpp.

◆ get() [2/2]

template<typename T>
const T * get ( ) const

Returns the DataComponent exactly matching the given type.

Returns 0 if this object does not have a component of the given type.

◆ getOrCreate()

template<typename T, typename... Args>
T & getOrCreate ( Args &&... ctorArgs)

Returns the DataComponent exactly matching the given type.

If no such DataComponent exists yet, a new one will be created first.

Parameters
ctorArgsArguments to be forwarded to the constructor of T in case the DataComponent needs to be created.
Examples
DicomExtensionExample.cpp, and DicomExtensionExample3.cpp.

◆ configuration()

void configuration ( Properties * p) const
overridevirtual

Writes the configuration of all DataComponents with non-empty string ID to the given properties.

Reimplemented from Configurable.

◆ configure()

void configure ( const Properties * p)
overridevirtual

Restores the collection of components and their state from the given properties configuration.

Reimplemented from Configurable.

◆ swapWith()

void swapWith ( DataComponentList & other)

Swaps the data component lists.

Permanent data components are kept in original data component list (and copied to other list). Temporary data components are removed from both lists.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close