ImFusion SDK 4.3
OwningDataList Class Referencefinal

#include <ImFusion/Base/OwningDataList.h>

Wrapper class to store a list of owned Data instances. More...

Detailed Description

Wrapper class to store a list of owned Data instances.

Internally, this class is merely a std::vector<std::unique_ptr<Data>>. However, it provides a couple of convenience functions for filtering and extracting data. Use a plain DataList to model a view on a list of Data instances without ownership.

See also
DataList
Examples
ExampleAlgorithm.cpp, and ExampleAlgorithm.h.

Public Member Functions

 OwningDataList ()
 Default Constructor to create an empty list.
 
template<typename T>
 OwningDataList (std::unique_ptr< T > data)
 Convenience constructor from a single unique_ptr<Data>.
 
template<typename T>
 OwningDataList (std::vector< std::unique_ptr< T > > &&data)
 Constructor from a vector of data.
 
 OwningDataList (OwningDataList &&rhs) noexcept
 Move constructor will guarantee that rhs is empty and usable afterwards.
 
OwningDataListoperator= (OwningDataList &&rhs) noexcept
 Move assignment will guarantee that rhs is empty and usable afterwards.
 
 OwningDataList (const OwningDataList &)=delete
 
OwningDataListoperator= (const OwningDataList &)=delete
 
virtual void add (std::unique_ptr< Data > data)
 Add data to the list.
 
virtual void add (OwningDataList &&dataList)
 Add data to the list.
 
int size () const
 Return the size of the list.
 
int indexOf (const Data *data) const
 Returns the index of data within the list or -1 if it is not present.
 
void clear ()
 Clear all data.
 
bool operator== (const OwningDataList &other) const
 Returns true if the both OwningDataList have the same elements in the same order, false otherwise.
 
bool operator!= (const OwningDataList &other) const
 Returns false if the both OwningDataList have the same elements in the same order, true otherwise.
 

Static Public Member Functions

template<typename... Items>
static OwningDataList create (Items &&... items)
 Factory function creating an OwningDataList from a list of std::unique_ptr<T>, with T derived from Data.
 

Retrieving items from a OwningDataList

std::unique_ptr< DataextractItem (int which)
 Extract the Data instance of the given index.
 
std::unique_ptr< DataextractFirst (Data::Kind kind=Data::UNKNOWN)
 Extract the first Data instance of the given kind.
 
template<typename T>
std::unique_ptr< T > extractFirst (Data::Kind kind=Data::UNKNOWN)
 Extract the first Data instance of the given type and kind.
 
std::vector< std::unique_ptr< Data > > extractAll (Data::Kind kind=Data::UNKNOWN)
 Extract all Data instances of given kind.
 
template<typename T>
std::vector< std::unique_ptr< T > > extractAll (Data::Kind kind=Data::UNKNOWN)
 Extract all Data instances of given type and kind.
 
std::unique_ptr< SharedImageSetextractFirstImage (Data::Kind kind=Data::UNKNOWN, Data::Modality modality=Data::NA)
 Extract the first SharedImageSet instance of given kind and modality.
 
std::vector< std::unique_ptr< SharedImageSet > > extractAllImages (Data::Kind kind=Data::UNKNOWN, Data::Modality modality=Data::NA)
 Extract all SharedImageSet instances of given kind and modality.
 
Dataoperator[] (int idx)
 Array access; returns the data located in the underlying vector at the given index.
 
const Dataoperator[] (int idx) const
 Array access; returns the data located in the underlying vector at the given index.
 
DataList dataListView () const
 Return a view in form of a DataList onto this OwningDataList.
 

Access to the underlying std::vector holding the data.

std::vector< std::unique_ptr< Data > > & container ()
 
const std::vector< std::unique_ptr< Data > > & container () const
 
std::vector< std::unique_ptr< Data > >::const_iterator begin () const
 
std::vector< std::unique_ptr< Data > >::const_iterator end () const
 
std::vector< std::unique_ptr< Data > >::iterator begin ()
 
std::vector< std::unique_ptr< Data > >::iterator end ()
 

Constructor & Destructor Documentation

◆ OwningDataList() [1/2]

template<typename T>
OwningDataList ( std::unique_ptr< T > data)
explicit

Convenience constructor from a single unique_ptr<Data>.

Template Parameters
TData type, must inherit from Data.

◆ OwningDataList() [2/2]

template<typename T>
OwningDataList ( std::vector< std::unique_ptr< T > > && data)

Constructor from a vector of data.

Note
This constructor is deliberately implicit to allow for easy assignment of OwningDataList queries (i.e. extract-accessors) to OwningDataLists. For instance, you can write owningDataList2 = owningDataList1.extractAll<SharedImageSet>(); to extract all SharedImageSets from owningDataList1 and assign them to owningDataList2.
Template Parameters
TData type stored in the vector, must inherit from Data.

Member Function Documentation

◆ create()

template<typename... Items>
OwningDataList create ( Items &&... items)
static

Factory function creating an OwningDataList from a list of std::unique_ptr<T>, with T derived from Data.

auto dataList2 = OwningDataList::create(std::move(data1), std::move(data2), ...);
static OwningDataList create(Items &&... items)
Factory function creating an OwningDataList from a list of std::unique_ptr<T>, with T derived from Da...
Definition OwningDataList.h:175
T make_unique(T... args)
Template Parameters
Itemsparameter pack of std::unique_ptr<Data>.

◆ extractFirst() [1/2]

std::unique_ptr< Data > extractFirst ( Data::Kind kind = Data::UNKNOWN)

Extract the first Data instance of the given kind.

Data::UNKNOWN will match all kinds.

Note
This is a shortcut for extractFirst<Data>(kind).

◆ extractFirst() [2/2]

template<typename T>
std::unique_ptr< T > extractFirst ( Data::Kind kind = Data::UNKNOWN)
inline

Extract the first Data instance of the given type and kind.

Data::UNKNOWN will match all kinds.

◆ extractAll() [1/2]

Extract all Data instances of given kind.

Data::UNKNOWN will match all kinds.

Note
This is a shortcut for extractAll<Data>(kind).

◆ extractAll() [2/2]

template<typename T>
std::vector< std::unique_ptr< T > > extractAll ( Data::Kind kind = Data::UNKNOWN)

Extract all Data instances of given type and kind.

Data::UNKNOWN will match all kinds.

◆ extractFirstImage()

std::unique_ptr< SharedImageSet > extractFirstImage ( Data::Kind kind = Data::UNKNOWN,
Data::Modality modality = Data::NA )

Extract the first SharedImageSet instance of given kind and modality.

Data::UNKNOWN will match all kinds and Data::NA will match all modalities.

◆ extractAllImages()

Extract all SharedImageSet instances of given kind and modality.

Data::UNKNOWN will match all kinds and Data::NA will match all modalities.

◆ dataListView()

DataList dataListView ( ) const

Return a view in form of a DataList onto this OwningDataList.

This can be useful to keep references to the data after passing ownership to another consumer.


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