Audacity 3.2.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
TrackIter< TrackType > Class Template Reference

Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicate; past-end value dereferenceable, to nullptr. More...

#include <Track.h>

Inheritance diagram for TrackIter< TrackType >:
[legend]
Collaboration diagram for TrackIter< TrackType >:
[legend]

Public Types

using FunctionType = std::function< bool(std::add_pointer_t< std::add_const_t< std::remove_pointer_t< TrackType > > >) >
 Type of predicate taking pointer to const TrackType. More...
 
- Public Types inherited from ValueIterator< TrackType *, std::bidirectional_iterator_tag >
using iterator_category = std::bidirectional_iterator_tag
 
using value_type = TrackType *
 
using difference_type = ptrdiff_t
 
using pointer = void
 
using reference = const TrackType *
 

Public Member Functions

 TrackIter (TrackNodePointer begin, TrackNodePointer iter, TrackNodePointer end, FunctionType pred={})
 Constructor, usually not called directly except by methods of TrackList. More...
 
template<typename Predicate2 >
TrackIter Filter (const Predicate2 &pred2) const
 Return an iterator that replaces the predicate. More...
 
template<typename TrackType2 >
auto Filter () const -> std::enable_if_t< std::is_base_of_v< TrackType, TrackType2 > &&(!std::is_const_v< TrackType >||std::is_const_v< TrackType2 >), TrackIter< TrackType2 > >
 Return an iterator for a subclass of TrackType (and not removing const) with same predicate. More...
 
const FunctionTypeGetPredicate () const
 
TrackIteroperator++ ()
 Safe to call even when at the end. More...
 
TrackIter operator++ (int)
 Safe to call even when at the end. More...
 
TrackIteroperator-- ()
 Safe to call even when at the beginning. More...
 
TrackIter operator-- (int)
 Safe to call even when at the beginning. More...
 
TrackType * operator* () const
 Safe to call even when at the end. More...
 
TrackIter advance (long amount) const
 This might be called operator + , but it's not constant-time as with a random access iterator. More...
 

Private Member Functions

bool valid () const
 Test satisfaction of the invariant, while initializing, incrementing, or decrementing. More...
 

Private Attributes

friend TrackIterRange< TrackType >
 This friendship is needed in TrackIterRange::StartingWith and TrackIterRange::EndingAfter() More...
 
TrackNodePointer mBegin
 Allows end of reverse iteration to be detected without comparison to other TrackIter. More...
 
TrackNodePointer mIter
 Current position. More...
 
TrackNodePointer mEnd
 Allows end of iteration to be detected without comparison to other TrackIter. More...
 
FunctionType mPred
 Optional filter More...
 

Friends

bool operator== (TrackIter a, TrackIter b)
 Compares only current positions, assuming same beginnings and ends. More...
 
bool operator!= (TrackIter a, TrackIter b)
 Compares only current positions, assuming same beginnings and ends. More...
 

Detailed Description

template<typename TrackType>
class TrackIter< TrackType >

Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicate; past-end value dereferenceable, to nullptr.

Does not suffer invalidation when an underlying std::list iterator is deleted, provided that is not equal to its current position or to the beginning or end iterator.

The filtering predicate is tested only when the iterator is constructed or advanced.

Template Parameters
TrackTypeTrack or a subclass, maybe const-qualified

Definition at line 644 of file Track.h.

Member Typedef Documentation

◆ FunctionType

template<typename TrackType >
using TrackIter< TrackType >::FunctionType = std::function< bool( std::add_pointer_t< std::add_const_t< std::remove_pointer_t<TrackType> > > ) >

Type of predicate taking pointer to const TrackType.

Definition at line 649 of file Track.h.

Constructor & Destructor Documentation

◆ TrackIter()

template<typename TrackType >
TrackIter< TrackType >::TrackIter ( TrackNodePointer  begin,
TrackNodePointer  iter,
TrackNodePointer  end,
FunctionType  pred = {} 
)
inline

Constructor, usually not called directly except by methods of TrackList.

Parameters
beginRemember lower bound
iterThe actual pointer
endRemember upper bound
predOptional filter

Definition at line 654 of file Track.h.

