Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[musicdb] Demise CSongMap and just use an std::map

  • Loading branch information...
commit 0eac69a2328a17cfd83e165d3a06c6eeff113fef 1 parent 170dc3e
night199uk authored
10 xbmc/music/MusicDatabase.cpp
@@ -1706,7 +1706,7 @@ void CMusicDatabase::IncrementPlayCount(const CFileItem& item)
1706 1706 }
1707 1707 }
1708 1708
1709   -bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs, bool bAppendToMap)
  1709 +bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, MAPSONGS& songs, bool bAppendToMap)
1710 1710 {
1711 1711 CStdString strPath(strPath1);
1712 1712 try
@@ -1715,7 +1715,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
1715 1715 URIUtils::AddSlashAtEnd(strPath);
1716 1716
1717 1717 if (!bAppendToMap)
1718   - songs.Clear();
  1718 + songs.clear();
1719 1719
1720 1720 if (NULL == m_pDB.get()) return false;
1721 1721 if (NULL == m_pDS.get()) return false;
@@ -1731,7 +1731,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
1731 1731 while (!m_pDS->eof())
1732 1732 {
1733 1733 CSong song = GetSongFromDataset();
1734   - songs.Add(song.strFileName, song);
  1734 + songs.insert(make_pair(song.strFileName, song));
1735 1735 m_pDS->next();
1736 1736 }
1737 1737
@@ -3958,7 +3958,7 @@ bool CMusicDatabase::GetPathHash(const CStdString &path, CStdString &hash)
3958 3958 return false;
3959 3959 }
3960 3960
3961   -bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &songs, bool exact)
  3961 +bool CMusicDatabase::RemoveSongsFromPath(const CStdString& path1, MAPSONGS& songs, bool exact)
