1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-13 22:21:11 +02:00

One less indirection accessing containers in Importer

This commit is contained in:
Paul Licameli
2016-08-10 23:33:51 -04:00
parent 8226441210
commit eef2669abd
2 changed files with 32 additions and 41 deletions

View File

@@ -77,41 +77,35 @@ Importer & Importer::Get()
Importer::Importer() Importer::Importer()
{ {
mExtImportItems = NULL;
} }
Importer::~Importer() Importer::~Importer()
{ {
if (mExtImportItems != NULL)
{
delete mExtImportItems;
mExtImportItems = NULL;
}
} }
bool Importer::Initialize() bool Importer::Initialize()
{ {
mImportPluginList = new ImportPluginList; ImportPluginList{}.swap(mImportPluginList);
mUnusableImportPluginList = new UnusableImportPluginList; UnusableImportPluginList{}.swap(mUnusableImportPluginList);
mExtImportItems = NULL; ExtImportItems{}.swap(mExtImportItems);
// build the list of import plugin and/or unusableImporters. // build the list of import plugin and/or unusableImporters.
// order is significant. If none match, they will all be tried // order is significant. If none match, they will all be tried
// in the order defined here. // in the order defined here.
GetPCMImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetPCMImportPlugin(mImportPluginList, mUnusableImportPluginList);
GetOGGImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetOGGImportPlugin(mImportPluginList, mUnusableImportPluginList);
GetFLACImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetFLACImportPlugin(mImportPluginList, mUnusableImportPluginList);
GetMP3ImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetMP3ImportPlugin(mImportPluginList, mUnusableImportPluginList);
GetLOFImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetLOFImportPlugin(mImportPluginList, mUnusableImportPluginList);
#if defined(USE_FFMPEG) #if defined(USE_FFMPEG)
GetFFmpegImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetFFmpegImportPlugin(mImportPluginList, mUnusableImportPluginList);
#endif #endif
#ifdef USE_QUICKTIME #ifdef USE_QUICKTIME
GetQTImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetQTImportPlugin(mImportPluginList, mUnusableImportPluginList);
#endif #endif
#if defined(USE_GSTREAMER) #if defined(USE_GSTREAMER)
GetGStreamerImportPlugin(*mImportPluginList, *mUnusableImportPluginList); GetGStreamerImportPlugin(mImportPluginList, mUnusableImportPluginList);
#endif #endif
ReadImportItems(); ReadImportItems();
@@ -122,15 +116,15 @@ bool Importer::Initialize()
bool Importer::Terminate() bool Importer::Terminate()
{ {
WriteImportItems(); WriteImportItems();
delete mImportPluginList; ImportPluginList{}.swap( mImportPluginList );
delete mUnusableImportPluginList; UnusableImportPluginList{}.swap( mUnusableImportPluginList );
return true; return true;
} }
void Importer::GetSupportedImportFormats(FormatList *formatList) void Importer::GetSupportedImportFormats(FormatList *formatList)
{ {
for(const auto &importPlugin : *mImportPluginList) for(const auto &importPlugin : mImportPluginList)
{ {
#ifdef __AUDACITY_OLD_STD__ #ifdef __AUDACITY_OLD_STD__
formatList->push_back(Format{importPlugin->GetPluginFormatDescription(), formatList->push_back(Format{importPlugin->GetPluginFormatDescription(),
@@ -157,10 +151,7 @@ void Importer::ReadImportItems()
wxString item_name; wxString item_name;
wxString item_value; wxString item_value;
if (this->mExtImportItems != NULL) ExtImportItems{}.swap(mExtImportItems);
delete this->mExtImportItems;
this->mExtImportItems = new ExtImportItems();
/* Rule string format is: /* Rule string format is:
* extension1:extension2:extension3\mime_type1:mime_type2:mime_type3|filter1:filter2:filter3\unusedfilter1:unusedfilter2 * extension1:extension2:extension3\mime_type1:mime_type2:mime_type3|filter1:filter2:filter3\unusedfilter1:unusedfilter2
* backslashes are escaped and unescaped internally * backslashes are escaped and unescaped internally
@@ -220,7 +211,7 @@ void Importer::ReadImportItems()
for (size_t i = 0; i < new_item->filters.Count(); i++) for (size_t i = 0; i < new_item->filters.Count(); i++)
{ {
bool found = false; bool found = false;
for (const auto &importPlugin : *mImportPluginList) for (const auto &importPlugin : mImportPluginList)
{ {
if (importPlugin->GetPluginStringID().Cmp(new_item->filters[i]) == 0) if (importPlugin->GetPluginStringID().Cmp(new_item->filters[i]) == 0)
{ {
@@ -234,7 +225,7 @@ void Importer::ReadImportItems()
new_item->filter_objects.Add (NULL); new_item->filter_objects.Add (NULL);
} }
/* Find all filter objects that are not present in the filter list */ /* Find all filter objects that are not present in the filter list */
for (const auto &importPlugin : *mImportPluginList) for (const auto &importPlugin : mImportPluginList)
{ {
bool found = false; bool found = false;
for (size_t i = 0; i < new_item->filter_objects.Count(); i++) for (size_t i = 0; i < new_item->filter_objects.Count(); i++)
@@ -257,7 +248,7 @@ void Importer::ReadImportItems()
new_item->divider++; new_item->divider++;
} }
} }
this->mExtImportItems->push_back( std::move(new_item) ); this->mExtImportItems.push_back( std::move(new_item) );
} }
} }
@@ -265,9 +256,9 @@ void Importer::WriteImportItems()
{ {
size_t i; size_t i;
wxString val, name; wxString val, name;
for (i = 0; i < this->mExtImportItems->size(); i++) for (i = 0; i < this->mExtImportItems.size(); i++)
{ {
ExtImportItem *item = (*mExtImportItems)[i].get(); ExtImportItem *item = mExtImportItems[i].get();
val.Clear(); val.Clear();
for (size_t j = 0; j < item->extensions.Count(); j++) for (size_t j = 0; j < item->extensions.Count(); j++)
@@ -307,7 +298,7 @@ void Importer::WriteImportItems()
/* If we used to have more items than we have now, DELETE the excess items. /* 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 We just keep deleting items and incrementing until we find there aren't any
more to DELETE.*/ more to DELETE.*/
i = this->mExtImportItems->size(); i = this->mExtImportItems.size();
do { do {
name.Printf (wxT("/ExtImportItems/Item%d"), (int)i); name.Printf (wxT("/ExtImportItems/Item%d"), (int)i);
// No item to DELETE? Then it's time to finish. // No item to DELETE? Then it's time to finish.
@@ -328,7 +319,7 @@ movable_ptr<ExtImportItem> Importer::CreateDefaultImportItem()
new_item->extensions.Add(wxT("*")); new_item->extensions.Add(wxT("*"));
new_item->mime_types.Add(wxT("*")); new_item->mime_types.Add(wxT("*"));
for (const auto &importPlugin : *mImportPluginList) for (const auto &importPlugin : mImportPluginList)
{ {
new_item->filters.Add (importPlugin->GetPluginStringID()); new_item->filters.Add (importPlugin->GetPluginStringID());
new_item->filter_objects.Add (importPlugin.get()); new_item->filter_objects.Add (importPlugin.get());
@@ -373,7 +364,7 @@ bool Importer::Import(const wxString &fName,
if (usersSelectionOverrides) if (usersSelectionOverrides)
{ {
for (const auto &plugin : *mImportPluginList) for (const auto &plugin : mImportPluginList)
{ {
if (plugin->GetPluginFormatDescription().CompareTo(type) == 0) if (plugin->GetPluginFormatDescription().CompareTo(type) == 0)
{ {
@@ -387,7 +378,7 @@ bool Importer::Import(const wxString &fName,
wxLogMessage(wxT("File name is %s"),(const char *) fName.c_str()); wxLogMessage(wxT("File name is %s"),(const char *) fName.c_str());
wxLogMessage(wxT("Mime type is %s"),(const char *) mime_type.Lower().c_str()); wxLogMessage(wxT("Mime type is %s"),(const char *) mime_type.Lower().c_str());
for (const auto &uItem : *mExtImportItems) for (const auto &uItem : mExtImportItems)
{ {
ExtImportItem *item = uItem.get(); ExtImportItem *item = uItem.get();
bool matches_ext = false, matches_mime = false; bool matches_ext = false, matches_mime = false;
@@ -449,10 +440,10 @@ bool Importer::Import(const wxString &fName,
// is not changed by user selection overrides or any other mechanism, but we include an assert // is not changed by user selection overrides or any other mechanism, but we include an assert
// in case subsequent code revisions to the constructor should break this assumption that // in case subsequent code revisions to the constructor should break this assumption that
// libsndfile is first. // libsndfile is first.
ImportPlugin *libsndfilePlugin = mImportPluginList->begin()->get(); ImportPlugin *libsndfilePlugin = mImportPluginList.begin()->get();
wxASSERT(libsndfilePlugin->GetPluginStringID().IsSameAs(wxT("libsndfile"))); wxASSERT(libsndfilePlugin->GetPluginStringID().IsSameAs(wxT("libsndfile")));
for (const auto &plugin : *mImportPluginList) for (const auto &plugin : mImportPluginList)
{ {
// Make sure its not already in the list // Make sure its not already in the list
if (importPlugins.end() == if (importPlugins.end() ==
@@ -488,7 +479,7 @@ bool Importer::Import(const wxString &fName,
// Otherwise, if FFmpeg (libav) has not been installed, libmad will still be there near the // Otherwise, if FFmpeg (libav) has not been installed, libmad will still be there near the
// end of the preference list importPlugins, where it will claim success importing FFmpeg file // end of the preference list importPlugins, where it will claim success importing FFmpeg file
// formats unsuitable for it, and produce distorted results. // formats unsuitable for it, and produce distorted results.
for (const auto &plugin : *mImportPluginList) for (const auto &plugin : mImportPluginList)
{ {
if (!(plugin->GetPluginStringID().IsSameAs(wxT("libmad")))) if (!(plugin->GetPluginStringID().IsSameAs(wxT("libmad"))))
{ {
@@ -564,7 +555,7 @@ bool Importer::Import(const wxString &fName,
// None of our plugins can handle this file. It might be that // None of our plugins can handle this file. It might be that
// Audacity supports this format, but support was not compiled in. // Audacity supports this format, but support was not compiled in.
// If so, notify the user of this fact // If so, notify the user of this fact
for (const auto &unusableImportPlugin : *mUnusableImportPluginList) for (const auto &unusableImportPlugin : mUnusableImportPluginList)
{ {
if( unusableImportPlugin->SupportsExtension(extension) ) if( unusableImportPlugin->SupportsExtension(extension) )
{ {

View File

@@ -129,7 +129,7 @@ public:
* Returns a pointer to internal items array. * Returns a pointer to internal items array.
* External objects are allowed to change the array contents. * 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 * Allocates NEW ExtImportItem, fills it with default data
@@ -147,9 +147,9 @@ public:
private: private:
static Importer mInstance; static Importer mInstance;
ExtImportItems *mExtImportItems; ExtImportItems mExtImportItems;
ImportPluginList *mImportPluginList; ImportPluginList mImportPluginList;
UnusableImportPluginList *mUnusableImportPluginList; UnusableImportPluginList mUnusableImportPluginList;
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------