2015-02-15 18:53:04 +03:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2005-2009 Anchorite (TeamX), <anchorite2001@yandex.ru>
|
2015-02-15 21:33:27 +03:00
|
|
|
* Copyright (c) 2014-2015 Nirran, phobos2077
|
|
|
|
|
* Copyright (c) 2015 alexeevdv <mail@alexeevdv.ru>
|
2015-02-15 18:53:04 +03:00
|
|
|
* Distributed under the GNU GPL v3. For full terms see the file license.txt
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2015-02-13 16:59:11 +03:00
|
|
|
#ifndef CMAP_H
|
|
|
|
|
#define CMAP_H
|
|
|
|
|
|
2015-02-15 16:31:38 +03:00
|
|
|
// C++ standard includes
|
2015-02-13 16:59:11 +03:00
|
|
|
#include <map>
|
2015-02-16 00:30:55 +03:00
|
|
|
#include <stdint.h>
|
2015-02-15 16:31:38 +03:00
|
|
|
|
|
|
|
|
// int2ssl includes
|
2015-02-13 16:59:11 +03:00
|
|
|
|
2015-02-15 16:31:38 +03:00
|
|
|
// Third party includes
|
|
|
|
|
|
2015-02-13 16:59:11 +03:00
|
|
|
template<typename A, typename B, typename C,typename D>
|
|
|
|
|
class CMap
|
|
|
|
|
{
|
|
|
|
|
std::map<A, C> _map;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CMap()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 18:28:27 +03:00
|
|
|
uint32_t GetSize() const
|
2015-02-13 16:59:11 +03:00
|
|
|
{
|
|
|
|
|
return _map.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoveAll()
|
|
|
|
|
{
|
|
|
|
|
_map.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 18:28:27 +03:00
|
|
|
void SetAt(uint32_t offset, C value)
|
2015-02-13 16:59:11 +03:00
|
|
|
{
|
|
|
|
|
if (_map.find(offset) != _map.end())
|
|
|
|
|
{
|
2019-05-14 08:57:59 +08:00
|
|
|
_map.at(offset) = value;
|
2015-02-13 16:59:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_map.insert(std::pair<A, C>(offset, value));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 18:28:27 +03:00
|
|
|
bool Lookup(uint32_t offset, C& value) const
|
2015-02-13 16:59:11 +03:00
|
|
|
{
|
2015-02-15 22:27:31 +03:00
|
|
|
if (_map.find(offset) != _map.end())
|
2015-02-13 16:59:11 +03:00
|
|
|
{
|
2015-02-15 22:27:31 +03:00
|
|
|
value = _map.find(offset)->second;
|
2015-02-13 16:59:11 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // CMAP_H
|