Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #ifndef ENTRY_H
  2. #define ENTRY_H
  3. #include <iostream>
  4. #include <stdexcept>
  5. #include <limits>
  6.  
  7.  
  8. class entry
  9. {
  10.     public:
  11.         entry (const std::string& in_val) { val = in_val; cnt = 0; }
  12.  
  13.         std::string operator*() const { return val; }
  14.  
  15.         operator int() const { return cnt; }
  16.  
  17.         int operator++ (int)
  18.         {
  19.             if (cnt == INT_MAX)
  20.                 throw std::invalid_argument("Reached maximum cnt");
  21.             else
  22.                 return cnt++;
  23.         }
  24.  
  25.         bool operator< (const entry& et) { return (val < et.val); }
  26.  
  27.         friend std::ostream& operator <<(std::ostream& os, const entry& et) { os << "[" << et.val << " " << et.cnt << "]"; return os; }
  28.  
  29.         friend std::istream& operator >>(std::istream& is, entry& et)
  30.         {
  31.             char //musi czytać nawias
  32.             is >> //nawias
  33.             if (/*nawias*/ != '[')
  34.                 throw std::invalid_argument();
  35.             is >> et.val >> et.cnt;
  36.             is >> parenthesis;
  37.             if (/*nawias*/ != ']')
  38.                 throw std::invalid_argument();
  39.  
  40.             return is;
  41.         }
  42.  
  43.     private:
  44.         std::string val;
  45.         int cnt;
  46. };
  47.  
  48. #endif // ENTRY_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement