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 998 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 1003 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 1008 of file Track.h.

1012 {}
1013 )
1014 : mBegin( begin ), mIter( iter ), mEnd( end )
1015 , mPred( std::move(pred) )
1016 {
1017 // Establish the class invariant
1018 if (this->mIter != this->mEnd && !this->valid())
1019 this->operator ++ ();
1020 }
TrackNodePointer mIter
Current position.
Definition: Track.h:1151
TrackNodePointer mBegin
Allows end of reverse iteration to be detected without comparison to other TrackIter.
Definition: Track.h:1150
TrackIter & operator++()
Safe to call even when at the end.
Definition: Track.h:1051
FunctionType mPred
Optional filter
Definition: Track.h:1153
bool valid() const
Test satisfaction of the invariant, while initializing, incrementing, or decrementing.
Definition: Track.h:1137
TrackNodePointer mEnd
Allows end of iteration to be detected without comparison to other TrackIter.
Definition: Track.h:1152
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 1105 of file Track.h.

1108 {
1109 auto copy = *this;
1110 std::advance( copy, amount );
1111 return copy;
1112 }

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

1042 {
1043 return { this->mBegin, this->mIter, this->mEnd, this->mPred };
1044 }

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

1027 {
1028 return { this->mBegin, this->mIter, this->mEnd, pred2 };
1029 }

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

1047 { 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 1093 of file Track.h.

1094 {
1095 if (this->mIter == this->mEnd)
1096 return nullptr;
1097 else
1098 // Other methods guarantee that the cast is correct
1099 // (provided no operations on the TrackList invalidated
1100 // underlying iterators or replaced the tracks there)
1101 return static_cast< TrackType * >( &**this->mIter.first );
1102 }

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

1052 {
1053 // Maintain the class invariant
1054 if (this->mIter != this->mEnd) do
1055 ++this->mIter.first;
1056 while (this->mIter != this->mEnd && !this->valid() );
1057 return *this;
1058 }

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

1062 {
1063 TrackIter result { *this };
1064 this-> operator ++ ();
1065 return result;
1066 }
Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicat...
Definition: Track.h:1000

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

1071 {
1072 // Maintain the class invariant
1073 do {
1074 if (this->mIter == this->mBegin)
1075 // Go circularly
1076 this->mIter = this->mEnd;
1077 else
1078 --this->mIter.first;
1079 } while (this->mIter != this->mEnd && !this->valid() );
1080 return *this;
1081 }

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

1085 {
1086 TrackIter result { *this };
1087 this->operator -- ();
1088 return result;
1089 }
TrackIter & operator--()
Safe to call even when at the beginning.
Definition: Track.h:1070

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

1138 {
1139 // assume mIter != mEnd
1140 const auto pTrack = track_cast< TrackType * >( &**this->mIter.first );
1141 if (!pTrack)
1142 return false;
1143 return !this->mPred || this->mPred( pTrack );
1144 }

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

1127 {
1128 return !(a == b);
1129 }

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

1116 {
1117 // Assume the predicate is not stateful. Just compare the iterators.
1118 return
1119 a.mIter == b.mIter
1120 // Assume this too:
1121 // && a.mBegin == b.mBegin && a.mEnd == b.mEnd
1122 ;
1123 }

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 1150 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 1152 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 1147 of file Track.h.


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