Loading...
Searching...
No Matches
meshkit::plan::ReadArray< T > Class Template Reference

Read-only array that either owns its elements or reads them from borrowed storage. More...

#include <meshkit/detail/planmodel.hpp>

Inheritance diagram for meshkit::plan::ReadArray< T >:
Collaboration diagram for meshkit::plan::ReadArray< T >:

Classes

struct  Iterator
 Minimal iterator for range-based for loops: supports only *, prefix ++ and !=, and yields elements by value through operator[]. More...
 

Public Member Functions

void borrow (const void *owner, std::ptrdiff_t count, T(*read)(const void *, std::size_t))
 View external storage instead of the owned elements, which are left unchanged.
 
std::ptrdiff_t size () const
 Borrowed count while borrowing, otherwise the owned element count.
 
bool isEmpty () const
 Return true when size() is 0.
 
T operator[] (std::size_t i) const
 Element i, from the borrowed storage or the owned elements.
 
Iterator begin () const
 Iterator at index 0.
 
Iterator end () const
 Iterator at index size().
 
- Public Member Functions inherited from meshkit::detail::Vector< T >
 Vector ()=default
 Empty vector.
 
 Vector (const std::vector< T > &v)
 Copy the elements of a std::vector.
 
 Vector (std::vector< T > &&v)
 Take over the buffer of a std::vector without copying elements.
 
decltype(auto) first ()
 Reference to the first element (front()); the vector must not be empty.
 
decltype(auto) first () const
 Read-only reference to the first element; the vector must not be empty.
 
decltype(auto) last ()
 Reference to the last element (back()); the vector must not be empty.
 
decltype(auto) last () const
 Read-only reference to the last element; the vector must not be empty.
 
const T * constData () const
 Read-only pointer to the contiguous elements (data()).
 
Vector mid (std::ptrdiff_t at, std::ptrdiff_t count=-1) const
 Copy of a contiguous run of elements.
 
void prepend (const T &v)
 Insert a copy of v before the first element; linear in size().
 
void append (const Vector &v)
 Append copies of all elements of v.
 
Vector & operator+= (const Vector &v)
 Append copies of all elements of v; same as append(const Vector &).
 
Vector & operator<< (const T &v)
 Append one element.
 
std::ptrdiff_t size () const noexcept
 Number of elements as a signed std::ptrdiff_t.
 
bool isEmpty () const
 True when the vector holds no elements.
 
void append (const T &v)
 Append a copy of v (push_back).
 
void append (T &&v)
 Append v by move (push_back).
 
T takeLast ()
 Remove the last element and return it by move; the vector must not be empty.
 
T takeFirst ()
 Remove the first element and return it by move; linear in size().
 
void removeLast ()
 Remove the last element (pop_back); the vector must not be empty.
 
void removeAt (int at)
 Erase one element; the elements after it shift down by one.
 
void fill (const T &v)
 Assign v to every existing element; the size is unchanged.
 
void fill (const T &v, std::size_t size)
 Replace the contents with size copies of v (assign()).
 
bool contains (const T &v) const
 Linear search with operator==.
 

Detailed Description

template<class T>
class meshkit::plan::ReadArray< T >

Read-only array that either owns its elements or reads them from borrowed storage.

Until borrow() is given a non-null owner, size(), operator[] and iteration use the owned Vector<T> elements. After borrow() they report the borrowed count instead and fetch each element by value through the supplied read function, so a container of another element type can be viewed without copying it. Members inherited from Vector<T> (first(), data(), append(), ...) always act on the owned elements, as does any access through a Vector<T> reference, because size() and operator[] hide rather than override the base members.

Template Parameters
TElement type, returned by value.

Member Function Documentation

◆ begin()

template<class T>
Iterator meshkit::plan::ReadArray< T >::begin ( ) const
inline

Iterator at index 0.

◆ borrow()

template<class T>
void meshkit::plan::ReadArray< T >::borrow ( const void * owner,
std::ptrdiff_t count,
T(* read )(const void *, std::size_t) )
inline

View external storage instead of the owned elements, which are left unchanged.

Parameters
[in]ownerOpaque pointer passed back to read; not owned. It must stay valid and unchanged for as long as this array is read. nullptr returns to the owned elements.
[in]countNumber of borrowed elements reported by size(); must be >= 0.
[in]readFunction returning element i of owner by value. It is called on every element access without a bounds check and must be non-null when owner is non-null.

◆ end()

template<class T>
Iterator meshkit::plan::ReadArray< T >::end ( ) const
inline

Iterator at index size().

Here is the call graph for this function:

◆ isEmpty()

template<class T>
bool meshkit::plan::ReadArray< T >::isEmpty ( ) const
inline

Return true when size() is 0.

Here is the call graph for this function:

◆ operator[]()

template<class T>
T meshkit::plan::ReadArray< T >::operator[] ( std::size_t i) const
inline

Element i, from the borrowed storage or the owned elements.

Parameters
[in]iIndex in [0, size()); not bounds-checked.
Returns
A copy of the element.
Here is the call graph for this function:

◆ size()

template<class T>
std::ptrdiff_t meshkit::plan::ReadArray< T >::size ( ) const
inline

Borrowed count while borrowing, otherwise the owned element count.

Here is the call graph for this function:
Here is the caller graph for this function:

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