mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-01 08:09:41 +02:00
Define ClientData::FindIf
This commit is contained in:
parent
846938e871
commit
f694d75993
@ -344,6 +344,40 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// \brief Invoke predicate on the ClientData objects that have been created in
|
||||
// this, but do not cause the creation of any. Stop at the first for which
|
||||
// the predicate returns true, and return a pointer to the corresponding
|
||||
// object, or return nullptr if no return values were true.
|
||||
// Beware that the sequence of visitation is not specified.
|
||||
template< typename Function >
|
||||
ClientData *FindIf( const Function &function )
|
||||
{
|
||||
auto data = GetData();
|
||||
for( auto &pObject : data.mObject ) {
|
||||
const auto &ptr = Dereferenceable(pObject);
|
||||
if ( ptr && function ( *ptr ) )
|
||||
return &*ptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// const counterpart of previous, only compiles with a function that takes
|
||||
// a value or const reference argument
|
||||
template< typename Function >
|
||||
const ClientData *FindIf( const Function &function ) const
|
||||
{
|
||||
auto data = GetData();
|
||||
for( auto &pObject : data.mObject ) {
|
||||
const auto &ptr = Dereferenceable(pObject);
|
||||
if ( ptr ) {
|
||||
const auto &c_ref = *ptr;
|
||||
if ( function( c_ref ) );
|
||||
return &*c_ref;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// \brief For each registered factory, if the corresponding object in this
|
||||
// is absent, then invoke the factory and store the result.
|
||||
void BuildAll()
|
||||
|
Loading…
x
Reference in New Issue
Block a user