Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include "ResourceType.h"
  2. #include <string>
  3. #include <istream>
  4. #include <ostream>
  5.  
  6. using namespace std;
  7.  
  8. namespace SoftUni{
  9. class Resource
  10. {
  11. private:
  12.     int id;
  13.     ResourceType type;
  14.     string link;
  15.  
  16. public:
  17.     Resource() {}
  18.  
  19.     Resource(int id, ResourceType type, std::string link)
  20.             : id(id)
  21.             , type(type)
  22.             , link(link) {}
  23.  
  24.     int getId() const
  25.     {
  26.         return this->id;
  27.     }
  28.     ResourceType getType() const
  29.     {
  30.         return this->type;
  31.     }
  32.     string getLink() const
  33.     {
  34.         return this->link;
  35.     }
  36.  
  37.     bool operator<(const Resource& other) const
  38.     {
  39.         return this->id < other.id;
  40.     }
  41. };
  42.  
  43. /*ostream& operator<<(ostream& out, const Resource& r)
  44. {
  45.     return out << r.getId() <<" "<< r.getType() <" "<< r.getLink();
  46. }*/
  47.  
  48. ostream& operator<<(ostream& out, const Resource& r) {
  49.         return out << r.getId() << " " << r.getType() << " " << r.getLink();
  50. }
  51.  
  52. istream& operator>>(istream& in, Resource& r)
  53. {
  54.     int id;
  55.     string typeString;
  56.     string link;
  57.  
  58.     in >> id >> typeString >> link;
  59.  
  60.     ResourceType type;
  61.     if (typeString == "Presentation") {
  62.         type = ResourceType::PRESENTATION;
  63.     }
  64.     else if (typeString == "Demo") {
  65.         type = ResourceType::DEMO;
  66.     }
  67.     else if (typeString == "Video") {
  68.         type = ResourceType::VIDEO;
  69.     }
  70.  
  71.     r = Resource(id, type, link);
  72.  
  73.     return in;
  74. }
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement