|
BDE 4.39.x Production Release
|
Provide a polymorphic adaptor for STL-style allocators.
Provide a polymorphic adaptor for STL-style allocators
Within the BDE libraries, the prefered way to handle memory allocation is through a pointer to the polymorphic base class, bslma::Allocator. The use of a run-time polymorphism for the allocator has numerous advantages over the compile-time polymorphism used by the STL components. However, there are times when client code may have an STL-style allocator available and needs to use it with a BDE component.
This component provides a class template, AllocatorAdaptor that wraps the STL-style allocator in an object of class derived from bslma::Allocator. A pointer to the object can thus be used with any component that uses BDE-style memory allocation.
This section illustrates intended use of this component.
Let's start with a simple class, my::FilePath, which allocates storage using a bslma::Allocator:
Next, assume that an STL-allocator exists that uses memory exactly the way you need:
Now, if we want to create a FilePath using a MagicAllocator, we need to adapt the MagicAllocator to the bslma::Allocator protocol. This is where bslma::AllocatorAdaptor comes in:
| STL_ALLOC bslma::AllocatorAdaptor_Imp< STL_ALLOC >::adaptedAllocator | ( | ) | const |
Return a copy of the STL allocator stored within this object.
|
virtual |
Return a maximally-aligned block of memory no smaller than size bytes allocated from the STL-style allocator that was supplied to this object's constructor. Any exceptions thrown by the underlying STL-style allocator are propagated out from this member.
Implements bslma::Allocator.
|
inline |
Constructs a polymorphic wrapper around a default-constructed STL-style allocator.
|
inline |
Constructs a polymorphic wrapper around a copy of the specified 'stla' STL-style allocator.
|
inline |
Construct a polymorphic wrapper around a default-constructed STL-style allocator.
|
inline |
Construct a polymorphic wrapper around a copy of the specified stla STL-style allocator.
|
virtual |
Return the memory block at the specified address back to the STL-allocator. If address is null, this funciton has no effect.
address was allocated using this allocator object and has not already been deallocated. Implements bslma::Allocator.
|
inline |
Destroy this object and the STL-style allocator that it wraps.