Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "AlbumCollection.h"
- #include "Album.h"
- #include "Track.h"
- #include <iostream>
- #include <fstream>
- #include <sstream>
- AlbumCollection::AlbumCollection() : albums (*new vector<Album>)
- {
- }
- AlbumCollection::AlbumCollection(vector<Album> a) : albums (*new vector<Album>)
- {
- albums = a;
- }
- Album AlbumCollection::getAlbum(int i)
- {
- return albums[i];
- }
- void AlbumCollection::addAlbum(Album a)
- {
- albums.push_back(a);
- }
- vector<Album>& AlbumCollection::getAlbumList()
- {
- return albums;
- }
- Album& AlbumCollection::getAlbum(string title)
- {
- for(vector<Album>::iterator it = albums.begin(); it != albums.end(); it++){
- Album& a = *it;
- if (a.getTitle().compare(title) == 0){
- return a;
- }
- }
- }
- istream& operator>>(istream& is, AlbumCollection& albumCollection)
- {
- string str;
- getline(is, str);
- if (str.find(": ") != -1)
- {
- Album a;
- stringstream strStream(str);
- strStream >> a;
- albumCollection.addAlbum(a);
- }
- if (str.find("-") != -1)
- {
- Track t;
- stringstream strStream(str);
- strStream >> t;
- albumCollection.getAlbumList().back().addTrack(t);
- }
- return is;
- }
- ifstream& operator>>(ifstream& ifs, AlbumCollection& albumCollection)
- {
- if (ifs.is_open()){
- while (ifs.good()){
- string str;
- getline(ifs, str);
- stringstream strStream(str);
- strStream >> albumCollection;
- }
- }
- return ifs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement