1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-28 22:28:44 +02:00

Less use of wxArrayString::Index() ...

... instead use the utility make_iterator_range and its index() or contains()
method.  This generic utility works with any container defining begin() and
end().

This further lessens dependency on wxWidgets container idioms.
This commit is contained in:
Paul Licameli 2019-03-04 02:13:40 -05:00
parent c68e336247
commit dd8eb9e3d9
21 changed files with 42 additions and 37 deletions

@ -98,7 +98,7 @@ MacroCommands::MacroCommands()
for( size_t i = 0;i<defaults.size();i++){
wxString name = defaults[i];
if (names.Index(name) == wxNOT_FOUND) {
if ( ! make_iterator_range( names ).contains(name) ) {
AddMacro(name);
RestoreMacro(name);
WriteMacro(name);
@ -1005,7 +1005,7 @@ wxArrayString MacroCommands::GetNames()
bool MacroCommands::IsFixed(const wxString & name)
{
wxArrayString defaults = GetNamesOfDefaultMacros();
if( defaults.Index( name ) != wxNOT_FOUND )
if( make_iterator_range( defaults ).contains( name ) )
return true;
return false;
}

@ -1516,7 +1516,7 @@ bool DirManager::EnsureSafeFilename(const wxFileName &fName)
// then the file name is A-OK.
const wxString fullPath{fName.GetFullPath()};
if (aliasList.Index(fullPath) == wxNOT_FOUND)
if ( !make_iterator_range( aliasList ).contains( fullPath ) )
return true;
/* i18n-hint: 'old' is part of a filename used when a file is renamed. */

@ -553,10 +553,12 @@ void LabelDialog::OnInsert(wxCommandEvent &event)
if (cnt > 0) {
row = mGrid->GetGridCursorRow();
if (row > 0 && row >= cnt) {
index = mTrackNames.Index(mGrid->GetCellValue(row - 1, Col_Track));
index = make_iterator_range( mTrackNames )
.index( mGrid->GetCellValue(row - 1, Col_Track) );
}
else {
index = mTrackNames.Index(mGrid->GetCellValue(row, Col_Track));
index = make_iterator_range( mTrackNames )
.index( mGrid->GetCellValue(row, Col_Track) );
}
}
@ -801,7 +803,7 @@ void LabelDialog::OnChangeTrack(wxGridEvent & WXUNUSED(event), int row, RowData
wxString val = mGrid->GetCellValue(row, Col_Track);
// User selected the "New..." choice so ask for a NEW name
if (mTrackNames.Index(val) == 0) {
if ( make_iterator_range( mTrackNames ).index( val ) == 0 ) {
AudacityTextEntryDialog d(this,
_("New Label Track"),
_("Enter track name"),
@ -821,7 +823,7 @@ void LabelDialog::OnChangeTrack(wxGridEvent & WXUNUSED(event), int row, RowData
}
else {
// Remember the tracks index
rd->index = mTrackNames.Index(val);
rd->index = make_iterator_range( mTrackNames ).index( val );
}
// Repopulate the grid

@ -77,7 +77,7 @@ LangChoiceDialog::LangChoiceDialog(wxWindow * parent,
{
SetName(GetTitle());
GetLanguages(mLangCodes, mLangNames);
int ndx = mLangCodes.Index(GetSystemLanguageCode());
int ndx = make_iterator_range( mLangCodes ).index( GetSystemLanguageCode() );
wxString lang;
if (ndx != wxNOT_FOUND) {
@ -111,7 +111,7 @@ void LangChoiceDialog::OnOk(wxCommandEvent & WXUNUSED(event))
mLang = mLangCodes[ndx];
wxString slang = GetSystemLanguageCode();
int sndx = mLangCodes.Index(slang);
int sndx = make_iterator_range( mLangCodes ).index( slang );
wxString sname;
if (sndx == wxNOT_FOUND) {

@ -2409,7 +2409,7 @@ void PluginManager::CheckForUpdates(bool bFast)
for (size_t i = 0, cnt = paths.size(); i < cnt; i++)
{
wxString path = paths[i].BeforeFirst(wxT(';'));;
if (pathIndex.Index(path) == wxNOT_FOUND)
if ( ! make_iterator_range( pathIndex ).contains( path ) )
{
PluginID ID = plugID + wxT("_") + path;
PluginDescriptor & plug2 = mPlugins[ID]; // This will create a NEW descriptor

@ -1610,8 +1610,8 @@ wxChoice * ShuttleGuiBase::TieChoice(
/// String-to-Index
int ShuttleGuiBase::TranslateToIndex( const wxString &Value, const wxArrayString &Choices )
{
int n = Choices.Index( Value );
if( n== wxNOT_FOUND )
int n = make_iterator_range( Choices ).index( Value );
if( n == wxNOT_FOUND )
n=miNoMatchSelector;
miNoMatchSelector = 0;
return n;

@ -937,7 +937,7 @@ teThemeType ThemeBase::ThemeTypeOfTypeName( const wxString & Name )
aThemes.Add( "light" );
aThemes.Add( "high-contrast" );
aThemes.Add( "custom" );
int themeIx = aThemes.Index( Name );
int themeIx = make_iterator_range( aThemes ).index( Name );
if( themeIx < 0 )
return GetFallbackThemeType();
return (teThemeType)themeIx;

@ -1603,7 +1603,7 @@ void CommandManager::GetCategories(wxArrayString &cats)
for (const auto &entry : mCommandList) {
wxString cat = entry->labelTop;
if (cats.Index(cat) == wxNOT_FOUND) {
if ( ! make_iterator_range( cats ).contains(cat) ) {
cats.push_back(cat);
}
}

@ -277,7 +277,7 @@ bool BuiltinCommandsModule::IsPluginValid(const wxString & path, bool bFast)
{
// bFast is unused as checking in the list is fast.
static_cast<void>(bFast); // avoid unused variable warning
return mNames.Index(path) != wxNOT_FOUND;
return make_iterator_range( mNames ).contains( path );
}
ComponentInterface *BuiltinCommandsModule::CreateInstance(const wxString & path)
@ -302,9 +302,10 @@ void BuiltinCommandsModule::DeleteInstance(ComponentInterface *instance)
std::unique_ptr<AudacityCommand> BuiltinCommandsModule::Instantiate(const wxString & path)
{
wxASSERT(path.StartsWith(BUILTIN_GENERIC_COMMAND_PREFIX));
wxASSERT(mNames.Index(path) != wxNOT_FOUND);
auto index = make_iterator_range( mNames ).index( path );
wxASSERT( index != wxNOT_FOUND );
switch (mNames.Index(path))
switch ( index )
{
COMMAND_LIST;
EXCLUDE_LIST;

@ -107,7 +107,7 @@ public:
bool Validate(const wxVariant &v) override
{
SetConverted(v);
return (mOptions.Index(v.GetString()) != wxNOT_FOUND);
return make_iterator_range( mOptions ).contains( v.GetString() );
}
wxString GetDescription() const override
{

@ -1039,7 +1039,7 @@ bool Effect::SetAutomationParameters(const wxString & parms)
{
preset.Replace(kFactoryPresetIdent, wxEmptyString, false);
wxArrayString presets = GetFactoryPresets();
success = LoadFactoryPreset(presets.Index(preset));
success = LoadFactoryPreset( make_iterator_range( presets ).index( preset ) );
}
else if (preset.StartsWith(kCurrentSettingsIdent))
{
@ -3679,7 +3679,7 @@ void EffectUIHost::OnSaveAs(wxCommandEvent & WXUNUSED(evt))
continue;
}
if (mUserPresets.Index(name) != wxNOT_FOUND)
if ( make_iterator_range( mUserPresets ).contains( name ) )
{
AudacityMessageDialog md(this,
_("Preset already exists.\n\nReplace?"),

@ -335,7 +335,7 @@ bool BuiltinEffectsModule::IsPluginValid(const wxString & path, bool bFast)
{
// bFast is unused as checking in the list is fast.
static_cast<void>(bFast);
return mNames.Index(path) != wxNOT_FOUND;
return make_iterator_range( mNames ).contains( path );
}
ComponentInterface *BuiltinEffectsModule::CreateInstance(const wxString & path)
@ -360,9 +360,10 @@ void BuiltinEffectsModule::DeleteInstance(ComponentInterface *instance)
std::unique_ptr<Effect> BuiltinEffectsModule::Instantiate(const wxString & path)
{
wxASSERT(path.StartsWith(BUILTIN_EFFECT_PREFIX));
wxASSERT(mNames.Index(path) != wxNOT_FOUND);
auto index = make_iterator_range( mNames ).index( path );
wxASSERT( index != wxNOT_FOUND );
switch (mNames.Index(path))
switch ( index )
{
EFFECT_LIST;
EXCLUDE_LIST;

@ -505,7 +505,7 @@ bool LV2Effect::SetHost(EffectHostInterface *host)
}
// Add it if not previously done
if (mGroups.Index(ctrl.mGroup) == wxNOT_FOUND)
if ( !make_iterator_range( mGroups ).contains( ctrl.mGroup ) )
{
mGroups.push_back(ctrl.mGroup);
}

@ -2072,7 +2072,7 @@ bool NyquistEffect::Parse(
}
}
if( mPresetNames.Index( ctrl.var ) == wxNOT_FOUND )
if( ! make_iterator_range( mPresetNames ).contains( ctrl.var ) )
{
mControls.push_back(ctrl);
}

@ -1624,7 +1624,7 @@ void ExportFFmpegOptions::FindSelectedFormat(wxString **name, wxString **longnam
wxString selfmt = mFormatList->GetString(selections[0]);
// Find it's index
int nFormat = mFormatNames.Index(selfmt);
int nFormat = make_iterator_range( mFormatNames ).index( selfmt );
if (nFormat == wxNOT_FOUND) return;
// Return short name and description
@ -1645,7 +1645,7 @@ void ExportFFmpegOptions::FindSelectedCodec(wxString **name, wxString **longname
wxString selcdc = mCodecList->GetString(selections[0]);
// Find it's index
int nCodec = mCodecNames.Index(selcdc);
int nCodec = make_iterator_range( mCodecNames ).index( selcdc );
if (nCodec == wxNOT_FOUND) return;
// Return short name and description
@ -1699,7 +1699,8 @@ int ExportFFmpegOptions::FetchCompatibleCodecList(const wxChar *fmt, AVCodecID i
{
if (codec->type == AVMEDIA_TYPE_AUDIO && av_codec_is_encoder(codec))
{
if (mShownCodecNames.Index(wxString::FromUTF8(codec->name)) < 0)
if (! make_iterator_range( mShownCodecNames )
.contains( wxString::FromUTF8(codec->name) ) )
{
if ((id >= 0) && codec->id == id) index = mShownCodecNames.size();
mShownCodecNames.push_back(wxString::FromUTF8(codec->name));

@ -98,7 +98,7 @@ void DevicePrefs::GetNamesAndLabels()
const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if ((info!=NULL)&&(info->maxOutputChannels > 0 || info->maxInputChannels > 0)) {
wxString name = wxSafeConvertMB2WX(Pa_GetHostApiInfo(info->hostApi)->name);
if (mHostNames.Index(name) == wxNOT_FOUND) {
if ( ! make_iterator_range( mHostNames ).contains( name ) ) {
mHostNames.push_back(name);
mHostLabels.push_back(name);
}

@ -521,7 +521,7 @@ void KeyConfigPrefs::SetKeyForSelected(const NormalizedKeyString & key)
mView->SetKey(mCommandSelected, key);
mManager->SetKeyFromName(name, key);
mNewKeys[mNames.Index(name)] = key;
mNewKeys[ make_iterator_range( mNames ).index( name ) ] = key;
}
@ -563,7 +563,7 @@ void KeyConfigPrefs::OnSet(wxCommandEvent & WXUNUSED(event))
mView->SetKeyByName(oldname, {});
mManager->SetKeyFromName(oldname, {});
mNewKeys[mNames.Index(oldname)] = {};
mNewKeys[ make_iterator_range( mNames ).index( oldname ) ] = {};
}

@ -103,7 +103,7 @@ void MidiIOPrefs::GetNamesAndLabels() {
const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
if (info->output || info->input) { //should always happen
wxString name = wxSafeConvertMB2WX(info->interf);
if (mHostNames.Index(name) == wxNOT_FOUND) {
if ( ! make_iterator_range( mHostNames ).contains( name ) ) {
mHostNames.push_back(name);
mHostLabels.push_back(name);
}

@ -510,10 +510,10 @@ void DeviceToolBar::FillHosts()
const std::vector<DeviceSourceMap> &outMaps = DeviceManager::Instance()->GetOutputDeviceMaps();
// go over our lists add the host to the list if it isn't there yet
for (i = 0; i < inMaps.size(); i++)
if (hosts.Index(inMaps[i].hostString) == wxNOT_FOUND)
if ( ! make_iterator_range( hosts ).contains( inMaps[i].hostString ) )
hosts.push_back(inMaps[i].hostString);
for (i = 0; i < outMaps.size(); i++)
if (hosts.Index(outMaps[i].hostString) == wxNOT_FOUND)
if ( ! make_iterator_range( hosts ).contains( outMaps[i].hostString ) )
hosts.push_back(outMaps[i].hostString);
mHost->Clear();

@ -131,7 +131,7 @@ void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)
wxLB_SINGLE);
lb->SetName(_("Face name"));
lb->SetSelection(facenames.Index(facename));
lb->SetSelection( make_iterator_range( facenames ).index( facename ));
S.AddWindow(lb, wxALIGN_LEFT | wxEXPAND | wxALL);
/* i18n-hint: (noun) The size of the typeface*/

@ -311,7 +311,7 @@ void ChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
Choice()->Clear();
Choice()->Append(mChoices);
Choice()->SetSelection(mChoices.Index(mOld));
Choice()->SetSelection( make_iterator_range( mChoices ).index( mOld ) );
Choice()->SetFocus();
}
@ -356,7 +356,7 @@ void ChoiceEditor::ApplyEdit(int row, int col, wxGrid *grid)
void ChoiceEditor::Reset()
{
Choice()->SetSelection(mChoices.Index(mOld));
Choice()->SetSelection( make_iterator_range( mChoices ).index( mOld ) );
}
void ChoiceEditor::SetChoices(const wxArrayString &choices)