| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Questions about right structure.
Hi everyone.
I'm tryin to create a library of my music and searching for tags in mp3 file. So good so far. My library database is defined as Code:
std::map<std::wstring,fileTag> m_playList;
where std::wstring is the complete path of the song and filetag is defined as:
class fileTag
{
public:
fileTag(){};
virtual ~fileTag(){};
std::wstring songTitle;
std::wstring artistName;
std::wstring trakNumber;
std::wstring trackYear;
std::wstring albumName;
std::wstring trackGenre;
};
Everything works ok. Now I wat to search by artist or by album. So I've created another map wich is defined as: Code:
std::map<std::wstring,std::vector<std::map<std::wstring,fileTag>::const_iterator> > m_albumList; I've made all the right reference with this function: Code:
void CPlaylistDlg::AddAlbumToList(const std::wstring & path)
{
std::map<std::wstring,fileTag>::iterator playListIt;
std::map<std::wstring,std::vector<std::map<std::wstring,fileTag>::const_iterator> >::iterator it;
playListIt = m_playList.find(path);
if(playListIt != m_playList.end())
{
it = m_albumList.find(playListIt->second.albumName);
if(it == m_albumList.end())
{
std::vector<std::map<std::wstring,fileTag>::const_iterator> m_songsVector;
m_songsVector.push_back(playListIt);
m_albumList[playListIt->second.albumName] = m_songsVector;
}
else
{
it->second.push_back(playListIt);
}
}
}
My question is: Is this the right way to do it or is there a better and faster way? Thanks to everybody. Last edited by SkyNetTo; October 9th, 2009 at 03:26 PM. |
|
#2
|
|||
|
|||
|
Re: Questions about right structure.
Quote:
If it were a linked list (std::list), then you can get away with storing iterators, since std::list iterators are not invalidated unless the particular item from the list is removed. Secondly, it would help matters if you typedefed a lot of your definitions Code:
typedef std::map<std::wstring,fileTag> StringToFileTagMap; StringToFileTagMap m_playList; //... Regards, Paul McKenzie |
|
#3
|
|||
|
|||
|
Re: Questions about right structure.
Thanks a lot for your response.
I'm using map iterators, instead of vector iterators. Do they still become invalid if I add or remove an Item for my database? And you're definelly right I should typedef a lot .so my design is this: a map (let's called it songs map) with string as key and a filetag structure as val. a second map (let's call it albums map) with string as key (the album name) and a vector of map iterators to the songs map as val. if I delete a song in the songs map first I should delete it referenced iterator from the vector on the albums map and if the size of the vector become zero (if this is the single songs that hase that album) delete also the pair(albumName,vector of iterator) from the albums map. Do the album map than become invalid? (I haven't tried yet deleting things only ading new songs). Last edited by SkyNetTo; October 10th, 2009 at 03:56 PM. |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|