/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
Classes
Foam::expression::IteratorBase
Foam::expression::Iterator
Foam::expression::IteratorNew
Description
Iterator class which facilitates iteration through an expression
\*---------------------------------------------------------------------------*/
#ifndef expressionIterator_H
#define expressionIterator_H
#include "expressionOperate.H"
#include "expressionBound.H"
#include "expressionSelect.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace expression
{
/*---------------------------------------------------------------------------*\
Class IteratorBase Declaration
\*---------------------------------------------------------------------------*/
template class Iterator, class Expression>
struct IteratorBase
{
protected:
const Expression& e_;
using eiType = typename Operate>>::type;
eiType ei_;
public:
template
inline IteratorBase
(
const Expression& e,
const Bound&
)
:
e_(e),
ei_
(
Operate>>::access
(
e,
Bound()
)
)
{}
inline Iterator& operator++()
{
advance(e_, ei_);
return static_cast&>(*this);
}
inline Iterator operator++(int)
{
Iterator ei0(e_, ei_);
advance(e_, ei_);
return ei0;
}
inline bool operator==(const IteratorBase& iter) const
{
return compare(e_, ei_, iter.ei_);
}
inline bool operator!=(const IteratorBase& iter) const
{
return !compare(e_, ei_, iter.ei_);
}
};
/*---------------------------------------------------------------------------*\
Class Iterator Declaration
\*---------------------------------------------------------------------------*/
template
struct Iterator
:
public IteratorBase
{
using IteratorBase::IteratorBase;
typedef typename Operate
<
Expression,
Arguments::eiType>
>::type value_type;
value_type operator*() const
{
return access(this->e_, this->ei_);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Return an iterator pointing to the start of the expression
template
Iterator begin(const Expression& e)
{
return Iterator(e, Bound());
}
//- Return an iterator pointing to the end of the expression
template
Iterator end(const Expression& e)
{
return Iterator(e, Bound());
}
/*---------------------------------------------------------------------------*\
Class IteratorNew Declaration
\*---------------------------------------------------------------------------*/
template
struct IteratorNew
:
public IteratorBase
{
using IteratorBase::IteratorBase;
typedef typename Select::type value_type;
typename Select::type operator*() const
{
return New(access(this->e_, this->ei_));
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Return an iterator pointing to the start of the expression
template
IteratorNew beginNew(const Expression& e)
{
return IteratorNew(e, Bound());
}
//- Return an iterator pointing to the end of the expression
template
IteratorNew endNew(const Expression& e)
{
return IteratorNew(e, Bound());
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace expression
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template
struct std::iterator_traits
<
Foam::expression::Iterator
>
{
typedef Foam::label difference_type;
typedef typename
Foam::expression::Iterator::value_type
value_type;
typedef void pointer_type;
typedef void reference;
typedef std::forward_iterator_tag iterator_category;
};
template
struct std::iterator_traits
<
Foam::expression::IteratorNew
>
{
typedef Foam::label difference_type;
typedef typename
Foam::expression::IteratorNew::value_type
value_type;
typedef void pointer_type;
typedef void reference;
typedef std::forward_iterator_tag iterator_category;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //