Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- repository.h
- class RepoInterface
- {
- public:
- class IteratorInterface
- {
- public:
- virtual Tower& operator*() const = 0;
- virtual bool operator!=(const IteratorInterface) const = 0;
- virtual bool valid() const = 0;
- virtual IteratorInterface& operator=(const IteratorInterface& it) = 0;
- virtual IteratorInterface& operator++() = 0;
- virtual IteratorInterface& operator++(int) = 0;
- };
- virtual int add(const std::vector<std::string>& params) = 0;
- virtual int remove(const std::vector<std::string>& params) = 0;
- virtual int update(const std::vector<std::string>& params) = 0;
- virtual int save(const std::vector<std::string>& params) = 0;
- virtual int size() = 0;
- virtual typename IteratorInterface& begin() = 0;
- virtual typename IteratorInterface& end() = 0;
- virtual ~RepoInterface() {}
- };
- RepoInMemory.h:
- #include "repository.h"
- class RepoInMemory: public RepoInterface
- {
- private:
- std::vector<Tower> elements;
- public:
- class iterator : public RepoInterface::IteratorInterface
- {
- private:
- std::vector<Tower>::iterator ptr;
- RepoInMemory& repo;
- public:
- iterator(std::vector<Tower>::iterator ptr, RepoInMemory& container) : ptr{ ptr }, repo{ container }{}
- Tower& operator*() const override;
- bool operator!=(const iterator& it) const override;
- bool valid() const override;
- iterator& operator=(const iterator& it) override;
- iterator& operator++() override;
- iterator& operator++(int) override;
- };
- RepoInMemory() : elements{ std::vector<Tower>() } {}
- int add(const std::vector<std::string>& params) override;
- int remove(const std::vector<std::string>& params) override;
- int update(const std::vector<std::string>& params) override;
- int save(const std::vector<std::string>& params) override;
- int size() override;
- typename iterator& begin() override;
- typename iterator& end() override;
- ~RepoInMemory() {};
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement