pbpt
Loading...
Searching...
No Matches
pbpt::math::VectorView< T, N > Class Template Reference

A non-owning, mutable view/proxy of vector-like data. More...

#include <matrix.hpp>

Public Member Functions

constexpr VectorView (const T *start, int stride)
 Constructs a read-only vector view.
constexpr const T & operator[] (int i) const
 Provides read-only access to an element of the view.
constexpr const T & at (int i) const
 Provides read-only access to an element of the view.
constexpr int dims () const noexcept
 Returns the number of dimensions of the view.
constexpr T dot (const Vector< T, N > &rhs) const
 Calculates the dot product with an owning vector.
constexpr T dot (const VectorView< T, N > &rhs) const
 Calculates the dot product with another vector view.
constexpr Vector< T, N > to_vector () const
 Converts the view into a new, owning Vec instance.
constexpr T & operator[] (int i)
 Provides mutable access to an element of the view.
constexpr T & at (int i)
 Provides mutable access to an element of the view.
constexpr VectorViewoperator= (const Vector< T, N > &other)
 Assigns an owning vector's content to the region represented by this view.
constexpr VectorViewoperator= (const VectorView< T, N > &other)
 Assigns another vector view's content to the region represented by this view.
void apply (const std::function< void(T &, int)> &func)
 Applies a function to each element of the view.

Protected Attributes

const T * m_start_ptr
 Pointer to the first element of the viewed data.
int m_stride
 The distance (in number of elements) between consecutive elements in the view.

Detailed Description

template<typename T, int N>
class pbpt::math::VectorView< T, N >

A non-owning, mutable view/proxy of vector-like data.

Extends ConstVectorView to allow modification of the underlying data.

Constructor & Destructor Documentation

◆ VectorView()

template<typename T, int N>
pbpt::math::VectorView< T, N >::VectorView ( const T * start,
int stride )
inlineconstexpr

Constructs a read-only vector view.

Parameters
startPointer to the first element.
strideThe step size to move between elements. For a row view, this is 1. For a column view, this is the column count of the source matrix.

Member Function Documentation

◆ apply()

template<typename T, int N>
void pbpt::math::VectorView< T, N >::apply ( const std::function< void(T &, int)> & func)
inline

Applies a function to each element of the view.

Parameters
funcThe function to apply.

◆ at() [1/2]

template<typename T, int N>
T & pbpt::math::VectorView< T, N >::at ( int i)
inlineconstexpr

Provides mutable access to an element of the view.

Parameters
iThe index of the element.
Returns
A mutable reference to the element in the original data source.

◆ at() [2/2]

template<typename T, int N>
const T & pbpt::math::VectorView< T, N >::at ( int i) const
inlineconstexpr

Provides read-only access to an element of the view.

Parameters
iThe index of the element.
Returns
A const reference to the element in the original data source.

◆ dot() [1/2]

template<typename T, int N>
T pbpt::math::VectorView< T, N >::dot ( const Vector< T, N > & rhs) const
inlineconstexpr

Calculates the dot product with an owning vector.

Parameters
rhsThe other vector.
Returns
The scalar dot product.

◆ dot() [2/2]

template<typename T, int N>
T pbpt::math::VectorView< T, N >::dot ( const VectorView< T, N > & rhs) const
inlineconstexpr

Calculates the dot product with another vector view.

Parameters
rhsThe other vector view.
Returns
The scalar dot product.

◆ operator=() [1/2]

template<typename T, int N>
VectorView & pbpt::math::VectorView< T, N >::operator= ( const Vector< T, N > & other)
inlineconstexpr

Assigns an owning vector's content to the region represented by this view.

Parameters
otherThe vector to copy from.
Returns
A reference to this view.

◆ operator=() [2/2]

template<typename T, int N>
VectorView & pbpt::math::VectorView< T, N >::operator= ( const VectorView< T, N > & other)
inlineconstexpr

Assigns another vector view's content to the region represented by this view.

Parameters
otherThe vector view to copy from.
Returns
A reference to this view.

◆ operator[]() [1/2]

template<typename T, int N>
T & pbpt::math::VectorView< T, N >::operator[] ( int i)
inlineconstexpr

Provides mutable access to an element of the view.

Parameters
iThe index of the element.
Returns
A mutable reference to the element in the original data source.

◆ operator[]() [2/2]

template<typename T, int N>
const T & pbpt::math::VectorView< T, N >::operator[] ( int i) const
inlineconstexpr

Provides read-only access to an element of the view.

Parameters
iThe index of the element.
Returns
A const reference to the element in the original data source.

◆ to_vector()

template<typename T, int N>
Vector< T, N > pbpt::math::VectorView< T, N >::to_vector ( ) const
inlineconstexpr

Converts the view into a new, owning Vec instance.

This performs a copy of the elements from the viewed region.


The documentation for this class was generated from the following file:
  • /Users/jinceyang/Desktop/codebase/pbpt/engine/math/matrix.hpp