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 519 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 524 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 529 of file Track.h.

533 {}
534 )
535 : mBegin( begin ), mIter( iter ), mEnd( end )
536 , mPred( std::move(pred) )
537 {
538 // Establish the class invariant
539 if (this->mIter != this->mEnd && !this->valid())
540 this->operator ++ ();
541 }
TrackNodePointer mIter
Current position.
Definition: Track.h:672
TrackNodePointer mBegin
Allows end of reverse iteration to be detected without comparison to other TrackIter.
Definition: Track.h:671
TrackIter & operator++()
Safe to call even when at the end.
Definition: Track.h:572
FunctionType mPred
Optional filter
Definition: Track.h:674
bool valid() const
Test satisfaction of the invariant, while initializing, incrementing, or decrementing.
Definition: Track.h:658
TrackNodePointer mEnd
Allows end of iteration to be detected without comparison to other TrackIter.
Definition: Track.h:673
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

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 626 of file Track.h.

629 {
630 auto copy = *this;
631 std::advance( copy, amount );
632 return copy;
633 }
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 556 of file Track.h.

563 {
564 return { this->mBegin, this->mIter, this->mEnd, this->mPred };
565 }

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 547 of file Track.h.

548 {
549 return { this->mBegin, this->mIter, this->mEnd, pred2 };
550 }

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 567 of file Track.h.

568 { 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 614 of file Track.h.

615 {
616 if (this->mIter == this->mEnd)
617 return nullptr;
618 else
619 // Other methods guarantee that the cast is correct
620 // (provided no operations on the TrackList invalidated
621 // underlying iterators or replaced the tracks there)
622 return static_cast< TrackType * >( &**this->mIter );
623 }

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 572 of file Track.h.

573 {
574 // Maintain the class invariant
575 if (this->mIter != this->mEnd) do
576 ++this->mIter;
577 while (this->mIter != this->mEnd && !this->valid() );
578 return *this;
579 }

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 582 of file Track.h.

583 {
584 TrackIter result { *this };
585 this-> operator ++ ();
586 return result;
587 }
Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicat...
Definition: Track.h:521

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 591 of file Track.h.

592 {
593 // Maintain the class invariant
594 do {
595 if (this->mIter == this->mBegin)
596 // Go circularly
597 this->mIter = this->mEnd;
598 else
599 --this->mIter;
600 } while (this->mIter != this->mEnd && !this->valid() );
601 return *this;
602 }

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 605 of file Track.h.

606 {
607 TrackIter result { *this };
608 this->operator -- ();
609 return result;
610 }
TrackIter & operator--()
Safe to call even when at the beginning.
Definition: Track.h:591

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 658 of file Track.h.

659 {
660 // assume mIter != mEnd
661 const auto pTrack = track_cast< TrackType * >( &**this->mIter );
662 if (!pTrack)
663 return false;
664 return !this->mPred || this->mPred( pTrack );
665 }

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 647 of file Track.h.

648 {
649 return !(a == b);
650 }

◆ 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 636 of file Track.h.

637 {
638 // Assume the predicate is not stateful. Just compare the iterators.
639 return
640 a.mIter == b.mIter
641 // Assume this too:
642 // && a.mBegin == b.mBegin && a.mEnd == b.mEnd
643 ;
644 }

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 671 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 673 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 668 of file Track.h.


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