SHARE
TWEET

Untitled

a guest Jan 27th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. template<class TKey, class TValue>
  4. class Dictionary
  5. {
  6. public:
  7.     virtual ~Dictionary() = default;
  8.  
  9.     virtual const TValue& Get(const TKey& key) const = 0;
  10.     virtual void Set(const TKey& key, const TValue& value) = 0;
  11.     virtual bool IsSet(const TKey& key) const = 0;
  12. };
  13.  
  14. template<class TKey>
  15. class NotFoundException : public std::exception
  16. {
  17. public:
  18.     virtual const TKey& GetKey() const noexcept = 0;
  19. };
  20.  
  21. template<class TKey>
  22. class ImplNotFoundException : public NotFoundException<TKey> {
  23. private:
  24.     const TKey key;
  25. public:
  26.     explicit ImplNotFoundException(const TKey &key): key(key) {}
  27.  
  28.     const TKey& GetKey() const noexcept override {
  29.         return key;
  30.     }
  31. };
  32.  
  33. template <class TKey, class TValue>
  34. class ImplDictionary : public Dictionary<TKey, TValue> {
  35. private:
  36.     std::map<TKey, TValue> dict;
  37. public:
  38.     ImplDictionary() = default;
  39.  
  40.     ~ImplDictionary() override {
  41.         dict.clear();
  42.     }
  43.  
  44.     const TValue& Get(const TKey& key) const override{
  45.         if (IsSet(key)) {
  46.             return dict.at(key);
  47.         } else {
  48.             throw(ImplNotFoundException<TKey>(key));
  49.         }
  50.     }
  51.  
  52.     void Set(const TKey& key, const TValue& value) override {
  53.         dict[key] = value;
  54.     }
  55.  
  56.     bool IsSet(const TKey& key) const override {
  57.         return dict.find(key) != dict.end();
  58.     }
  59. };
  60.  
  61. void TrimRight(char *s) {
  62.     char *end = s, *cur = s;
  63.  
  64.     while (cur++) {
  65.         if (*cur != ' ') {
  66.             if (*cur == 0) {
  67.                 break;
  68.             } else {
  69.                 end = cur;
  70.             }
  71.         }
  72.     }
  73.  
  74.     if (*end == ' ' || *end == 0) {
  75.         *end = 0;
  76.     } else {
  77.         *(end + 1) = 0;
  78.     }
  79. }
  80.  
  81. int main() {
  82.     return 0;
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top