Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::ParallelVectorTuple< Types > Class Template Reference

A class that holds multiple vectors of different types in a tuple, constraind to the same size. More...

#include <vclib/space/core/parallel_vector_tuple.h>

Public Member Functions

void clear ()
 Clears all enabled vectors and resets the size of the parallel vector tuple to zero.
 
void disableAllVectors ()
 Disables all vectors in the tuple.
 
template<uint I>
void disableVector ()
 Disables the vector at the given index.
 
void enableAllVectors ()
 Enables all vectors in the tuple.
 
template<uint I>
void enableVector ()
 Enables the vector at the given index.
 
template<uint I>
bool isVectorEnabled () const
 Returns whether a vector at a given index is enabled.
 
 ParallelVectorTuple ()
 Constructs a ParallelVectorTuple with all vectors enabled.
 
void reserve (std::size_t size)
 Reserves space for all enabled vectors to the given size.
 
void resize (std::size_t size)
 Resizes all enabled vectors to the given size, and sets the current size of the parallel vector tuple.
 
std::size_t size () const
 Returns the size of the parallel vector tuple.
 
template<uint I>
auto span ()
 Returns a std::span to the vector at the given index.
 
template<uint I>
auto span () const
 Returns a const std::span to the vector at the given index.
 

Static Public Member Functions

static constexpr uint tupleSize ()
 The number of vectors in the tuple.
 

Static Public Attributes

static constexpr uint TUPLE_SIZE = std::tuple_size_v<VecTuple>
 The number of vectors in the tuple.
 

Private Types

using VecTuple = std::tuple< std::vector< Types >... >
 

Private Member Functions

template<std::size_t N>
void applyToAllEnabledVectors (auto &&func)
 

Private Attributes

std::size_t mSize = 0
 
std::array< bool, TUPLE_SIZEmVecEnabled
 
VecTuple mVecTuple
 

Detailed Description

template<typename... Types>
class vcl::ParallelVectorTuple< Types >

A class that holds multiple vectors of different types in a tuple, constraind to the same size.

This class is designed to hold multiple std::vector instances, each of a different type, in a tuple-like structure. The size of all vectors is constrained to be the same, and operations like resize, reserve, and clear are applied to all vectors simultaneously.

Each vector can be accessed, trough the index of its type in the template parameter pack, using the span() member function. It will allow to access to its elements.

The class also supports enabling and disabling individual vectors, which allows for selective operations on the contained vectors. Disabled vectors are not resized or reserved, and their contents are cleared when disabled.

The class stores the current size of the vectors, which changes only when resize or clear members are called. The size is not changed when enabling or disabling vectors (even when all vectors are disabled, the size remains unchanged).

Member Function Documentation

◆ disableAllVectors()

template<typename... Types>
void vcl::ParallelVectorTuple< Types >::disableAllVectors ( )
inline

Disables all vectors in the tuple.

All the vectors in the tuple are disabled, and their contents are cleared. The size of the parallel vector tuple remains unchanged.

◆ disableVector()

template<typename... Types>
template<uint I>
void vcl::ParallelVectorTuple< Types >::disableVector ( )
inline

Disables the vector at the given index.

At the end of the operation, the vectori si cleared and all the elements are removed. The size of the parallel vector tuple remains unchanged.

Template Parameters
IThe index of the vector to disable.

◆ enableAllVectors()

template<typename... Types>
void vcl::ParallelVectorTuple< Types >::enableAllVectors ( )
inline

Enables all vectors in the tuple.

All the vectors in the tuple are enabled, and their sizes are set to the current size of the parallel vector tuple.

◆ enableVector()

template<typename... Types>
template<uint I>
void vcl::ParallelVectorTuple< Types >::enableVector ( )
inline

Enables the vector at the given index.

At the end of the operation, the vector is resized to the current size of the parallel vector tuple, and its elements are initialized to their default values.

Note
If the vector was already enabled, this operation has no effect.
Template Parameters
IThe index of the vector to enable.

◆ isVectorEnabled()

template<typename... Types>
template<uint I>
bool vcl::ParallelVectorTuple< Types >::isVectorEnabled ( ) const
inline

Returns whether a vector at a given index is enabled.

Template Parameters
IThe index of the vector to check.
Returns
True if the vector at index I is enabled, false otherwise.

◆ reserve()

template<typename... Types>
void vcl::ParallelVectorTuple< Types >::reserve ( std::size_t  size)
inline

Reserves space for all enabled vectors to the given size.

Note
This does not change the size of the vectors, it only reserves space.
Parameters
[in]sizeThe new size to reserve for all enabled vectors.

◆ resize()

template<typename... Types>
void vcl::ParallelVectorTuple< Types >::resize ( std::size_t  size)
inline

Resizes all enabled vectors to the given size, and sets the current size of the parallel vector tuple.

Parameters
[in]sizeThe new size to set for all enabled vectors.

◆ size()

template<typename... Types>
std::size_t vcl::ParallelVectorTuple< Types >::size ( ) const
inline

Returns the size of the parallel vector tuple.

Note
The size is the same for all vectors in the tuple and it does not change if the vectors are enabled or disabled. This means that even if all the vectors are disabled, this size could be greater than zero.
Returns
The size of the parallel vector tuple.

◆ span() [1/2]

template<typename... Types>
template<uint I>
auto vcl::ParallelVectorTuple< Types >::span ( )
inline

Returns a std::span to the vector at the given index.

This function allows access to the elements of the vector at the specified index, throwing an exception if the vector is disabled.

Exceptions
std::runtime_errorif the vector at index I is disabled.
Returns
A std::span to the vector at index I.

◆ span() [2/2]

template<typename... Types>
template<uint I>
auto vcl::ParallelVectorTuple< Types >::span ( ) const
inline

Returns a const std::span to the vector at the given index.

This function allows access to the elements of the vector at the specified index, throwing an exception if the vector is disabled.

Exceptions
std::runtime_errorif the vector at index I is disabled.
Returns
A const std::span to the vector at index I.

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