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) | |
reference | dereference() const |
bool | equals(const Iterator & b) const<br>Determines whether this iterator is pointing to the same element as another one (used by the == operator) |
void | next()<br>Advance the iterator. |
pointer | ptr() const |
shared_pointer | sharedPtr() const |
bool | valid() 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_t | difference_type |
using std::forward_iterator_tag | iterator_category |
using typename std::conditional< IsConst, const Value *, Value * >::type | pointer |
using typename std::conditional< IsConst, const Value &, Value & >::type | reference |
using typename std::conditional< IsConst, const Value, Value >::type | value_type |
Public Functions inherited from DIWNE::ForwardIteratorBase< Iterator, NodeType, IsConst >
Name | |
---|---|
reference | operator*() |
Iterator & | operator++() |
Iterator | operator++(int ) |
pointer | operator->() |
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 | |
---|---|
bool | operator!=(const Iterator & a, const Iterator & b) |
bool | operator==(const Iterator & a, const Iterator & b) |
Detailed Description
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
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::Container = const NodeList*;
using DIWNE::ForwardNodeIterator< Iterator, NodeType, IsConst >::Container = const NodeList*;
using shared_pointer
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
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
inline ForwardNodeIterator()
inline ForwardNodeIterator()
function ForwardNodeIterator
inline ForwardNodeIterator(
Container nodes,
std::size_t idx
)
inline ForwardNodeIterator(
Container nodes,
std::size_t idx
)
function dereference
inline reference dereference() const
inline reference dereference() const
function equals
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
inline void next()
inline void next()
Advance the iterator.
function ptr
inline pointer ptr() const
inline pointer ptr() const
function sharedPtr
inline shared_pointer sharedPtr() const
inline shared_pointer sharedPtr() const
function valid
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
std::size_t _idx {0};
std::size_t _idx {0};
Current node index // TODO: Should probably be an int.
variable _nodes
Container _nodes {nullptr};
Container _nodes {nullptr};
Reference to the node list.
Updated on 2025-05-31 at 12:55:31 +0000