LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
LLU::DataList< T > Class Template Reference

Description

template<typename T>
class LLU::DataList< T >

Top-level wrapper over LibraryLink's DataStore.

Designed to be strongly typed i.e. to wrap only homogeneous DataStores but by passing NodeType::Any as template parameter it will work with arbitrary DataStores.

Template Parameters
T- type of data stored in each node, see the NodeType namespace for possible node types
+ Inheritance diagram for LLU::DataList< T >:
+ Collaboration diagram for LLU::DataList< T >:

#include <DataList.h>

Public Types

using iterator = NodeIterator< T >
 Default DataList iterator is NodeIterator<T> More...
 
using const_iterator = iterator
 All DataList iterators are proxy iterators so in a way they are all const, therefore const_iterator is the same as iterator. More...
 
using value_iterator = NodeValueIterator< T >
 To iterate over node values use a proxy iterator NodeValueIterator<T> More...
 
using name_iterator = NodeNameIterator
 To iterate over node names use a proxy iterator NodeNameIterator. More...
 
using value_type = T
 Value of a node is of type T. More...
 
using Container = Argument::CType< Type >
 The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container". More...
 

Public Member Functions

 DataList (GenericDataList gds)
 Create DataList wrapping around an existing GenericDataList. More...
 
 DataList (std::initializer_list< value_type > initList)
 Create DataList from list of values. More...
 
 DataList (std::initializer_list< std::pair< std::string, value_type >> initList)
 Create DataList from list of keys and corresponding values. More...
 
DataList clone () const
 Clone this DataList, performing a deep copy of the underlying DataStore. More...
 
iterator begin () const
 Get iterator at the beginning of underlying data. More...
 
const_iterator cbegin () const
 Get constant iterator at the beginning of underlying data. More...
 
iterator end () const
 Get iterator after the end of underlying data. More...
 
const_iterator cend () const
 Get constant reverse iterator after the end of underlying data. More...
 
value_iterator valueBegin () const
 Get proxy iterator over node values pointing to the first node. More...
 
value_iterator valueEnd () const
 Get proxy iterator over node values pointing past the last node. More...
 
name_iterator nameBegin () const
 Get proxy iterator over node names (keys) pointing to the first node. More...
 
name_iterator nameEnd () const
 Get proxy iterator over node names (keys) pointing past the last node. More...
 
void push_back (value_type nodeData)
 Add new node to the DataList. More...
 
void push_back (std::string_view name, value_type nodeData)
 Add new named node to the DataList. More...
 
std::vector< T > values () const
 Return a vector of DataList node values. More...
 
std::vector< std::string > names () const
 Return a vector of DataList node names. More...
 
std::vector< DataNode< T > > toVector () const
 Return a vector of DataList nodes. More...
 
mint length () const
 Get the length of the DataStore. More...
 
DataStoreNode front () const
 Get the first node of the DataStore. More...
 
DataStoreNode back () const
 Get the last node of the DataStore. More...
 
template<MArgumentType Type, EnableIfUnambiguousWrapperType< Type > = 0>
void push_back (Argument::WrapperType< Type > nodeValue)
 Add new nameless node at the end of the underlying DataStore. More...
 
template<MArgumentType Type, EnableIfUnambiguousWrapperType< Type > = 0>
void push_back (std::string_view name, Argument::WrapperType< Type > nodeValue)
 Add new named node at the end of the underlying DataStore. More...
 
template<MArgumentType Type>
void push_back (Argument::CType< Type > nodeValue)
 Add new nameless node at the end of the underlying DataStore. More...
 
template<MArgumentType Type>
void push_back (std::string_view name, Argument::CType< Type > nodeValue)
 Add new named node at the end of the underlying DataStore. More...
 
void push_back (const Argument::Typed::Any &node)
 Add new nameless node at the end of the underlying DataStore. More...
 
void push_back (std::string_view name, const Argument::Typed::Any &node)
 Add new named node at the end of the underlying DataStore. More...
 
Container getContainer () const noexcept
 Get internal container. More...
 
Container abandonContainer () const noexcept
 Give a handle to internal container and stop owning it. More...
 
mint shareCount () const noexcept
 Return share count of internal container, if present and 0 otherwise. More...
 
void pass (MArgument &res) const
 Pass the internal container as result of a LibraryLink function. More...
 
Ownership getOwner () const noexcept
 Get ownership information. More...
 

Protected Member Functions

Container cloneContainer () const
 Clone the raw container, if it's present. More...
 
void disown () const noexcept
 Disown internal container if present. More...
 
void free () const noexcept
 Free internal container if present. More...
 
void reset (Container newCont, Ownership newOwnerMode=Ownership::Library) noexcept
 Set a new internal container safely disposing of the old one. More...
 

