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 1005 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 1010 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 1015 of file Track.h.

1019 {}
1020 )
1021 : mBegin( begin ), mIter( iter ), mEnd( end )
1022 , mPred( std::move(pred) )
1023 {
1024 // Establish the class invariant
1025 if (this->mIter != this->mEnd && !this->valid())
1026 this->operator ++ ();
1027 }
TrackNodePointer mIter
Current position.
Definition: Track.h:1158
TrackNodePointer mBegin
Allows end of reverse iteration to be detected without comparison to other TrackIter.
Definition: Track.h:1157
TrackIter & operator++()
Safe to call even when at the end.
Definition: Track.h:1058
FunctionType mPred
Optional filter
Definition: Track.h:1160
bool valid() const
Test satisfaction of the invariant, while initializing, incrementing, or decrementing.
Definition: Track.h:1144
TrackNodePointer mEnd
Allows end of iteration to be detected without comparison to other TrackIter.
Definition: Track.h:1159
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 1112 of file Track.h.

1115 {
1116 auto copy = *this;
1117 std::advance( copy, amount );
1118 return copy;
1119 }

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

1049 {
1050 return { this->mBegin, this->mIter, this->mEnd, this->mPred };
1051 }

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

1034 {
1035 return { this->mBegin, this->mIter, this->mEnd, pred2 };
1036 }

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

1054 { 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 1100 of file Track.h.

1101 {
1102 if (this->mIter == this->mEnd)
1103 return nullptr;
1104 else
1105 // Other methods guarantee that the cast is correct
1106 // (provided no operations on the TrackList invalidated
1107 // underlying iterators or replaced the tracks there)
1108 return static_cast< TrackType * >( &**this->mIter.first );
1109 }

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

1059 {
1060 // Maintain the class invariant
1061 if (this->mIter != this->mEnd) do
1062 ++this->mIter.first;
1063 while (this->mIter != this->mEnd && !this->valid() );
1064 return *this;
1065 }

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

1069 {
1070 TrackIter result { *this };
1071 this-> operator ++ ();
1072 return result;
1073 }
Iterator over only members of a TrackList of the specified subtype, optionally filtered by a predicat...
Definition: Track.h:1007

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

1078 {
1079 // Maintain the class invariant
1080 do {
1081 if (this->mIter == this->mBegin)
1082 // Go circularly
1083 this->mIter = this->mEnd;
1084 else
1085 --this->mIter.first;
1086 } while (this->mIter != this->mEnd && !this->valid() );
1087 return *this;
1088 }

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

1092 {
1093 TrackIter result { *this };
1094 this->operator -- ();
1095 return result;
1096 }
TrackIter & operator--()
Safe to call even when at the beginning.
Definition: Track.h:1077

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

1145 {
1146 // assume mIter != mEnd
1147 const auto pTrack = track_cast< TrackType * >( &**this->mIter.first );
1148 if (!pTrack)
1149 return false;
1150 return !this->mPred || this->mPred( pTrack );
1151 }

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

1134 {
1135 return !(a == b);
1136 }

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

1123 {
1124 // Assume the predicate is not stateful. Just compare the iterators.
1125 return
1126 a.mIter == b.mIter
1127 // Assume this too:
1128 // && a.mBegin == b.mBegin && a.mEnd == b.mEnd
1129 ;
1130 }

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 1157 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 1159 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 1154 of file Track.h.


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