25 #ifndef COMMON_PTRMAP_H 26 #define COMMON_PTRMAP_H 31 #include <boost/noncopyable.hpp> 41 template<
typename Key,
typename T,
class Compare = std::less<Key>,
class Deallocator = DeallocatorDefault>
42 class PtrMap : boost::noncopyable,
public std::map<Key, T *, Compare> {
49 for (
typename std::map<Key, T *, Compare>::iterator it = std::map<Key, T *, Compare>::begin();
50 it != std::map<Key, T *, Compare>::end(); ++it)
51 Deallocator::destroy(it->second);
53 std::map<Key, T *, Compare>::clear();
56 void erase(
typename std::map<Key, T *, Compare>::iterator position) {
57 Deallocator::destroy(position->second);
58 std::map<Key, T *, Compare>::erase(position);
61 typename std::map<Key, T *, Compare>::size_type
62 erase(
const typename std::map<Key, T *, Compare>::key_type &k) {
64 typename std::map<Key, T *, Compare>::iterator it(std::map<Key, T *, Compare>::find(k));
65 if (it == std::map<Key, T *, Compare>::end())
72 void erase(
typename std::map<Key, T *, Compare>::iterator first,
73 typename std::map<Key, T *, Compare>::iterator last) {
75 for (
typename std::map<Key, T *, Compare>::iterator it = std::map<Key, T *, Compare>::begin();
76 it != std::map<Key, T *, Compare>::end(); ++it)
77 Deallocator::destroy(it->second);
79 std::map<Key, T *, Compare>::erase(first, last);
85 #endif // COMMON_PTRMAP_H void erase(typename std::map< Key, T *, Compare >::iterator position)
void erase(typename std::map< Key, T *, Compare >::iterator first, typename std::map< Key, T *, Compare >::iterator last)
std::map< Key, T *, Compare >::size_type erase(const typename std::map< Key, T *, Compare >::key_type &k)
Simple deallocator concept.
A map of pointer to objects, with automatic deletion.