Filipbg

Task 04 - Resources

Dec 22nd, 2019
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef RESOURCE_H
  2. #define RESOURCE_H
  3.  
  4. #include <ostream>
  5. #include <string>
  6. #include <sstream>
  7. #include "ResourceType.h"
  8. using namespace std;
  9.  
  10. namespace SoftUni
  11. {
  12.   class Resource
  13.   {
  14.   private:
  15.  
  16.     int id{ };
  17.     ResourceType type{ };
  18.     string link;
  19.   public:
  20.  
  21.     Resource() = default;
  22.  
  23.     ResourceType getType() const
  24.     {
  25.       return this->type;
  26.     }
  27.  
  28.     bool operator<(const Resource& other) const
  29.     {
  30.       return this->id < other.id;
  31.     }
  32.  
  33.     friend ostream& operator<<(ostream& outStream, const Resource& resource);
  34.     friend istream& operator>>(istream& inStream, Resource& resource);
  35.   };
  36.  
  37.   ostream& operator<<(ostream& outStream, const Resource& resource)
  38.   {
  39.       return outStream << resource.id << " " << resource.type << " " << resource.link;
  40.   }
  41.  
  42.   istream& operator>>(istream& inStream, ResourceType& resourceType)
  43.   {
  44.     string type;
  45.     inStream >> type;
  46.     if(type == "Presentation")
  47.       resourceType = ResourceType::PRESENTATION;
  48.     else if(type == "Demo")
  49.       resourceType = ResourceType::DEMO;
  50.     else if(type == "Video")
  51.       resourceType = ResourceType::VIDEO;
  52.  
  53.     return inStream;
  54.   }
  55.  
  56.   istream& operator>>(istream& inStream, Resource& resource)
  57.   {
  58.       return inStream >> resource.id >> resource.type >> resource.link;
  59.   }
  60.  
  61. }
  62. #endif // !RESOURCE_H
RAW Paste Data