Don't use an internal iterator in Tags
This commit is contained in:
parent
a1c7b396b3
commit
ffe9989f7c
45
src/Tags.cpp
45
src/Tags.cpp
|
@ -394,30 +394,9 @@ wxString Tags::GetTag(const wxString & name)
|
|||
return mMap[iter->second];
|
||||
}
|
||||
|
||||
bool Tags::GetFirst(wxString & name, wxString & value)
|
||||
Tags::Iterators Tags::GetRange() const
|
||||
{
|
||||
mIter = mMap.begin();
|
||||
if (mIter == mMap.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = mIter->first;
|
||||
value = mIter->second;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Tags::GetNext(wxString & name, wxString & value)
|
||||
{
|
||||
++mIter;
|
||||
if (mIter == mMap.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = mIter->first;
|
||||
value = mIter->second;
|
||||
|
||||
return true;
|
||||
return std::make_pair(mMap.begin(), mMap.end());
|
||||
}
|
||||
|
||||
void Tags::SetTag(const wxString & name, const wxString & value)
|
||||
|
@ -510,8 +489,9 @@ void Tags::WriteXML(XMLWriter &xmlFile)
|
|||
{
|
||||
xmlFile.StartTag(wxT("tags"));
|
||||
|
||||
wxString n, v;
|
||||
for (bool cont = GetFirst(n, v); cont; cont = GetNext(n, v)) {
|
||||
for (const auto &pair : GetRange()) {
|
||||
const auto &n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
xmlFile.StartTag(wxT("tag"));
|
||||
xmlFile.WriteAttr(wxT("name"), n);
|
||||
xmlFile.WriteAttr(wxT("value"), v);
|
||||
|
@ -863,8 +843,6 @@ bool TagsEditor::TransferDataFromWindow()
|
|||
bool TagsEditor::TransferDataToWindow()
|
||||
{
|
||||
size_t i;
|
||||
wxString n;
|
||||
wxString v;
|
||||
TagMap popTagMap;
|
||||
|
||||
// Disable redrawing until we're done
|
||||
|
@ -895,12 +873,14 @@ bool TagsEditor::TransferDataToWindow()
|
|||
}
|
||||
|
||||
// Populate the rest
|
||||
for (bool cont = mLocal.GetFirst(n, v); cont; cont = mLocal.GetNext(n, v)) {
|
||||
if ( popTagMap.find(n) == popTagMap.end() ) {
|
||||
for (const auto &pair : mLocal.GetRange()) {
|
||||
const auto &n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
if (popTagMap.find(n) == popTagMap.end()) {
|
||||
mGrid->AppendRows();
|
||||
mGrid->SetCellValue(i, 0, n);
|
||||
mGrid->SetCellValue(i, 1, v);
|
||||
i++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1186,8 +1166,9 @@ void TagsEditor::OnSaveDefaults(wxCommandEvent & WXUNUSED(event))
|
|||
gPrefs->DeleteGroup(wxT("/Tags"));
|
||||
|
||||
// Write out each tag
|
||||
wxString n, v;
|
||||
for (bool cont = mLocal.GetFirst(n, v); cont; cont = mLocal.GetNext(n, v)) {
|
||||
for (const auto &pair : mLocal.GetRange()) {
|
||||
const auto &n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
gPrefs->Write(wxT("/Tags/") + n, v);
|
||||
}
|
||||
gPrefs->Flush();
|
||||
|
|
12
src/Tags.h
12
src/Tags.h
|
@ -33,6 +33,7 @@
|
|||
#include "widgets/Grid.h"
|
||||
#include "xml/XMLTagHandler.h"
|
||||
|
||||
#include <utility>
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/hashmap.h>
|
||||
#include <wx/notebook.h>
|
||||
|
@ -99,8 +100,14 @@ class AUDACITY_DLL_API Tags: public XMLTagHandler {
|
|||
bool HasTag(const wxString & name);
|
||||
wxString GetTag(const wxString & name);
|
||||
|
||||
bool GetFirst(wxString & name, wxString & value);
|
||||
bool GetNext(wxString & name, wxString & value);
|
||||
using IterPair = std::pair<TagMap::const_iterator, TagMap::const_iterator>;
|
||||
struct Iterators : public IterPair {
|
||||
Iterators(IterPair p) : IterPair(p) {}
|
||||
// Define begin() and end() for convenience in range-for
|
||||
auto begin() -> decltype(first) const { return first; }
|
||||
auto end() -> decltype(second) const { return second; }
|
||||
};
|
||||
Iterators GetRange() const;
|
||||
|
||||
void SetTag(const wxString & name, const wxString & value);
|
||||
void SetTag(const wxString & name, const int & value);
|
||||
|
@ -111,7 +118,6 @@ class AUDACITY_DLL_API Tags: public XMLTagHandler {
|
|||
private:
|
||||
void LoadDefaults();
|
||||
|
||||
TagMap::iterator mIter;
|
||||
TagMap mXref;
|
||||
TagMap mMap;
|
||||
|
||||
|
|
|
@ -388,8 +388,10 @@ bool ExportFLAC::GetMetadata(AudacityProject *project, Tags *tags)
|
|||
|
||||
mMetadata = ::FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT);
|
||||
|
||||
wxString n, v;
|
||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
||||
wxString n;
|
||||
for (const auto &pair : tags->GetRange()) {
|
||||
n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
if (n == TAG_YEAR) {
|
||||
n = wxT("DATE");
|
||||
}
|
||||
|
|
|
@ -344,8 +344,9 @@ int ExportMP2::AddTags(AudacityProject * WXUNUSED(project), char **buffer, bool
|
|||
#ifdef USE_LIBID3TAG
|
||||
struct id3_tag *tp = id3_tag_new();
|
||||
|
||||
wxString n, v;
|
||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
||||
for (const auto &pair : tags->GetRange()) {
|
||||
const auto &n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
const char *name = "TXXX";
|
||||
|
||||
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
||||
|
|
|
@ -1970,8 +1970,9 @@ int ExportMP3::AddTags(AudacityProject *WXUNUSED(project), char **buffer, bool *
|
|||
#ifdef USE_LIBID3TAG
|
||||
struct id3_tag *tp = id3_tag_new();
|
||||
|
||||
wxString n, v;
|
||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
||||
for (const auto &pair : tags->GetRange()) {
|
||||
const auto &n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
const char *name = "TXXX";
|
||||
|
||||
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
||||
|
|
|
@ -349,8 +349,10 @@ bool ExportOGG::FillComment(AudacityProject *project, vorbis_comment *comment, T
|
|||
|
||||
vorbis_comment_init(comment);
|
||||
|
||||
wxString n, v;
|
||||
for (bool cont = metadata->GetFirst(n, v); cont; cont = metadata->GetNext(n, v)) {
|
||||
wxString n;
|
||||
for (const auto &pair : metadata->GetRange()) {
|
||||
n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
if (n == TAG_YEAR) {
|
||||
n = wxT("DATE");
|
||||
}
|
||||
|
|
|
@ -746,8 +746,9 @@ void ExportPCM::AddID3Chunk(wxString fName, Tags *tags, int sf_format)
|
|||
#ifdef USE_LIBID3TAG
|
||||
struct id3_tag *tp = id3_tag_new();
|
||||
|
||||
wxString n, v;
|
||||
for (bool cont = tags->GetFirst(n, v); cont; cont = tags->GetNext(n, v)) {
|
||||
for (const auto &pair : tags->GetRange()) {
|
||||
const auto &n = pair.first;
|
||||
const auto &v = pair.second;
|
||||
const char *name = "TXXX";
|
||||
|
||||
if (n.CmpNoCase(TAG_TITLE) == 0) {
|
||||
|
|
Loading…
Reference in New Issue