20#include <cereal/archives/binary.hpp>
21#include <cereal/types/map.hpp>
22#include <cereal/types/string.hpp>
23#include <cereal/types/vector.hpp>
62 template <
class Archive>
88 std::map<std::string, std::map<std::string, std::map<unsigned int, std::map<unsigned int, Song>>>> tree;
111 for (
const auto& artistPair : tree)
113 std::cout <<
"Artist: " << artistPair.first <<
"\n";
114 for (
const auto& albumPair : artistPair.second)
116 std::cout <<
" Album: " << albumPair.first <<
"\n";
117 for (
const auto& discPair : albumPair.second)
119 std::cout <<
" Disc: " << discPair.first <<
"\n";
120 for (
const auto& trackPair : discPair.second)
122 const auto& song = trackPair.second;
123 std::cout <<
" Track " << trackPair.first <<
": " << song.metadata.title
124 <<
" (Inode: " << song.inode <<
", Artist: " << song.metadata.artist
125 <<
", Album: " << song.metadata.album <<
", Genre: " << song.metadata.genre
143 std::vector<Song> result;
144 auto artistIt = tree.find(artist);
145 if (artistIt != tree.end())
147 for (
const auto& albumPair : artistIt->second)
149 for (
const auto& discPair : albumPair.second)
151 for (
const auto& trackPair : discPair.second)
153 result.push_back(trackPair.second);
170 std::vector<Song>
getSongsByAlbum(
const std::string& artist,
const std::string& album)
const
172 std::vector<Song> result;
173 auto artistIt = tree.find(artist);
174 if (artistIt != tree.end())
176 auto albumIt = artistIt->second.find(album);
177 if (albumIt != artistIt->second.end())
179 for (
const auto& discPair : albumIt->second)
181 for (
const auto& trackPair : discPair.second)
183 result.push_back(trackPair.second);
198 std::map<std::string, std::map<std::string, std::map<unsigned int, std::map<unsigned int, Song>>>>
returnSongMap()
210 template <
class Archive>
226 std::ofstream file(filename, std::ios::binary);
229 throw std::runtime_error(
"Failed to open file for saving.");
231 cereal::BinaryOutputArchive archive(file);
245 std::ifstream file(filename, std::ios::binary);
248 throw std::runtime_error(
"Failed to open file for loading.");
250 cereal::BinaryInputArchive archive(file);
Represents a hierarchical tree structure to store songs by artist, album, disc number,...
Definition songmap.hpp:78
void serialize(Archive &ar)
Serializes the SongTree object.
Definition songmap.hpp:211
void display() const
Displays all songs in the tree hierarchically.
Definition songmap.hpp:109
void addSong(const Song &song)
Adds a song to the tree.
Definition songmap.hpp:98
std::vector< Song > getSongsByArtist(const std::string &artist) const
Retrieves all songs by a specific artist.
Definition songmap.hpp:141
std::map< std::string, std::map< std::string, std::map< unsigned int, std::map< unsigned int, Song > > > > returnSongMap()
Returns the internal song map.
Definition songmap.hpp:198
void saveToFile(const std::string &filename) const
Saves the SongTree to a file.
Definition songmap.hpp:224
void loadFromFile(const std::string &filename)
Loads a SongTree from a file.
Definition songmap.hpp:243
std::vector< Song > getSongsByAlbum(const std::string &artist, const std::string &album) const
Retrieves all songs from a specific album by a given artist.
Definition songmap.hpp:170
Represents a song with associated metadata and inode.
Definition songmap.hpp:38
Song()
Default constructor for a Song, initializing with default values.
Definition songmap.hpp:53
unsigned int inode
Definition songmap.hpp:39
Metadata metadata
Definition songmap.hpp:40
void serialize(Archive &ar)
Serializes the Song object.
Definition songmap.hpp:63
Song(unsigned int inode, const Metadata &metadata)
Constructs a Song with the given inode and metadata.
Definition songmap.hpp:48
A header file for the TagLibParser class and Metadata structure, used to parse metadata from audio fi...