Skip to content
Browse files

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

  • Loading branch information...
1 parent 170dc3e commit 0eac69a2328a17cfd83e165d3a06c6eeff113fef @night199uk committed Jul 3, 2012
View
10 xbmc/music/MusicDatabase.cpp
@@ -1706,7 +1706,7 @@ void CMusicDatabase::IncrementPlayCount(const CFileItem& item)
}
}
-bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs, bool bAppendToMap)
+bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, MAPSONGS& songs, bool bAppendToMap)
{
CStdString strPath(strPath1);
try
@@ -1715,7 +1715,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
URIUtils::AddSlashAtEnd(strPath);
if (!bAppendToMap)
- songs.Clear();
+ songs.clear();
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
@@ -1731,7 +1731,7 @@ bool CMusicDatabase::GetSongsByPath(const CStdString& strPath1, CSongMap& songs,
while (!m_pDS->eof())
{
CSong song = GetSongFromDataset();
- songs.Add(song.strFileName, song);
+ songs.insert(make_pair(song.strFileName, song));
m_pDS->next();
}
@@ -3958,7 +3958,7 @@ bool CMusicDatabase::GetPathHash(const CStdString &path, CStdString &hash)
return false;
}
-bool CMusicDatabase::RemoveSongsFromPath(const CStdString &path1, CSongMap &songs, bool exact)
+bool CMusicDatabase::RemoveSongsFromPath(const CStdString& path1, MAPSONGS& songs, bool exact)
{
// We need to remove all songs from this path, as their tags are going
// 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
{
CSong song = GetSongFromDataset();
song.strThumb = GetArtForItem(song.idSong, "song", "thumb");
- songs.Add(song.strFileName, song);
+ songs.insert(make_pair(song.strFileName, song));
songIds += PrepareSQL("%i,", song.idSong);
ids.push_back(song.idSong);
m_pDS->next();
View
5 xbmc/music/MusicDatabase.h
@@ -122,7 +122,7 @@ class CMusicDatabase : public CDatabase
bool GetSongById(int idSong, CSong& song);
bool GetSongByKaraokeNumber( int number, CSong& song );
bool SetKaraokeSongDelay( int idSong, int delay );
- bool GetSongsByPath(const CStdString& strPath, CSongMap& songs, bool bAppendToMap = false);
+ bool GetSongsByPath(const CStdString& strPath1, MAPSONGS& songs, bool bAppendToMap = false);
bool Search(const CStdString& search, CFileItemList &items);
bool GetAlbumFromSong(int idSong, CAlbum &album);
@@ -144,12 +144,13 @@ class CMusicDatabase : public CDatabase
bool GetRecentlyAddedAlbumSongs(const CStdString& strBaseDir, CFileItemList& item, unsigned int limit=0);
bool GetRecentlyPlayedAlbums(VECALBUMS& albums);
bool GetRecentlyPlayedAlbumSongs(const CStdString& strBaseDir, CFileItemList& item);
+
/*! \brief Increment the playcount of an item
Increments the playcount and updates the last played date
\param item CFileItem to increment the playcount for
*/
void IncrementPlayCount(const CFileItem &item);
- bool RemoveSongsFromPath(const CStdString &path, CSongMap &songs, bool exact=true);
+ bool RemoveSongsFromPath(const CStdString& path, MAPSONGS& songs, bool exact = true);
bool CleanupOrphanedItems();
bool GetPaths(std::set<CStdString> &paths);
bool SetPathHash(const CStdString &path, const CStdString &hash);
View
11 xbmc/music/MusicInfoLoader.cpp
@@ -147,12 +147,11 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
m_databaseHits++;
}
- CSong *song=NULL;
-
- if ((song=m_songsMap.Find(pItem->GetPath()))!=NULL)
+ MAPSONGS::iterator it = m_songsMap.find(pItem->GetPath());
+ if (it != m_songsMap.end())
{ // Have we loaded this item from database before
- pItem->GetMusicInfoTag()->SetSong(*song);
- pItem->SetThumbnailImage(song->strThumb);
+ pItem->GetMusicInfoTag()->SetSong(it->second);
+ pItem->SetThumbnailImage(it->second.strThumb);
}
else if (pItem->IsMusicDb())
{ // a music db item that doesn't have tag loaded - grab details from the database
@@ -183,7 +182,7 @@ bool CMusicInfoLoader::LoadItem(CFileItem* pItem)
void CMusicInfoLoader::OnLoaderFinish()
{
// cleanup last loaded songs from database
- m_songsMap.Clear();
+ m_songsMap.clear();
// cleanup cache loaded from HD
m_mapFileItems->Clear();
View
2 xbmc/music/MusicInfoLoader.h
@@ -43,7 +43,7 @@ class CMusicInfoLoader : public CBackgroundInfoLoader
protected:
CStdString m_strCacheFileName;
CFileItemList* m_mapFileItems;
- CSongMap m_songsMap;
+ MAPSONGS m_songsMap;
CStdString m_strPrevPath;
CMusicDatabase m_musicDatabase;
unsigned int m_databaseHits;
View
42 xbmc/music/Song.cpp
@@ -130,45 +130,3 @@ bool CSong::ArtMatches(const CSong &right) const
return (right.strThumb == strThumb &&
embeddedArt.matches(right.embeddedArt));
}
-
-CSongMap::CSongMap()
-{
-}
-
-std::map<CStdString, CSong>::const_iterator CSongMap::Begin()
-{
- return m_map.begin();
-}
-
-std::map<CStdString, CSong>::const_iterator CSongMap::End()
-{
- return m_map.end();
-}
-
-void CSongMap::Add(const CStdString &file, const CSong &song)
-{
- CStdString lower = file;
- lower.ToLower();
- m_map.insert(pair<CStdString, CSong>(lower, song));
-}
-
-CSong* CSongMap::Find(const CStdString &file)
-{
- CStdString lower = file;
- lower.ToLower();
- map<CStdString, CSong>::iterator it = m_map.find(lower);
- if (it == m_map.end())
- return NULL;
- return &(*it).second;
-}
-
-void CSongMap::Clear()
-{
- m_map.erase(m_map.begin(), m_map.end());
-}
-
-int CSongMap::Size()
-{
- return (int)m_map.size();
-}
-
View
16 xbmc/music/Song.h
@@ -113,21 +113,7 @@ class CSong: public ISerializable
\ingroup music
\brief A map of CSong objects, used for CMusicDatabase
*/
-class CSongMap
-{
-public:
- CSongMap();
-
- std::map<CStdString, CSong>::const_iterator Begin();
- std::map<CStdString, CSong>::const_iterator End();
- CSong *Find(const CStdString &file);
- void Add(const CStdString &file, const CSong &song);
- void Clear();
- int Size();
-
-private:
- std::map<CStdString, CSong> m_map;
-};
+typedef std::map<CStdString, CSong> MAPSONGS;
/*!
\ingroup music
View
7 xbmc/music/infoscanner/MusicInfoScanner.cpp
@@ -437,7 +437,7 @@ bool CMusicInfoScanner::DoScan(const CStdString& strDirectory)
int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString& strDirectory)
{
- CSongMap songsMap;
+ MAPSONGS songsMap;
// get all information for all files in current directory from database, and remove them
if (m_musicDatabase.RemoveSongsFromPath(strDirectory, songsMap))
@@ -468,7 +468,10 @@ int CMusicInfoScanner::RetrieveMusicInfo(CFileItemList& items, const CStdString&
// CLog::Log(LOGDEBUG, "%s - Reading tag for: %s", __FUNCTION__, pItem->GetPath().c_str());
// grab info from the song
- CSong *dbSong = songsMap.Find(pItem->GetPath());
+ CSong *dbSong = NULL;
+ MAPSONGS::iterator it = songsMap.find(pItem->GetPath());
+ if (it != songsMap.end())
+ dbSong = &it->second;
CMusicInfoTag& tag = *pItem->GetMusicInfoTag();
if (!tag.Loaded() )
View
2 xbmc/music/windows/GUIWindowMusicSongs.cpp
@@ -470,7 +470,7 @@ void CGUIWindowMusicSongs::OnRemoveSource(int iItem)
bool bCanceled;
if (CGUIDialogYesNo::ShowAndGetInput(522,20340,20341,20022,bCanceled))
{
- CSongMap songs;
+ MAPSONGS songs;
CMusicDatabase database;
database.Open();
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.