Type aliases documentation

◆ const_iterator

template<typename T >
using LLU::DataList< T >::const_iterator = iterator

All DataList iterators are proxy iterators so in a way they are all const, therefore const_iterator is the same as iterator.

◆ Container

using LLU::MContainerBase< Type >::Container = Argument::CType<Type>
inherited

The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container".

◆ iterator

template<typename T >
using LLU::DataList< T >::iterator = NodeIterator<T>

Default DataList iterator is NodeIterator<T>

◆ name_iterator

template<typename T >
using LLU::DataList< T >::name_iterator = NodeNameIterator

To iterate over node names use a proxy iterator NodeNameIterator.

◆ value_iterator

template<typename T >
using LLU::DataList< T >::value_iterator = NodeValueIterator<T>

To iterate over node values use a proxy iterator NodeValueIterator<T>

◆ value_type

template<typename T >
using LLU::DataList< T >::value_type = T

Value of a node is of type T.

Constructor & Destructor Documentation

◆ DataList() [1/3]

template<typename T >
LLU::DataList< T >::DataList ( GenericDataList< T >  gds)
explicit

Create DataList wrapping around an existing GenericDataList.

Parameters
gds- GenericDataList

◆ DataList() [2/3]

template<typename T >
LLU::DataList< T >::DataList ( std::initializer_list< value_type initList)

Create DataList from list of values.

Keys will be set to empty strings.

Parameters
initList- list of values to put in the DataList
Note
This constructor can only be used if value_type is copyable.

◆ DataList() [3/3]

template<typename T >
LLU::DataList< T >::DataList ( std::initializer_list< std::pair< std::string, value_type >>  initList)

Create DataList from list of keys and corresponding values.

Parameters
initList- list of pairs key - value to put in the DataList
Note
This constructor can only be used if value_type is copyable.

Member Function Documentation

◆ abandonContainer()

Container LLU::MContainerBase< Type >::abandonContainer
inlinenoexceptinherited

Give a handle to internal container and stop owning it.

Should be used with caution as it may potentially result with resource leak.

Returns
a handle to the internal container

◆ back()

DataStoreNode LLU::MContainer< MArgumentType::DataStore >::back ( ) const
inlineinherited

Get the last node of the DataStore.

Returns
last node, if it doesn't exist the behavior is undefined

◆ begin()

template<typename T >
iterator LLU::DataList< T >::begin ( ) const
inline

Get iterator at the beginning of underlying data.

◆ cbegin()

template<typename T >
const_iterator LLU::DataList< T >::cbegin ( ) const
inline

Get constant iterator at the beginning of underlying data.

◆ cend()

template<typename T >
const_iterator LLU::DataList< T >::cend ( ) const
inline

Get constant reverse iterator after the end of underlying data.

◆ clone()

template<typename T >
DataList< T > LLU::DataList< T >::clone

Clone this DataList, performing a deep copy of the underlying DataStore.

Note
The cloned DataStore always belongs to the library (Ownership::Library) because LibraryLink has no idea of its existence.
Returns
new DataList

◆ cloneContainer()

Container LLU::MContainerBase< Type >::cloneContainer
inlineprotectedinherited

Clone the raw container, if it's present.

Returns
cloned container or nullptr if there is no internal container

◆ disown()

void LLU::MContainerBase< Type >::disown
inlineprotectednoexceptinherited

Disown internal container if present.

◆ end()

template<typename T >
iterator LLU::DataList< T >::end ( ) const
inline

Get iterator after the end of underlying data.

◆ free()

void LLU::MContainerBase< Type >::free
inlineprotectednoexceptinherited

Free internal container if present.

◆ front()

DataStoreNode LLU::MContainer< MArgumentType::DataStore >::front ( ) const
inlineinherited

Get the first node of the DataStore.

Returns
first node, if it doesn't exist the behavior is undefined

◆ getContainer()

Container LLU::MContainerBase< Type >::getContainer
inlinenoexceptinherited

Get internal container.

Returns
a handle to the internal container

◆ getOwner()

Ownership LLU::MContainerBase< Type >::getOwner
inlinenoexceptinherited

Get ownership information.

Returns
the owner of the internal container

◆ length()

mint LLU::MContainer< MArgumentType::DataStore >::length ( ) const
inlineinherited

Get the length of the DataStore.

Returns
total number of nodes in the DataStore

◆ nameBegin()

template<typename T >
name_iterator LLU::DataList< T >::nameBegin ( ) const
inline

Get proxy iterator over node names (keys) pointing to the first node.

◆ nameEnd()

template<typename T >
name_iterator LLU::DataList< T >::nameEnd ( ) const
inline