658 {}
659 )
660 : mBegin( begin ), mIter( iter ), mEnd( end )
661 , mPred( std::move(pred) )
662 {
663 // Establish the class invariant
664 if (this->mIter != this->mEnd && !this->valid())
665 this->operator ++ ();
666 }
TrackNodePointer mIter
Current position.
Definition: Track.h:797
TrackNodePointer mBegin
Allows end of reverse iteration to be detected without comparison to other TrackIter.
Definition: Track.h:796
TrackIter & operator++()
Safe to call even when at the end.
Definition: Track.h:697
FunctionType mPred
Optional filter
Definition: Track.h:799
bool valid() const
Test satisfaction of the invariant, while initializing, incrementing, or decrementing.
Definition: Track.h:783
TrackNodePointer mEnd
Allows end of iteration to be detected without comparison to other TrackIter.
Definition: Track.h:798
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

Member Function Documentation

◆ advance()

template<typename TrackType >
TrackIter TrackIter< TrackType >::advance ( long  amount) const
inline

This might be called operator + , but it's not constant-time as with a random access iterator.

Parameters
amountmay be negative

Definition at line 751 of file Track.h.

754 {
755 auto copy = *this;
756 std::advance( copy, amount );
757 return copy;
758 }
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy().

Here is the call graph for this function:

◆ Filter() [1/2]

template<typename TrackType >
template<typename TrackType2 >
auto TrackIter< TrackType >::Filter ( ) const -> std::enable_if_t< std::is_base_of_v< TrackType, TrackType2 > && (!std::is_const_v<TrackType> || std::is_const_v<TrackType2>), TrackIter< TrackType2 > >
inline

Return an iterator for a subclass of TrackType (and not removing const) with same predicate.

Advance to the first position at or after the old position that satisfies the type constraint, or to the end

Definition at line 681 of file Track.h.

688 {
689 return { this->mBegin, this->mIter, this->mEnd, this->mPred };
690 }

References TrackIter< TrackType >::mBegin, TrackIter< TrackType >::mEnd, TrackIter< TrackType >::mIter, and TrackIter< TrackType >::mPred.

◆ Filter() [2/2]

template<typename TrackType >
template<typename Predicate2 >
TrackIter TrackIter< TrackType >::Filter ( const Predicate2 &  pred2) const
inline

Return an iterator that replaces the predicate.

Advance to the first position at or after the old position that satisfies the new predicate, or to the end

Definition at line 672 of file Track.h.

673 {
674 return { this->mBegin, this->mIter, this->mEnd, pred2 };
675 }

References TrackIter< TrackType >::mBegin, TrackIter< TrackType >::mEnd, and TrackIter< TrackType >::mIter.

Referenced by TrackList::Channels_().

Here is the caller graph for this function:

◆ GetPredicate()

template<typename TrackType >
const FunctionType & TrackIter< TrackType >::GetPredicate ( ) const
inline

Definition at line 692 of file Track.h.

693 { return this->mPred; }

References TrackIter< TrackType >::mPred.

◆ operator*()

template<typename TrackType >
TrackType * TrackIter< TrackType >::operator* ( ) const
inline

Safe to call even when at the end.

In that case you get nullptr.

Definition at line 739 of file Track.h.

740 {
741 if (this->mIter == this->mEnd)
742 return nullptr;
743 else
744 // Other methods guarantee that the cast is correct
745 // (provided no operations on the TrackList invalidated
746 // underlying iterators or replaced the tracks there)
747 return static_cast< TrackType * >( &**this->mIter.first );
748 }

References TrackIter< TrackType >::mEnd, and TrackIter< TrackType >::mIter.

◆ operator++() [1/2]

template<typename TrackType >
TrackIter & TrackIter< TrackType >::operator++ ( )
inline

Safe to call even when at the end.

In that case *this remains unchanged.

Definition at line 697 of file Track.h.

698 {
699 // Maintain the class invariant
700 if (this->mIter != this->mEnd) do
701 ++this->mIter.first;
702 while (this->mIter != this->mEnd && !this->valid() );
703 return *this;
704 }

References TrackIter< TrackType >::mEnd, TrackIter< TrackType >::mIter, and TrackIter< TrackType >::valid().

Referenced by TrackIter< TrackType >::operator++().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator++() [2/2]

template<typename TrackType >
TrackIter TrackIter< TrackType >::operator++ ( int  )
inline

Safe to call even when at the end.

In that case *this remains unchanged.

Definition at line 707 of file Track.h.

