18 #ifndef LIBMESH_VARIANT_FILTER_ITERATOR_H
19 #define LIBMESH_VARIANT_FILTER_ITERATOR_H
28 #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__INTEL_COMPILER)
33 #include "libmesh/libmesh_common.h"
49 template<
class Predicate,
class Type,
class ReferenceType = Type &,
class PointerType = Type *,
50 class ConstType =
const Type,
class ConstReferenceType =
const Type &,
51 class ConstPointerType =
const Type *>
65 ConstType, ConstReferenceType, ConstPointerType>
Iterator;
79 virtual std::unique_ptr<IterBase>
clone()
const = 0;
84 virtual ReferenceType
operator*()
const = 0;
91 virtual bool equal(
const std::unique_ptr<IterBase> & other)
const = 0;
100 virtual std::unique_ptr<const_IterBase>
const_clone()
const = 0;
115 virtual std::unique_ptr<PredBase>
clone()
const = 0;
116 virtual bool operator()(
const std::unique_ptr<IterBase> & in)
const = 0;
125 virtual std::unique_ptr<const_PredBase>
const_clone()
const = 0;
137 template<
typename IterType>
157 virtual ~Iter () =
default;
163 virtual std::unique_ptr<IterBase>
clone()
const override
165 return std::make_unique<Iter<IterType>>(
iter_data);
172 virtual std::unique_ptr<typename IterBase::const_IterBase>
const_clone()
const override
178 return std::make_unique<const_Iter>(
iter_data);
204 virtual bool equal(
const std::unique_ptr<IterBase> & other)
const override
207 libMesh::cast_ptr<const Iter<IterType> *>(other.get());
237 template <
typename IterType,
typename PredType>
249 virtual ~Pred () =
default;
254 virtual std::unique_ptr<PredBase>
clone()
const override
256 return std::make_unique<Pred<IterType,PredType>>(
pred_data);
262 virtual std::unique_ptr<typename PredBase::const_PredBase>
const_clone()
const override
265 return std::make_unique<const_Pred>(
pred_data);
271 virtual bool operator() (
const std::unique_ptr<IterBase> & in)
const override
277 libMesh::cast_ptr<const Iter<IterType> *>(in.get());
301 std::unique_ptr<IterBase>
data;
307 std::unique_ptr<IterBase>
end;
314 std::unique_ptr<PredBase>
pred;
324 template<
typename PredType,
typename IterType>
327 const PredType & p ):
328 data ( std::make_unique<
Iter<IterType>>(d) ),
329 end ( std::make_unique<
Iter<IterType>>(e) ),
330 pred ( std::make_unique<
Pred<IterType,PredType>>(p) )
346 end (rhs.
end ? rhs.
end->clone() : nullptr),
360 template <
class OtherType,
class OtherReferenceType,
class OtherPointerType,
361 class OtherConstType,
class OtherConstReferenceType,
class OtherConstPointerType>
363 OtherConstType, OtherConstReferenceType, OtherConstPointerType> & rhs)
365 end (rhs.
end ? rhs.
end->const_clone() : nullptr),
430 std::swap (lhs.
end, rhs.
end);
467 template<
class Predicate,
class Type,
class ReferenceType,
class PointerType,
468 class OtherConstType,
class OtherConstReferenceType,
class OtherConstPointerType>
471 OtherConstType, OtherConstReferenceType, OtherConstPointerType> & x,
473 OtherConstType, OtherConstReferenceType, OtherConstPointerType> & y)
481 template<
class Predicate,
class Type,
class ReferenceType,
class PointerType,
482 class OtherConstType,
class OtherConstReferenceType,
class OtherConstPointerType>
485 OtherConstType, OtherConstReferenceType, OtherConstPointerType> & x,
487 OtherConstType, OtherConstReferenceType, OtherConstPointerType> & y)
494 #endif // LIBMESH_VARIANT_FILTER_ITERATOR_H
virtual std::unique_ptr< const_IterBase > const_clone() const =0
Similar to the clone() function.
The actual iterator object is held as a template parameter here.
Iterator & operator=(const Iterator &rhs)
Assignment operator.
Original Authors: Corwin Joy * Michael Gradman cjoy@houston.rr.com * Michael.Gradman@caminus.com Caminus, Suite 1150, Two Allen Center, 1200 Smith Street, Houston, TX 77002 This class is an extension of variant_bidirectional_iterator to a filter_iterator similar to boost's.
The actual predicate is held as a template parameter here.
std::forward_iterator_tag iterator_category
virtual ReferenceType operator*() const override
Dereferences the iterator.
std::ptrdiff_t difference_type
virtual IterBase & operator++()=0
Pre-increments the iterator.
virtual std::unique_ptr< typename PredBase::const_PredBase > const_clone() const override
The redefinition of the const_clone function for the Pred class.
IterType iter_data
This is the iterator passed by the user.
virtual std::unique_ptr< IterBase > clone() const =0
virtual std::unique_ptr< IterBase > clone() const override
bool operator==(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &y)
variant_filter_iterator(const IterType &d, const IterType &e, const PredType &p)
Templated Constructor.
virtual ~IterBase()=default
virtual std::unique_ptr< const_PredBase > const_clone() const =0
Similar to the clone() function.
std::unique_ptr< IterBase > end
Also have a polymorphic pointer to the end object, this prevents iterating past the end...
PointerType iter_ptr() const
This seems to work around a bug in g++ prior to version 10 and clang++ prior to version 10...
virtual ~Iter()=default
Destructor.
variant_filter_iterator(const variant_filter_iterator< Predicate, OtherType, OtherReferenceType, OtherPointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &rhs)
Copy construct from another (similar) variant_filter_iterator.
virtual ~variant_filter_iterator()=default
Destructor.
virtual bool operator()(const std::unique_ptr< IterBase > &in) const override
Re-implementation of op()
variant_filter_iterator()=default
Default Constructor.
PredType pred_data
This is the predicate passed in by the user.
Abstract base class for the predicate.
Iter(const IterType &v)
Constructor.
void satisfy_predicate()
Advances the data pointer until it reaches the end or the predicate is satisfied. ...
variant_filter_iterator(const Iterator &rhs)
Copy Constructor.
virtual ~PredBase()=default
virtual bool equal(const std::unique_ptr< IterBase > &other) const =0
bool operator!=(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &y)
ReferenceType operator*() const
unary op*() forwards on to Iter::op*()
virtual std::unique_ptr< PredBase > clone() const override
virtual Iter & operator++() override
Pre-increments the iterator.
std::unique_ptr< PredBase > pred
The predicate object.
Pred(const PredType &v)
Constructor.
PointerType operator->() const
op->()
const Iterator operator++(int)
postfix op++(), creates a temporary!
variant_filter_iterator< Predicate, ConstType, ConstReferenceType, ConstPointerType >::IterBase const_IterBase
std::unique_ptr< IterBase > data
Ideally this private member data should have protected access.
Iter(const Iter &other)
Copy Constructor.
virtual bool equal(const std::unique_ptr< IterBase > &other) const override
Use a dynamic cast to convert the base pointer passed in to the derived type.
virtual bool operator()(const std::unique_ptr< IterBase > &in) const =0
variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType > Iterator
Shortcut name for the fully-qualified typename.
virtual std::unique_ptr< PredBase > clone() const =0
virtual ~Pred()=default
Destructor.
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
variant_filter_iterator< Predicate, ConstType, ConstReferenceType, ConstPointerType >::PredBase const_PredBase
bool equal(const variant_filter_iterator &other) const
Forwards to the equal() function defined for the IterBase pointer.
Iterator & operator++()
op++() forwards on to Iter::op++()
virtual ReferenceType operator*() const =0
Dereferences the iterator.
virtual std::unique_ptr< typename IterBase::const_IterBase > const_clone() const override
Abstract base class for the iterator type.