Advertisement
Guest User

Untitled

a guest
Dec 10th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include "AlbumCollection.h"
  2. #include "Album.h"
  3. #include "Track.h"
  4. #include <iostream>
  5. #include <fstream>
  6. #include <sstream>
  7.  
  8. AlbumCollection::AlbumCollection() : albums (*new vector<Album>)
  9. {
  10. }
  11.  
  12. AlbumCollection::AlbumCollection(vector<Album> a) : albums (*new vector<Album>)
  13. {
  14.     albums = a;
  15. }
  16.  
  17. Album AlbumCollection::getAlbum(int i)
  18. {
  19.     return albums[i];
  20. }
  21.  
  22. void AlbumCollection::addAlbum(Album a)
  23. {
  24.     albums.push_back(a);
  25. }
  26.  
  27. vector<Album>& AlbumCollection::getAlbumList()
  28. {
  29.     return albums;
  30. }
  31.  
  32. Album& AlbumCollection::getAlbum(string title)
  33. {
  34.     for(vector<Album>::iterator it = albums.begin(); it != albums.end(); it++){
  35.         Album& a = *it;
  36.         if (a.getTitle().compare(title) == 0){
  37.             return a;
  38.         }
  39.     }
  40. }
  41.  
  42. istream& operator>>(istream& is, AlbumCollection& albumCollection)
  43. {
  44.     string str;
  45.     getline(is, str);
  46.  
  47.     if (str.find(": ") != -1)
  48.     {
  49.         Album a;
  50.         stringstream strStream(str);
  51.         strStream >> a;
  52.         albumCollection.addAlbum(a);
  53.     }
  54.     if (str.find("-") != -1)
  55.     {
  56.         Track t;
  57.         stringstream strStream(str);
  58.         strStream >> t;
  59.         albumCollection.getAlbumList().back().addTrack(t);
  60.     }
  61.  
  62.  
  63.     return is;
  64. }
  65.  
  66. ifstream& operator>>(ifstream& ifs, AlbumCollection& albumCollection)
  67. {
  68.     if (ifs.is_open()){
  69.         while (ifs.good()){
  70.             string str;
  71.             getline(ifs, str);
  72.             stringstream strStream(str);
  73.             strStream >> albumCollection;
  74.         }
  75.     }
  76.  
  77.     return ifs;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement