Advertisement
Guest User

Untitled

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