Advertisement
obernardovieira

SaveVars(integer,char,integer) map

Sep 28th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <ostream>
  4. #include <tuple>
  5.  
  6. class playervars {
  7. private:
  8.     typedef std::tuple<char,int> key_t;
  9.     typedef std::map<key_t, int> m_i;
  10.     m_i m;
  11. public:
  12.     void SetInt(int playerid, char letter, int valor) {
  13.         m[std::make_tuple(letter,playerid)] = valor;
  14.     }
  15.     int GetInt(int playerid, char letter) {
  16.         auto itr = m.find(std::make_tuple(letter,playerid));
  17.         if (m.end() != itr)
  18.         {
  19.             return itr->second;
  20.         }
  21.         return -1;
  22.     }
  23.     bool Delete(int playerid, char letter) {
  24.         auto itr = m.find(std::make_tuple(letter,playerid));
  25.         if (m.end() != itr)
  26.         {
  27.             m.erase(std::make_tuple(letter,playerid));
  28.             return true;
  29.         }
  30.         return false;
  31.     }
  32. };
  33.  
  34. playervars PVar;
  35.  
  36. int main() {
  37.     PVar.SetInt(5,'l',10);
  38.  
  39.     std::cout << PVar.GetInt(5,'l') << std::endl;
  40.  
  41.     system("pause");
  42.     return 1;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement