Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. repository.h
  2.  
  3. class RepoInterface
  4. {
  5. public:
  6.     class IteratorInterface
  7.     {
  8.     public:
  9.         virtual Tower& operator*() const = 0;
  10.         virtual bool operator!=(const IteratorInterface) const = 0;
  11.         virtual bool valid() const = 0;
  12.         virtual IteratorInterface& operator=(const IteratorInterface& it) = 0;
  13.         virtual IteratorInterface& operator++() = 0;
  14.         virtual IteratorInterface& operator++(int) = 0;
  15.     };
  16.  
  17.     virtual int add(const std::vector<std::string>& params) = 0;
  18.     virtual int remove(const std::vector<std::string>& params) = 0;
  19.     virtual int update(const std::vector<std::string>& params) = 0;
  20.     virtual int save(const std::vector<std::string>& params) = 0;
  21.     virtual int size() = 0;
  22.     virtual typename IteratorInterface& begin() = 0;
  23.     virtual typename IteratorInterface& end() = 0;
  24.     virtual ~RepoInterface() {}
  25. };
  26.  
  27. RepoInMemory.h:
  28.  
  29. #include "repository.h"
  30.  
  31. class RepoInMemory: public RepoInterface
  32. {
  33. private:
  34.     std::vector<Tower> elements;
  35. public:
  36.     class iterator : public RepoInterface::IteratorInterface
  37.     {
  38.     private:
  39.         std::vector<Tower>::iterator ptr;
  40.         RepoInMemory& repo;
  41.     public:
  42.         iterator(std::vector<Tower>::iterator ptr, RepoInMemory& container) : ptr{ ptr }, repo{ container }{}
  43.         Tower& operator*() const override;
  44.         bool operator!=(const iterator& it) const override;
  45.         bool valid() const override;
  46.         iterator& operator=(const iterator& it) override;
  47.         iterator& operator++() override;
  48.         iterator& operator++(int) override;
  49.     };
  50.  
  51.     RepoInMemory() : elements{ std::vector<Tower>() } {}
  52.     int add(const std::vector<std::string>& params) override;
  53.     int remove(const std::vector<std::string>& params) override;
  54.     int update(const std::vector<std::string>& params) override;
  55.     int save(const std::vector<std::string>& params) override;
  56.     int size() override;
  57.     typename iterator& begin() override;
  58.     typename iterator& end() override;
  59.     ~RepoInMemory() {};
  60. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement