1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-18 17:10:55 +02:00

use vector of smart pointers to ExtImportItem objects

This commit is contained in:
Paul Licameli 2016-08-10 23:33:04 -04:00
parent 28f0b11376
commit 8226441210
3 changed files with 41 additions and 42 deletions

View File

@ -63,8 +63,6 @@ and ImportLOF.cpp.
#include "ImportGStreamer.h"
#include "../Prefs.h"
WX_DEFINE_OBJARRAY(ExtImportItems);
// ============================================================================
//
// Return reference to singleton
@ -158,7 +156,6 @@ void Importer::ReadImportItems()
wxStringTokenizer toker;
wxString item_name;
wxString item_value;
ExtImportItem *new_item;
if (this->mExtImportItems != NULL)
delete this->mExtImportItems;
@ -181,7 +178,7 @@ void Importer::ReadImportItems()
if (toker.CountTokens() != 2)
break;
new_item = new ExtImportItem();
auto new_item = make_movable<ExtImportItem>();
/* First token is the filtering condition, second - the filter list */
condition = toker.GetNextToken();
@ -260,7 +257,7 @@ void Importer::ReadImportItems()
new_item->divider++;
}
}
this->mExtImportItems->Add (new_item);
this->mExtImportItems->push_back( std::move(new_item) );
}
}
@ -268,9 +265,9 @@ void Importer::WriteImportItems()
{
size_t i;
wxString val, name;
for (i = 0; i < this->mExtImportItems->Count(); i++)
for (i = 0; i < this->mExtImportItems->size(); i++)
{
ExtImportItem *item = &(mExtImportItems->Item(i));
ExtImportItem *item = (*mExtImportItems)[i].get();
val.Clear();
for (size_t j = 0; j < item->extensions.Count(); j++)
@ -310,7 +307,7 @@ void Importer::WriteImportItems()
/* If we used to have more items than we have now, DELETE the excess items.
We just keep deleting items and incrementing until we find there aren't any
more to DELETE.*/
i = this->mExtImportItems->Count();
i = this->mExtImportItems->size();
do {
name.Printf (wxT("/ExtImportItems/Item%d"), (int)i);
// No item to DELETE? Then it's time to finish.
@ -325,11 +322,9 @@ void Importer::WriteImportItems()
} while( true );
}
ExtImportItem *Importer::CreateDefaultImportItem()
movable_ptr<ExtImportItem> Importer::CreateDefaultImportItem()
{
ExtImportItem *new_item;
new_item = new ExtImportItem();
auto new_item = make_movable<ExtImportItem>();
new_item->extensions.Add(wxT("*"));
new_item->mime_types.Add(wxT("*"));
@ -392,9 +387,9 @@ bool Importer::Import(const wxString &fName,
wxLogMessage(wxT("File name is %s"),(const char *) fName.c_str());
wxLogMessage(wxT("Mime type is %s"),(const char *) mime_type.Lower().c_str());
for (size_t i = 0; i < mExtImportItems->Count(); i++)
for (const auto &uItem : *mExtImportItems)
{
ExtImportItem *item = &(*mExtImportItems)[i];
ExtImportItem *item = uItem.get();
bool matches_ext = false, matches_mime = false;
wxLogDebug(wxT("Testing extensions"));
for (size_t j = 0; j < item->extensions.Count(); j++)

View File

@ -45,7 +45,7 @@ class ExtImportItem;
using FormatList = std::vector<Format> ;
WX_DEFINE_ARRAY_PTR(ImportPlugin *, ImportPluginPtrArray);
WX_DECLARE_OBJARRAY(ExtImportItem, ExtImportItems);
using ExtImportItems = std::vector< movable_ptr<ExtImportItem> >;
class ExtImportItem
{
@ -129,13 +129,13 @@ public:
* Returns a pointer to internal items array.
* External objects are allowed to change the array contents.
*/
ExtImportItems *GetImportItems() { return mExtImportItems; };
ExtImportItems &GetImportItems() { return *mExtImportItems; };
/**
* Allocates NEW ExtImportItem, fills it with default data
* and returns a pointer to it.
*/
ExtImportItem *CreateDefaultImportItem();
movable_ptr<ExtImportItem> CreateDefaultImportItem();
// if false, the import failed and errorMessage will be set.
bool Import(const wxString &fName,

View File

@ -146,10 +146,13 @@ void ExtImportPrefs::PopulateOrExchange(ShuttleGui & S)
PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE_USEHEADER);
ExtImportItems *items = Importer::Get().GetImportItems();
for (unsigned int i = 0; i < items->Count(); i++)
AddItemToTable (i, &(*items)[i]);
if (items->Count() > 0)
auto &items = Importer::Get().GetImportItems();
{
int i = -1;
for (const auto &item : items)
AddItemToTable (++i, item.get());
}
if (!items.empty())
{
RuleTable->SelectRow(0);
RuleTable->SetGridCursor(0,0);
@ -212,8 +215,8 @@ void ExtImportPrefs::SwapPluginRows (int row1, int row2)
long d, d2;
ImportPlugin *ip1, *ip2;
ExtImportItems *items = Importer::Get().GetImportItems();
ExtImportItem *item = &(*items)[last_selected];
auto &items = Importer::Get().GetImportItems();
ExtImportItem *item = items[last_selected].get();
t = PluginList->GetItemText (row1);
d = PluginList->GetItemData (row1);
@ -261,8 +264,8 @@ bool ExtImportPrefs::DoOnPluginKeyDown (int code)
if (last_selected == -1)
return false;
ExtImportItems *items = Importer::Get().GetImportItems();
ExtImportItem *item = &(*items)[last_selected];
auto &items = Importer::Get().GetImportItems();
ExtImportItem *item = items[last_selected].get();
if (code == WXK_UP && itemIndex == 0)
return false;
@ -298,7 +301,6 @@ bool ExtImportPrefs::DoOnPluginKeyDown (int code)
void ExtImportPrefs::SwapRows (int row1, int row2)
{
int t;
ExtImportItem *t1, *t2;
wxString ts;
if (row1 == row2)
return;
@ -308,11 +310,12 @@ void ExtImportPrefs::SwapRows (int row1, int row2)
row1 = row2;
row2 = t;
}
ExtImportItems *items = Importer::Get().GetImportItems();
t1 = items->Detach(row1);
t2 = items->Detach(row1);
items->Insert (t1, row1);
items->Insert (t2, row1);
auto &items = Importer::Get().GetImportItems();
auto &t1 = items[row1];
auto &t2 = items[row2];
std::swap(t1, t2);
for (int i = 0; i < RuleTable->GetNumberCols(); i++)
{
ts = RuleTable->GetCellValue (row2, i);
@ -411,14 +414,14 @@ void ExtImportPrefs::OnRuleTableSelectRange (wxGridRangeSelectEvent& event)
void ExtImportPrefs::DoOnRuleTableSelect (int toprow)
{
ExtImportItems *items = Importer::Get().GetImportItems();
auto &items = Importer::Get().GetImportItems();
if (toprow < 0 || toprow > (int)items->GetCount())
if (toprow < 0 || toprow > (int)items.size())
{
return;
}
ExtImportItem *item = &(*items)[toprow];
ExtImportItem *item = items[toprow].get();
PluginList->DeleteAllItems();
int fcount;
@ -463,8 +466,8 @@ void ExtImportPrefs::OnRuleTableEdit (wxGridEvent& event)
{
int row = event.GetRow();
int col = event.GetCol();
ExtImportItems *items = Importer::Get().GetImportItems();
ExtImportItem *item = &(*items)[row];
auto &items = Importer::Get().GetImportItems();
ExtImportItem *item = items[row].get();
RuleTable->SaveEditControlValue();
wxString val = RuleTable->GetCellValue (row, col);
@ -566,11 +569,12 @@ void ExtImportPrefs::AddItemToTable (int index, const ExtImportItem *item)
void ExtImportPrefs::OnAddRule(wxCommandEvent& WXUNUSED(event))
{
ExtImportItems *items = Importer::Get().GetImportItems();
ExtImportItem *item = Importer::Get().CreateDefaultImportItem();
items->Add (item);
auto &items = Importer::Get().GetImportItems();
auto uitem = Importer::Get().CreateDefaultImportItem();
auto item = uitem.get();
items.push_back(std::move(uitem));
AddItemToTable (RuleTable->GetNumberRows (), item);
RuleTable->SelectRow(RuleTable->GetNumberRows () - 1);
RuleTable->SetGridCursor (RuleTable->GetNumberRows () - 1, 0);
RuleTable->SetFocus();
@ -580,7 +584,7 @@ void ExtImportPrefs::OnDelRule(wxCommandEvent& WXUNUSED(event))
{
if (last_selected < 0)
return;
ExtImportItems *items = Importer::Get().GetImportItems();
auto &items = Importer::Get().GetImportItems();
int msgres = wxMessageBox (_("Do you really want to delete selected rule?"),
_("Rule deletion confirmation"), wxYES_NO, RuleTable);
@ -588,7 +592,7 @@ void ExtImportPrefs::OnDelRule(wxCommandEvent& WXUNUSED(event))
return;
RuleTable->DeleteRows (last_selected);
items->RemoveAt (last_selected);
items.erase (items.begin() + last_selected);
RuleTable->AutoSizeColumns ();
if (last_selected >= RuleTable->GetNumberRows ())
last_selected = RuleTable->GetNumberRows () - 1;