Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <tuple>
- #include <utility>
- #include <unordered_map>
- typedef std::tuple<std::string,int> key_t;
- struct key_hash : public std::unary_function<key_t, std::size_t>
- {
- std::size_t operator()(const key_t& k) const
- {
- return std::get<0>(k)[0] ^ std::get<1>(k);
- }
- };
- struct key_equal : public std::binary_function<key_t, key_t, bool>
- {
- bool operator()(const key_t& v0, const key_t& v1) const
- {
- return (
- std::get<0>(v0) == std::get<0>(v1) &&
- std::get<1>(v0) == std::get<1>(v1)
- );
- }
- };
- class playervars {
- private:
- typedef std::unordered_map<key_t,int,key_hash,key_equal> variable_i;
- variable_i vari;
- int numero;
- public:
- void SetInt(int playerid, std::string nomevar,int valor) {
- vari[std::make_tuple(nomevar,playerid)] = valor;
- }
- int GetInt(int playerid, std::string nomevar) {
- auto itr = vari.find(std::make_tuple(nomevar,playerid));
- if (vari.end() != itr)
- {
- return itr->second;
- }
- }
- };
- playervars PVar;
- int main()
- {
- PVar.SetInt(5,"carro",10);
- std::cout << PVar.GetInt(5,"carro") << std::endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement