1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Define ClientData::FindIf

This commit is contained in:
Paul Licameli 2019-07-23 11:36:50 -04:00
parent 846938e871
commit f694d75993

View File

@ -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()