File indexing completed on 2025-01-18 10:04:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _NCollection_OccAllocator_HeaderFile
0015 #define _NCollection_OccAllocator_HeaderFile
0016
0017 #include <NCollection_BaseAllocator.hxx>
0018 #include <Standard.hxx>
0019
0020 #include <memory>
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 template <typename ItemType>
0036 class NCollection_OccAllocator
0037 {
0038 public:
0039
0040 typedef ItemType value_type;
0041 typedef value_type* pointer;
0042 typedef const value_type* const_pointer;
0043 typedef value_type& reference;
0044 typedef const value_type& const_reference;
0045 typedef size_t size_type;
0046 typedef ptrdiff_t difference_type;
0047 typedef std::false_type propagate_on_container_move_assignment;
0048
0049 template <typename OtherType>
0050 struct rebind
0051 {
0052 typedef NCollection_OccAllocator<OtherType> other;
0053 };
0054
0055
0056
0057
0058 NCollection_OccAllocator() :
0059 myAllocator(nullptr)
0060 {}
0061
0062
0063 NCollection_OccAllocator(const Handle(NCollection_BaseAllocator)& theAlloc) :
0064 myAllocator(theAlloc)
0065 {}
0066
0067
0068 NCollection_OccAllocator(Handle(NCollection_BaseAllocator)&& theAlloc) :
0069 myAllocator(theAlloc)
0070 {}
0071
0072
0073 NCollection_OccAllocator(const NCollection_OccAllocator& theOther) :
0074 myAllocator(theOther.myAllocator)
0075 {}
0076
0077
0078 NCollection_OccAllocator(NCollection_OccAllocator&& theOther) noexcept :
0079 myAllocator(theOther.myAllocator)
0080 {}
0081
0082
0083 NCollection_OccAllocator& operator=(const NCollection_OccAllocator& theOther)
0084 {
0085 myAllocator = theOther.myAllocator;
0086 return *this;
0087 }
0088
0089
0090 NCollection_OccAllocator& operator=(NCollection_OccAllocator&& theOther) noexcept
0091 {
0092 myAllocator = theOther.myAllocator;
0093 return *this;
0094 }
0095
0096
0097 template <typename OtherType>
0098 NCollection_OccAllocator& operator=(const NCollection_OccAllocator<OtherType>& theOther)
0099 {
0100 myAllocator = theOther.myAllocator;
0101 return *this;
0102 }
0103
0104
0105
0106
0107 template <typename OtherType>
0108 NCollection_OccAllocator(const NCollection_OccAllocator<OtherType>& theOther) :
0109 myAllocator(theOther.Allocator())
0110 {}
0111
0112 void SetAllocator(const Handle(NCollection_BaseAllocator)& theAlloc)
0113 {
0114 myAllocator = theAlloc;
0115 }
0116
0117 const Handle(NCollection_BaseAllocator)& Allocator() const
0118 {
0119 return myAllocator;
0120 }
0121
0122
0123 pointer allocate(size_type theSize, const void* = 0)
0124 {
0125 return static_cast<pointer> (myAllocator.IsNull() ?
0126 Standard::AllocateOptimal(theSize * sizeof(ItemType)) :
0127 myAllocator->AllocateOptimal(theSize * sizeof(ItemType)));
0128 }
0129
0130
0131
0132 template <typename T>
0133 void deallocate(T* thePnt, size_type)
0134 {
0135 myAllocator.IsNull() ?
0136 Standard::Free(thePnt) :
0137 myAllocator->Free(thePnt);
0138 }
0139
0140
0141 void deallocate(pointer thePnt, size_type)
0142 {
0143 myAllocator.IsNull() ?
0144 Standard::Free(thePnt) :
0145 myAllocator->Free(thePnt);
0146 }
0147
0148
0149
0150 template<class _Objty, class... _Types>
0151 void construct(_Objty* _Ptr, _Types&&... _Args)
0152 {
0153 ::new ((void*)_Ptr) _Objty(std::forward<_Types>(_Args)...);
0154 }
0155
0156
0157 pointer address(reference theItem) const
0158 {
0159 return &theItem;
0160 }
0161
0162
0163 const_pointer address(const_reference theItem) const
0164 {
0165 return &theItem;
0166 }
0167
0168
0169
0170 template<class _Uty>
0171 void destroy(_Uty* _Ptr)
0172 {
0173 (void)_Ptr; _Ptr->~_Uty();
0174 }
0175
0176
0177 size_t max_size() const noexcept
0178 {
0179 return ((size_t)(-1) / sizeof(ItemType));
0180 }
0181
0182 bool operator==(const NCollection_OccAllocator& theOther) const
0183 {
0184 return theOther.Allocator() == myAllocator;
0185 }
0186
0187 template<class U>
0188 bool operator==(const NCollection_OccAllocator<U>& theOther) const
0189 {
0190 return theOther.Allocator() == myAllocator;
0191 }
0192
0193 bool operator!=(const NCollection_OccAllocator& theOther) const
0194 {
0195 return theOther.Allocator() != myAllocator;
0196 }
0197
0198 template<class U>
0199 bool operator!=(const NCollection_OccAllocator<U>& theOther) const
0200 {
0201 return theOther.Allocator() != myAllocator;
0202 }
0203
0204 private:
0205
0206 Handle(NCollection_BaseAllocator) myAllocator;
0207 };
0208
0209 template<class U, class V>
0210 bool operator==(const NCollection_OccAllocator<U>& theFirst, const NCollection_OccAllocator<V>& theSecond)
0211 {
0212 return theFirst.Allocator() == theSecond.Allocator();
0213 }
0214
0215 #endif