Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocunorderedmap.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_STLALLOC_ALLOCUNORDEREDMAP_H_
19 #define ION_BASE_STLALLOC_ALLOCUNORDEREDMAP_H_
20 
21 #include <unordered_map>
22 
23 #include "ion/base/allocatable.h"
26 
27 namespace ion {
28 namespace base {
29 
48 
49 template <typename Key,
50  typename Value,
51  typename Hash = ::std::hash<Key>,
52  typename Pred = ::std::equal_to<Key> >
53 class AllocUnorderedMap : public std::unordered_map<
54  Key, Value, Hash, Pred, StlAllocator<std::pair<const Key, Value> > > {
55  public:
56  typedef std::pair<const Key, Value> PairType;
58  typedef std::unordered_map<Key, Value, Hash, Pred, AllocType> MapType;
59 
60  explicit AllocUnorderedMap(const AllocatorPtr& alloc)
61  : MapType(kBucketCountHint, Hash(), Pred(),
62  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
63  explicit AllocUnorderedMap(const Allocatable& owner)
64  : MapType(kBucketCountHint, Hash(), Pred(),
65  AllocType(owner.GetNonNullAllocator())) {}
66 
69  template <typename ContainerT>
70  AllocUnorderedMap(const AllocatorPtr& alloc, const ContainerT& from)
71  : MapType(from.begin(), from.end(), kBucketCountHint, Hash(), Pred(),
72  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
73  template <typename ContainerT>
74  AllocUnorderedMap(const Allocatable& owner, const ContainerT& from)
75  : MapType(from.begin(), from.end(), kBucketCountHint, Hash(), Pred(),
76  AllocType(owner.GetNonNullAllocator())) {}
77 
78  private:
82  enum { kBucketCountHint = 10 };
83 };
84 
85 } // namespace base
86 } // namespace ion
87 
88 #endif // ION_BASE_STLALLOC_ALLOCUNORDEREDMAP_H_
StlAllocator is derived std::allocator class that allows an Ion Allocator to be used for STL containe...
Definition: stlallocator.h:35
std::unordered_map< Key, Value, Hash, Pred, AllocType > MapType
This class can be used in place of std::unordered_map to allow an Ion Allocator to be used for memory...
StlAllocator< PairType > AllocType
AllocUnorderedMap(const AllocatorPtr &alloc)
AllocationManager is a singleton class that is used to manage Allocators used to allocate Ion objects...
AllocUnorderedMap(const Allocatable &owner, const ContainerT &from)
Allocatable is an abstract base class for classes whose memory is managed by an Allocator.
Definition: allocatable.h:60
AllocUnorderedMap(const AllocatorPtr &alloc, const ContainerT &from)
These constructors can be used to copy from "STL iterables": anything that provides a pair of compati...
AllocUnorderedMap(const Allocatable &owner)
std::pair< const Key, Value > PairType