// ------------------------------------------------------------------------ // // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (C) 2017 - 2023 by the deal.II authors // // This file is part of the deal.II library. // // Part of the source code is dual licensed under Apache-2.0 WITH // LLVM-exception OR LGPL-2.1-or-later. Detailed license information // governing the source code and code contributions can be found in // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. // // ------------------------------------------------------------------------ #ifndef dealii_particles_particle_iterator_h #define dealii_particles_particle_iterator_h #include #include DEAL_II_NAMESPACE_OPEN namespace Particles { // Forward declaration #ifndef DOXYGEN template class ParticleHandler; #endif /** * A class that is used to iterate over particles. Together with the * ParticleAccessor class this is used to hide the internal implementation * of the particle class and the particle container. */ template class ParticleIterator { public: /** * A type for the storage container for particles. */ using particle_container = typename ParticleAccessor::particle_container; /** * Empty constructor. Such an object is not usable! */ ParticleIterator() = default; /** * Constructor of the iterator. Takes a reference to the particle * container, an iterator to the cell, and the particle index within that * cell. */ ParticleIterator( const typename particle_container::iterator particles_in_cell, const PropertyPool &property_pool, const unsigned int particle_index_within_cell); /** * Dereferencing operator, returns a reference to an accessor. Usage is thus * like (*i).get_id (); */ const ParticleAccessor & operator*() const; /** * Dereferencing operator, non-@p const version. */ ParticleAccessor & operator*(); /** * Dereferencing operator, returns a pointer of the particle pointed to. * Usage is thus like i->get_id (); * * There is a @p const and a non-@p const version. */ const ParticleAccessor * operator->() const; /** * Dereferencing operator, non-@p const version. */ ParticleAccessor * operator->(); /** * Compare for equality. */ bool operator==(const ParticleIterator &) const; /** * Compare for inequality. */ bool operator!=(const ParticleIterator &) const; /** * Prefix ++ operator: ++iterator. This operator advances * the iterator to the next element and returns a reference to * *this. */ ParticleIterator & operator++(); /** * Postfix ++ operator: iterator++. This operator advances * the iterator to the next element, but returns an iterator to the element * previously pointed to. */ ParticleIterator operator++(int); /** * Prefix \-- operator: \--iterator. This operator moves * the iterator to the previous element and returns a reference to * *this. */ ParticleIterator & operator--(); /** * Postfix \-- operator: iterator\--. This operator moves * the iterator to the previous element, but returns an iterator to the * element previously pointed to. */ ParticleIterator operator--(int); /** * Return the state of the iterator. */ IteratorState::IteratorStates state() const; /** * Mark the class as bidirectional iterator and declare some alias which * are standard for iterators and are used by algorithms to enquire about * the specifics of the iterators they work on. */ using iterator_category = std::bidirectional_iterator_tag; using value_type = ParticleAccessor; using difference_type = std::ptrdiff_t; using pointer = ParticleAccessor *; using reference = ParticleAccessor &; private: /** * The accessor to the actual particle. */ ParticleAccessor accessor; }; // ------------------------------ inline functions ------------------------- template inline ParticleIterator::ParticleIterator( const typename particle_container::iterator particles_in_cell, const PropertyPool &property_pool, const unsigned int particle_index_within_cell) : accessor(particles_in_cell, property_pool, particle_index_within_cell) {} template inline ParticleAccessor & ParticleIterator::operator*() { return accessor; } template inline ParticleAccessor * ParticleIterator::operator->() { return &(this->operator*()); } template inline const ParticleAccessor & ParticleIterator::operator*() const { return accessor; } template inline const ParticleAccessor * ParticleIterator::operator->() const { return &(this->operator*()); } template inline bool ParticleIterator::operator!=( const ParticleIterator &other) const { return accessor != other.accessor; } template inline bool ParticleIterator::operator==( const ParticleIterator &other) const { return accessor == other.accessor; } template inline ParticleIterator & ParticleIterator::operator++() { accessor.next(); return *this; } template inline ParticleIterator ParticleIterator::operator++(int) { ParticleIterator tmp(*this); operator++(); return tmp; } template inline ParticleIterator & ParticleIterator::operator--() { accessor.prev(); return *this; } template inline ParticleIterator ParticleIterator::operator--(int) { ParticleIterator tmp(*this); operator--(); return tmp; } template inline IteratorState::IteratorStates ParticleIterator::state() const { return accessor.state(); } } // namespace Particles DEAL_II_NAMESPACE_CLOSE #endif