3962 3962 {
3963 3963 // We need to remove all songs from this path, as their tags are going
3964 3964 // to be re-read. We need to remove all songs from the song table + all links to them
@@ -4011,7 +4011,7 @@ bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &song
4011 4011 {
4012 4012 CSong song = GetSongFromDataset();
4013 4013 song.strThumb = GetArtForItem(song.idSong, "song", "thumb");
4014   - songs.Add(song.strFileName, song);
  4014 + songs.insert(make_pair(song.strFileName, song));
4015 4015 songIds += PrepareSQL("%i,", song.idSong);
4016 4016 ids.push_back(song.idSong);
4017 4017 m_pDS->next();
5 xbmc/music/MusicDatabase.h
@@ -122,7 +122,7 @@ class CMusicDatabase : public CDatabase
122 122 bool GetSongById(int idSong, CSong& song);
123 123 bool GetSongByKaraokeNumber( int number, CSong& song );
124 124 bool SetKaraokeSongDelay( int idSong, int delay );
125   - bool GetSongsByPath(const CStdString& strPath, CSongMap& songs, bool bAppendToMap = false);
  125 + bool GetSongsByPath(const CStdString& strPath1, MAPSONGS& songs, bool bAppendToMap = false);
126 126 bool Search(const CStdString& search, CFileItemList &items);
127 127
128 128 bool GetAlbumFromSong(int idSong, CAlbum &album);
@@ -144,12 +144,13 @@ class CMusicDatabase : public CDatabase
144 144 bool GetRecentlyAddedAlbumSongs(const CStdString& strBaseDir, CFileItemList& item, unsigned int limit=0);
145 145 bool GetRecentlyPlayedAlbums(VECALBUMS& albums);
146 146 bool GetRecentlyPlayedAlbumSongs(const CStdString& strBaseDir, CFileItemList& item);
  147 +
147 148 /*! \brief Increment the playcount of an item
148 149 Increments the playcount and updates the last played date
149 150 \param item CFileItem to increment the playcount for
150 151 */
151 152 void IncrementPlayCount(const CFileItem &item);
152   - bool RemoveSongsFromPath(const CStdString &path, CSongMap &songs, bool exact=true);
  153 + bool RemoveSongsFromPath(const CStdString& path, MAPSONGS& songs, bool exact = true);
153 154 bool CleanupOrphanedItems();
154 155 bool GetPaths(std::set<CStdString> &paths);
155 156 bool SetPathHash(const CStdString &path, const CStdString &hash);
11 xbmc/music/MusicInfoLoader.cpp
@@ -147,12 +147,11 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
147 147 m_databaseHits++;
148 148 }
149 149
150   - CSong *song=NULL;
151   -
152   - if ((song=m_songsMap.Find(pItem->GetPath()))!=NULL)
  150 + MAPSONGS::iterator it = m_songsMap.find(pItem->GetPath());
  151 + if (it != m_songsMap.end())
153 152 { // Have we loaded this item from database before
154   - pItem->GetMusicInfoTag()->SetSong(*song);
155   - pItem->SetThumbnailImage(song->strThumb);
  153 + pItem->GetMusicInfoTag()->SetSong(it->second);
  154 + pItem->SetThumbnailImage(it->second.strThumb);
156 155 }
157 156 else if (pItem->IsMusicDb())
158 157 { // a music db item that doesn't have tag loaded - grab details from the database
@@ -183,7 +182,7 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
183 182 void CMusicInfoLoader::OnLoaderFinish()
184 183 {
185 184 // cleanup last loaded songs from database
186   - m_songsMap.Clear();
  185 + m_songsMap.clear();
187 186
188 187 // cleanup cache loaded from HD
189 188 m_mapFileItems->Clear();
2  xbmc/music/MusicInfoLoader.h
@@ -43,7 +43,7 @@ class CMusicInfoLoader : public CBackgroundInfoLoader
43 43 protected:
44 44 CStdString m_strCacheFileName;
45 45 CFileItemList* m_mapFileItems;
46   - CSongMap m_songsMap;
  46 + MAPSONGS m_songsMap;
47 47 CStdString m_strPrevPath;
48 48 CMusicDatabase m_musicDatabase;
49 49 unsigned int m_databaseHits;
42 xbmc/music/Song.cpp
@@ -130,45 +130,3 @@ bool CSong::ArtMatches(const CSong &right) const
130 130 return (right.strThumb == strThumb &&
131 131 embeddedArt.matches(right.embeddedArt));
132 132 }
133   -
134   -CSongMap::CSongMap()
135   -{
136   -}
137   -
138   -std::map<CStdString, CSong>::const_iterator CSongMap::Begin()
139   -{
140   - return m_map.begin();
141   -}
142   -
143   -std::map<CStdString, CSong>::const_iterator CSongMap::End()
144   -{
145   - return m_map.end();
146   -}
147   -
148   -void CSongMap::Add(const CStdString &file, const CSong &song)
149   -{
150   - CStdString lower = file;
151   - lower.ToLower();
152   - m_map.insert(pair<CStdString, CSong>(lower, song));
153   -}
154   -
155   -CSong* CSongMap::Find(const CStdString &file)
156   -{
157   - CStdString lower = file;
158   - lower.ToLower();
159   - map<CStdString, CSong>::iterator it = m_map.find(lower);
160   - if (it == m_map.end())
161   - return NULL;
162   - return &(*it).second;
163   -}
164   -
165   -void CSongMap::Clear()
166   -{
167   - m_map.erase(m_map.begin(), m_map.end());
168   -}
169   -
170   -int CSongMap::Size()
171   -{
172   - return (int)m_map.size();
173   -}
174   -
16 xbmc/music/Song.h
@@ -113,21 +113,7 @@ class CSong: public ISerializable
113 113 \ingroup music
114 114 \brief A map of CSong objects, used for CMusicDatabase
115 115 */
116   -class CSongMap
117   -{
118   -public:
119   - CSongMap();
120   -
121   - std::map<CStdString, CSong>::const_iterator Begin();
122   - std::map<CStdString, CSong>::const_iterator End();
123   - CSong *Find(const CStdString &file);
124   - void Add(const CStdString &file, const CSong &song);
125   - void Clear();
126   - int Size();
127   -
128   -private:
129   - std::map<CStdString, CSong> m_map;
130   -};
  116 +typedef std::map<CStdString, CSong> MAPSONGS;
131 117
132 118 /*!
133 119 \ingroup music
7 xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -437,7 +437,7 @@ bool CMusicInfoScanner::DoScan(const CStdString& strDirectory)
437 437
438 438 int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory)
439 439 {
440   - CSongMap songsMap;
  440 + MAPSONGS songsMap;
441 441
442 442 // get all information for all files in current directory from database, and remove them
443 443 if (m_musicDatabase.RemoveSongsFromPath(strDirectory, songsMap))
@@ -468,7 +468,10 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
468 468 // CLog::Log(LOGDEBUG, "%s - Reading tag for: %s", __FUNCTION__, pItem->GetPath().c_str());
469 469
470 470 // grab info from the song
471   - CSong *dbSong = songsMap.Find(pItem->GetPath());
  471 + CSong *dbSong = NULL;
  472 + MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
  473 + if (it != songsMap.end())
  474 + dbSong = &it->second;
472 475
473 476 CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
474 477 if (!tag.Loaded() )
2  xbmc/music/windows/GUIWindowMusicSongs.cpp
@@ -470,7 +470,7 @@ void CGUIWindowMusicSongs::OnRemoveSource(int iItem)
470 470 bool bCanceled;
471 471 if (CGUIDialogYesNo::ShowAndGetInput(522,20340,20341,20022,bCanceled))
472 472 {
473   - CSongMap songs;
  473 + MAPSONGS songs;
474 474 CMusicDatabase database;
475 475 database.Open();
476 476 database.RemoveSongsFromPath(m_vecItems->Get(iItem)->GetPath(),songs,false);

0 comments on commit 0eac69a

Please sign in to comment.
Something went wrong with that request. Please try again.