Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocmap.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_STLALLOC_ALLOCMAP_H_
19 #define ION_BASE_STLALLOC_ALLOCMAP_H_
20 
21 #include <map>
22 
23 #include "ion/base/allocatable.h"
26 
27 namespace ion {
28 namespace base {
29 
48 
49 template <typename K, typename V, typename Compare = std::less<K> >
50 class AllocMap : public std::map<K, V, Compare,
51  StlAllocator<std::pair<const K, V> > > {
52  public:
53  typedef std::pair<const K, V> PairType;
55  typedef std::map<K, V, Compare, AllocType> MapType;
56  explicit AllocMap(const AllocatorPtr& alloc)
57  : MapType(Compare(),
58  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
59  explicit AllocMap(const Allocatable& owner)
60  : MapType(Compare(), AllocType(owner.GetNonNullAllocator())) {}
61 
64  template <typename ContainerT>
65  AllocMap(const AllocatorPtr& alloc, const ContainerT& from)
66  : MapType(from.begin(), from.end(), Compare(),
67  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
68  template <typename ContainerT>
69  AllocMap(const Allocatable& owner, const ContainerT& from)
70  : MapType(from.begin(), from.end(), Compare(),
71  AllocType(owner.GetNonNullAllocator())) {}
72 
76  AllocMap(const AllocatorPtr& alloc, std::initializer_list<PairType> init)
77  : MapType(init, Compare(),
78  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
79  AllocMap(const Allocatable& owner, std::initializer_list<PairType> init)
80  : MapType(init, Compare(),
81  AllocType(owner.GetNonNullAllocator())) {}
82 };
83 
84 } // namespace base
85 } // namespace ion
86 
87 #endif // ION_BASE_STLALLOC_ALLOCMAP_H_
StlAllocator is derived std::allocator class that allows an Ion Allocator to be used for STL containe...
Definition: stlallocator.h:35
This class can be used in place of std::map to allow an Ion Allocator to be used for memory allocatio...
Definition: allocmap.h:50
std::pair< const K, V > PairType
Definition: allocmap.h:53
AllocationManager is a singleton class that is used to manage Allocators used to allocate Ion objects...
StlAllocator< PairType > AllocType
Definition: allocmap.h:54
AllocMap(const Allocatable &owner, std::initializer_list< PairType > init)
Definition: allocmap.h:79
AllocMap(const Allocatable &owner, const ContainerT &from)
Definition: allocmap.h:69
AllocMap(const AllocatorPtr &alloc, const ContainerT &from)
These constructors can be used to copy from "STL iterables": anything that provides a pair of compati...
Definition: allocmap.h:65
Allocatable is an abstract base class for classes whose memory is managed by an Allocator.
Definition: allocatable.h:60
AllocMap(const Allocatable &owner)
Definition: allocmap.h:59
AllocMap(const AllocatorPtr &alloc)
Definition: allocmap.h:56
std::map< K, V, Compare, AllocType > MapType
Definition: allocmap.h:55
AllocMap(const AllocatorPtr &alloc, std::initializer_list< PairType > init)
These constructors allow AllocMap to be initialized using c++11's list initialization: AllocMap<int...
Definition: allocmap.h:76