708 {
709 TrackIter result { *this };
710 this-> operator ++ ();
711 return result;
712 }
Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicat...
Definition: Track.h:646

References TrackIter< TrackType >::operator++().

Here is the call graph for this function:

◆ operator--() [1/2]

template<typename TrackType >
TrackIter & TrackIter< TrackType >::operator-- ( )
inline

Safe to call even when at the beginning.

In that case *this wraps to the end.

Definition at line 716 of file Track.h.

717 {
718 // Maintain the class invariant
719 do {
720 if (this->mIter == this->mBegin)
721 // Go circularly
722 this->mIter = this->mEnd;
723 else
724 --this->mIter.first;
725 } while (this->mIter != this->mEnd && !this->valid() );
726 return *this;
727 }

References TrackIter< TrackType >::mBegin, TrackIter< TrackType >::mEnd, TrackIter< TrackType >::mIter, and TrackIter< TrackType >::valid().

Referenced by TrackIter< TrackType >::operator--().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator--() [2/2]

template<typename TrackType >
TrackIter TrackIter< TrackType >::operator-- ( int  )
inline

Safe to call even when at the beginning.

In that case *this wraps to the end.

Definition at line 730 of file Track.h.

731 {
732 TrackIter result { *this };
733 this->operator -- ();
734 return result;
735 }
TrackIter & operator--()
Safe to call even when at the beginning.
Definition: Track.h:716

References TrackIter< TrackType >::operator--().

Here is the call graph for this function:

◆ valid()

template<typename TrackType >
bool TrackIter< TrackType >::valid ( ) const
inlineprivate

Test satisfaction of the invariant, while initializing, incrementing, or decrementing.

Precondition
underlying iterators are still valid, and mPred, if not null, is well behaved
Invariant
mIter == mEnd, or else, mIter != mEnd, and **mIter is of the appropriate subclass, and mPred is null or mPred(&**mIter) is true.

Definition at line 783 of file Track.h.

784 {
785 // assume mIter != mEnd
786 const auto pTrack = track_cast< TrackType * >( &**this->mIter.first );
787 if (!pTrack)
788 return false;
789 return !this->mPred || this->mPred( pTrack );
790 }

References TrackIter< TrackType >::mIter, and TrackIter< TrackType >::mPred.

Referenced by TrackIter< TrackType >::operator++(), and TrackIter< TrackType >::operator--().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

template<typename TrackType >
bool operator!= ( TrackIter< TrackType >  a,
TrackIter< TrackType >  b 
)
friend

Compares only current positions, assuming same beginnings and ends.

Definition at line 772 of file Track.h.

773 {
774 return !(a == b);
775 }

◆ operator==

template<typename TrackType >
bool operator== ( TrackIter< TrackType >  a,
TrackIter< TrackType >  b 
)
friend

Compares only current positions, assuming same beginnings and ends.

Definition at line 761 of file Track.h.

762 {
763 // Assume the predicate is not stateful. Just compare the iterators.
764 return
765 a.mIter == b.mIter
766 // Assume this too:
767 // && a.mBegin == b.mBegin && a.mEnd == b.mEnd
768 ;
769 }

Member Data Documentation

◆ mBegin

template<typename TrackType >
TrackNodePointer TrackIter< TrackType >::mBegin
private

Allows end of reverse iteration to be detected without comparison to other TrackIter.

Definition at line 796 of file Track.h.

Referenced by TrackIter< TrackType >::Filter(), and TrackIter< TrackType >::operator--().

◆ mEnd

template<typename TrackType >
TrackNodePointer TrackIter< TrackType >::mEnd
private

Allows end of iteration to be detected without comparison to other TrackIter.

Definition at line 798 of file Track.h.

Referenced by TrackIter< TrackType >::Filter(), TrackIter< TrackType >::operator*(), TrackIter< TrackType >::operator++(), and TrackIter< TrackType >::operator--().

◆ mIter

template<typename TrackType >
TrackNodePointer TrackIter< TrackType >::mIter
private

◆ mPred

template<typename TrackType >
FunctionType TrackIter< TrackType >::mPred
private

◆ TrackIterRange< TrackType >

template<typename TrackType >
friend TrackIter< TrackType >::TrackIterRange< TrackType >
private

This friendship is needed in TrackIterRange::StartingWith and TrackIterRange::EndingAfter()

Definition at line 793 of file Track.h.


The documentation for this class was generated from the following file: