Skip to content

DIWNE::ForwardNodeIterator

A simple forward node iterator for DIWNE node containers that is used as a base implementation for other iterators. More...

#include "DIWNE/Core/diwne_iterators.h"

Inherits from DIWNE::ForwardIteratorBase< Iterator, NodeType, IsConst >

Inherited by DIWNE::BidirectionalNodeIterator< NodeIteratorImpl< Node, IsConst >, Node, IsConst >, DIWNE::BidirectionalNodeIterator< FilteredNodeIterator< Node >, Node, IsConst >, DIWNE::BidirectionalNodeIterator< NodeIteratorImpl< NodeType, IsConst >, NodeType, IsConst >, DIWNE::RecursiveNodeIteratorImpl< FilteredRecursiveNodeIterator< Node >, Node >, DIWNE::RecursiveNodeIteratorImpl< RecursiveNodeIterator< Node >, Node >, DIWNE::BidirectionalNodeIterator< Iterator, NodeType, IsConst >

Public Types

Name
using const NodeList *Container
using std::shared_ptr< typename Super::value_type >shared_pointer

Protected Types

Name
using ForwardIteratorBase< Iterator, NodeType, IsConst >Super

Public Functions

Name
ForwardNodeIterator()
ForwardNodeIterator(Container nodes, std::size_t idx)
referencedereference() const
boolequals(const Iterator & b) const<br>Determines whether this iterator is pointing to the same element as another one (used by the == operator)
voidnext()<br>Advance the iterator.
pointerptr() const
shared_pointersharedPtr() const
boolvalid() const<br>Check whether the iterator is pointing at a valid element (eg. not the end of a container)

Protected Attributes

Name
std::size_t_idx <br>Current node index // TODO: Should probably be an int.
Container_nodes <br>Reference to the node list.

Additional inherited members

Public Types inherited from DIWNE::ForwardIteratorBase< Iterator, NodeType, IsConst >

Name
using std::ptrdiff_tdifference_type
using std::forward_iterator_tagiterator_category
using typename std::conditional< IsConst, const Value *, Value * >::typepointer
using typename std::conditional< IsConst, const Value &, Value & >::typereference
using typename std::conditional< IsConst, const Value, Value >::typevalue_type

Public Functions inherited from DIWNE::ForwardIteratorBase< Iterator, NodeType, IsConst >

Name
referenceoperator*()
Iterator &operator++()
Iteratoroperator++(int )
pointeroperator->()

Protected Functions inherited from DIWNE::ForwardIteratorBase< Iterator, NodeType, IsConst >

Name
ForwardIteratorBase()
virtual~ForwardIteratorBase() =default
Iterator *self()<br>CRTP self pointer (pointer to the derived type)
const Iterator *self() const<br>CRTP const self pointer.

Friends inherited from DIWNE::ForwardIteratorBase< Iterator, NodeType, IsConst >

Name
booloperator!=(const Iterator & a, const Iterator & b)
booloperator==(const Iterator & a, const Iterator & b)

Detailed Description

cpp
template <typename Iterator ,
typename NodeType ,
bool IsConst>
class DIWNE::ForwardNodeIterator;
template <typename Iterator ,
typename NodeType ,
bool IsConst>
class DIWNE::ForwardNodeIterator;

A simple forward node iterator for DIWNE node containers that is used as a base implementation for other iterators.

Template Parameters:

  • Iterator The CRTP derived iterator

Note: Both regular dynamic and CRTP static inheritance is used in the iterators. For performance reasons iterators often rely on static (compile time) inheritance to avoid virtual call overhead. For clarity virtual calls are used.

Node iterators are essentially a pair of a vector of node pointers and an index pointing to one of them.

Node iterators are mainly to be used for read only iteration in order to avoid costly construction of filtered containers.

Currently all the iterators wrap the default owning NodeList (std::vector<std::shared_ptr<Node>>). Eg. a list of shared pointers to nodes. A reference is kept to this list and dereferencing an iterator return a reference or raw pointer to a single node. An owning shared pointer can be retrieved from the reference or raw pointer by calling the sharedPtr() method. Or by just calling shared_from_this() directly as all DiwneObjects are std::enable_shared_from_this objects.

The iterator itself can be iterated over like a container using its begin() and end() methods. This is to avoid having an intermediary container for each iterator type and to simplify range based for loops. CRTP and inheritance is used mostly to just reduce code duplication and generally a derived iterator shouldn't be casted to its parent type.

The iterators attempt to comply with C++ legacy (pre C++20) iterator named requirements, but aren't necessarily guaranteed to work well with the rest of the standard library.

Public Types Documentation

using Container

cpp
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::Container =  const NodeList*;
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::Container =  const NodeList*;

using shared_pointer

cpp
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::shared_pointer =  std::shared_ptr<typename Super::value_type>;
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::shared_pointer =  std::shared_ptr<typename Super::value_type>;

Protected Types Documentation

using Super

cpp
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::Super =  ForwardIteratorBase<Iterator, NodeType, IsConst>;
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::Super =  ForwardIteratorBase<Iterator, NodeType, IsConst>;

Public Functions Documentation

function ForwardNodeIterator

cpp
inline ForwardNodeIterator()
inline ForwardNodeIterator()

function ForwardNodeIterator

cpp
inline ForwardNodeIterator(
    Container nodes,
    std::size_t idx
)
inline ForwardNodeIterator(
    Container nodes,
    std::size_t idx
)

function dereference

cpp
inline reference dereference() const
inline reference dereference() const

function equals

cpp
inline bool equals(
    const Iterator & b
) const
inline bool equals(
    const Iterator & b
) const

Determines whether this iterator is pointing to the same element as another one (used by the == operator)

function next

cpp
inline void next()
inline void next()

Advance the iterator.

function ptr

cpp
inline pointer ptr() const
inline pointer ptr() const

function sharedPtr

cpp
inline shared_pointer sharedPtr() const
inline shared_pointer sharedPtr() const

function valid

cpp
inline bool valid() const
inline bool valid() const

Check whether the iterator is pointing at a valid element (eg. not the end of a container)

Protected Attributes Documentation

variable _idx

cpp
std::size_t _idx {0};
std::size_t _idx {0};

Current node index // TODO: Should probably be an int.

variable _nodes

cpp
Container _nodes {nullptr};
Container _nodes {nullptr};

Reference to the node list.


Updated on 2025-05-31 at 12:55:31 +0000