Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocvector.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_STLALLOC_ALLOCVECTOR_H_
19 #define ION_BASE_STLALLOC_ALLOCVECTOR_H_
20 
21 #include <vector>
22 
23 #include "ion/base/allocatable.h"
26 
27 namespace ion {
28 namespace base {
29 
48 
49 template <typename T>
50 class AllocVector : public std::vector<T, StlAllocator<T> > {
51  public:
53  typedef std::vector<T, AllocType> VectorType;
54  explicit AllocVector(const AllocatorPtr& alloc)
55  : VectorType(AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
56  explicit AllocVector(const Allocatable& owner)
57  : VectorType(AllocType(owner.GetNonNullAllocator())) {}
58 
59  AllocVector(const AllocatorPtr& alloc, size_t n, const T& val)
60  : VectorType(n, val,
61  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
62  AllocVector(const Allocatable& owner, size_t n, const T& val)
63  : VectorType(n, val, AllocType(owner.GetNonNullAllocator())) {}
64 
65  template <class IteratorT>
66  AllocVector(const AllocatorPtr& alloc, IteratorT first, IteratorT last)
67  : VectorType(first, last,
68  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
69  template <class IteratorT>
70  AllocVector(const Allocatable& owner, IteratorT first, IteratorT last)
71  : VectorType(first, last,
72  AllocType(owner.GetNonNullAllocator())) {}
73 
76  template <typename ContainerT>
77  AllocVector(const AllocatorPtr& alloc, const ContainerT& from)
78  : VectorType(from.begin(), from.end(),
79  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
80  template <typename ContainerT>
81  AllocVector(const Allocatable& owner, const ContainerT& from)
82  : VectorType(from.begin(), from.end(),
83  AllocType(owner.GetNonNullAllocator())) {}
84 
88  AllocVector(const AllocatorPtr& alloc, std::initializer_list<T> init)
89  : VectorType(init,
90  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
91  AllocVector(const Allocatable& owner, std::initializer_list<T> init)
92  : VectorType(init,
93  AllocType(owner.GetNonNullAllocator())) {}
94 };
95 
98 template <typename T, int N>
99 class InlinedAllocVector : public std::vector<T, StlInlinedAllocator<T, N> > {
100  public:
102  typedef std::vector<T, AllocType> VectorType;
103  explicit InlinedAllocVector(const AllocatorPtr& alloc)
104  : VectorType(AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
105  explicit InlinedAllocVector(const Allocatable& owner)
106  : VectorType(AllocType(owner.GetNonNullAllocator())) {}
107 
108  InlinedAllocVector(const AllocatorPtr& alloc, size_t n, const T& val)
109  : VectorType(n, val,
110  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
111  InlinedAllocVector(const Allocatable& owner, size_t n, const T& val)
112  : VectorType(n, val, AllocType(owner.GetNonNullAllocator())) {}
113 
114  template <class IteratorT>
115  InlinedAllocVector(const AllocatorPtr& alloc, IteratorT first, IteratorT last)
116  : VectorType(first, last,
117  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
118  template <class IteratorT>
119  InlinedAllocVector(const Allocatable& owner, IteratorT first, IteratorT last)
120  : VectorType(first, last,
121  AllocType(owner.GetNonNullAllocator())) {}
122 
125  template <typename ContainerT>
126  InlinedAllocVector(const AllocatorPtr& alloc, const ContainerT& from)
127  : VectorType(from.begin(), from.end(),
128  AllocType(AllocationManager::GetNonNullAllocator(alloc))) {}
129  template <typename ContainerT>
130  InlinedAllocVector(const Allocatable& owner, const ContainerT& from)
131  : VectorType(from.begin(), from.end(),
132  AllocType(owner.GetNonNullAllocator())) {}
133 };
134 
135 } // namespace base
136 } // namespace ion
137 
138 #endif // ION_BASE_STLALLOC_ALLOCVECTOR_H_
AllocVector(const Allocatable &owner, IteratorT first, IteratorT last)
Definition: allocvector.h:70
InlinedAllocVector(const AllocatorPtr &alloc)
Definition: allocvector.h:103
StlAllocator is derived std::allocator class that allows an Ion Allocator to be used for STL containe...
Definition: stlallocator.h:35
AllocVector(const AllocatorPtr &alloc, std::initializer_list< T > init)
These constructors allow AllocVector to be initialized using c++11's list initialization: AllocVector...
Definition: allocvector.h:88
InlinedAllocVector(const AllocatorPtr &alloc, size_t n, const T &val)
Definition: allocvector.h:108
InlinedAllocVector(const Allocatable &owner, const ContainerT &from)
Definition: allocvector.h:130
InlinedAllocVector(const AllocatorPtr &alloc, IteratorT first, IteratorT last)
Definition: allocvector.h:115
AllocationManager is a singleton class that is used to manage Allocators used to allocate Ion objects...
AllocVector(const Allocatable &owner, const ContainerT &from)
Definition: allocvector.h:81
std::vector< T, AllocType > VectorType
Definition: allocvector.h:53
InlinedAllocVector(const Allocatable &owner, IteratorT first, IteratorT last)
Definition: allocvector.h:119
StlInlinedAllocator is a derived StlAllocator class that uses inlined storage for its first N element...
Definition: stlallocator.h:157
Allocatable is an abstract base class for classes whose memory is managed by an Allocator.
Definition: allocatable.h:60
AllocVector(const Allocatable &owner, size_t n, const T &val)
Definition: allocvector.h:62
AllocVector(const AllocatorPtr &alloc)
Definition: allocvector.h:54
InlinedAllocVector(const Allocatable &owner)
Definition: allocvector.h:105
std::vector< T, AllocType > VectorType
Definition: allocvector.h:102
AllocVector(const Allocatable &owner)
Definition: allocvector.h:56
AllocVector(const AllocatorPtr &alloc, IteratorT first, IteratorT last)
Definition: allocvector.h:66
AllocVector(const AllocatorPtr &alloc, size_t n, const T &val)
Definition: allocvector.h:59
InlinedAllocVectoris a similar to AllocVector, but uses inlined storage for its first N elements...
Definition: allocvector.h:99
InlinedAllocVector(const AllocatorPtr &alloc, const ContainerT &from)
These constructors can be used to copy from "STL iterables": anything that provides a pair of compati...
Definition: allocvector.h:126
AllocVector(const Allocatable &owner, std::initializer_list< T > init)
Definition: allocvector.h:91
StlInlinedAllocator< T, N > AllocType
Definition: allocvector.h:101
StlAllocator< T > AllocType
Definition: allocvector.h:52
InlinedAllocVector(const Allocatable &owner, size_t n, const T &val)
Definition: allocvector.h:111
AllocVector(const AllocatorPtr &alloc, const ContainerT &from)
These constructors can be used to copy from "STL iterables": anything that provides a pair of compati...
Definition: allocvector.h:77
This class can be used in place of std::vector to allow an Ion Allocator to be used for memory alloca...
Definition: allocvector.h:50