Get proxy iterator over node names (keys) pointing past the last node.

◆ names()

template<typename T >
std::vector<std::string> LLU::DataList< T >::names ( ) const
inline

Return a vector of DataList node names.

Returns
a std::vector of node names

◆ pass()

void LLU::MContainerBase< Type >::pass ( MArgument &  res) const
inlineinherited

Pass the internal container as result of a LibraryLink function.

Parameters
res- MArgument which will hold internal container of this MContainerBase

◆ push_back() [1/8]

template<MArgumentType Type>
void LLU::MContainer< MArgumentType::DataStore >::push_back ( Argument::CType< Type >  nodeValue)
inlineinherited

Add new nameless node at the end of the underlying DataStore.

Template Parameters
Type- type of the node data expressed via the MArgumentType enum
Parameters
nodeValue- a value to be pushed as the new node, must be of a primitive LibraryLink type

◆ push_back() [2/8]

template<MArgumentType Type, EnableIfUnambiguousWrapperType< Type > = 0>
void LLU::MContainer< MArgumentType::DataStore >::push_back ( Argument::WrapperType< Type >  nodeValue)
inlineinherited

Add new nameless node at the end of the underlying DataStore.

Template Parameters
Type- type of the node data expressed via the MArgumentType enum
Parameters
nodeValue- a value to be pushed as the new node, must be a wrapper over a primitive LibraryLink type

◆ push_back() [3/8]

void LLU::MContainer< MArgumentType::DataStore >::push_back ( const Argument::Typed::Any node)
inherited

Add new nameless node at the end of the underlying DataStore.

Parameters
node- a value to be pushed as the new node

◆ push_back() [4/8]

template<MArgumentType Type>
void LLU::MContainer< MArgumentType::DataStore >::push_back ( std::string_view  name,
Argument::CType< Type >  nodeValue 
)
inlineinherited

Add new named node at the end of the underlying DataStore.

Template Parameters
Type- type of the node data expressed via the MArgumentType enum
Parameters
name- name of the new node, names in a DataStore do not have to be unique
nodeValue- a value to be pushed as the new node, must be of a primitive LibraryLink type

◆ push_back() [5/8]

template<MArgumentType Type, EnableIfUnambiguousWrapperType< Type > = 0>
void LLU::MContainer< MArgumentType::DataStore >::push_back ( std::string_view  name,
Argument::WrapperType< Type >  nodeValue 
)
inlineinherited

Add new named node at the end of the underlying DataStore.

Template Parameters
Type- type of the node data expressed via the MArgumentType enum
Parameters
name- name of the new node, names in a DataStore do not have to be unique
nodeValue- a value to be pushed as the new node, must be a wrapper over a primitive LibraryLink type

◆ push_back() [6/8]

void LLU::MContainer< MArgumentType::DataStore >::push_back ( std::string_view  name,
const Argument::Typed::Any node 
)
inherited

Add new named node at the end of the underlying DataStore.

Parameters
name- name of the new node, names in a DataStore do not have to be unique
node- a value to be pushed as the new node,

◆ push_back() [7/8]

template<typename T >
void LLU::DataList< T >::push_back ( std::string_view  name,
value_type  nodeData 
)

Add new named node to the DataList.

Parameters
name- name for the new node
nodeData- actual data to store in the new node

◆ push_back() [8/8]

template<typename T >
void LLU::DataList< T >::push_back ( value_type  nodeData)

Add new node to the DataList.

Parameters
nodeData- actual data to store in the new node

◆ reset()

void LLU::MContainerBase< Type >::reset ( Container  newCont,
Ownership  newOwnerMode = Ownership::Library 
)
inlineprotectednoexceptinherited

Set a new internal container safely disposing of the old one.

Parameters
newCont- new internal container
newOwnerMode- owner of the new container

◆ shareCount()

mint LLU::MContainerBase< Type >::shareCount
inlinenoexceptinherited

Return share count of internal container, if present and 0 otherwise.

◆ toVector()

template<typename T >
std::vector<DataNode<T> > LLU::DataList< T >::toVector ( ) const
inline

Return a vector of DataList nodes.

Returns
a std::vector of nodes in the form of DataNode<T> objects

◆ valueBegin()

template<typename T >
value_iterator LLU::DataList< T >::valueBegin ( ) const
inline

Get proxy iterator over node values pointing to the first node.

◆ valueEnd()

template<typename T >
value_iterator LLU::DataList< T >::valueEnd ( ) const
inline

Get proxy iterator over node values pointing past the last node.

◆ values()

template<typename T >
std::vector<T> LLU::DataList< T >::values ( ) const
inline

Return a vector of DataList node values.

Returns
a std::vector of node values