Quick Links:

bal | bbl | bdl | bsl

Classes | Public Types | Public Member Functions

bslma::StdTestAllocator< TYPE > Class Template Reference

#include <bslma_stdtestallocator.h>

List of all members.

Classes

struct  rebind

Public Types

typedef std::size_t size_type
typedef std::ptrdiff_t difference_type
typedef TYPE * pointer
typedef const TYPE * const_pointer
typedef bsl::conditional
< bsl::is_void< TYPE >::value,
void, TYPE & >::type 
reference
typedef bsl::conditional
< bsl::is_void< TYPE >::value,
void, const TYPE & >::type 
const_reference
typedef TYPE value_type

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (StdTestAllocator, bsl::is_trivially_copyable)
 BSLMF_NESTED_TRAIT_DECLARATION (StdTestAllocator, bslmf::IsBitwiseMoveable)
 BSLMF_NESTED_TRAIT_DECLARATION (StdTestAllocator, bslmf::IsBitwiseEqualityComparable)
 StdTestAllocator ()
 StdTestAllocator (Allocator *mechanism)
 StdTestAllocator (const StdTestAllocator &original)
template<class ANY_TYPE >
 StdTestAllocator (const StdTestAllocator< ANY_TYPE > &rhs)
 ~StdTestAllocator ()
StdTestAllocatoroperator= (const StdTestAllocator &rhs)
pointer allocate (size_type n, const void *hint=0)
void deallocate (pointer p, size_type n=1)
template<class ELEMENT_TYPE >
void construct (ELEMENT_TYPE *address, const TYPE &val)
template<class ELEMENT_TYPE >
void destroy (ELEMENT_TYPE *address)
pointer address (reference x) const
const_pointer address (const_reference x) const
size_type max_size () const
TestAllocatormechanism () const

Detailed Description

template<class TYPE>
class bslma::StdTestAllocator< TYPE >

An STL-compatible test allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::TestAllocator. This class template adheres to the allocator requirements defined in section 20.1.5 [lib.allocator.requirements] of the C++ standard and may be used to instantiate any [container] class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.

See Component bslma_stdtestallocator


Member Typedef Documentation

template<class TYPE>
typedef std::size_t bslma::StdTestAllocator< TYPE >::size_type
template<class TYPE>
typedef std::ptrdiff_t bslma::StdTestAllocator< TYPE >::difference_type
template<class TYPE>
typedef TYPE* bslma::StdTestAllocator< TYPE >::pointer
template<class TYPE>
typedef const TYPE* bslma::StdTestAllocator< TYPE >::const_pointer
template<class TYPE>
typedef bsl::conditional<bsl::is_void<TYPE>::value, void, TYPE&>::type bslma::StdTestAllocator< TYPE >::reference
template<class TYPE>
typedef bsl::conditional<bsl::is_void<TYPE>::value, void, const TYPE&>::type bslma::StdTestAllocator< TYPE >::const_reference
template<class TYPE>
typedef TYPE bslma::StdTestAllocator< TYPE >::value_type

Constructor & Destructor Documentation

template<class TYPE>
bslma::StdTestAllocator< TYPE >::StdTestAllocator (  ) 

TBD: fix comment to mention that the default allocator has to be a test allocator. Create a proxy object which will forward allocation calls to the object pointed to by bslma::Default::defaultAllocator(). Postcondition:

template<class TYPE>
bslma::StdTestAllocator< TYPE >::StdTestAllocator ( Allocator mechanism  ) 

IMPLICIT: TBD: fix comment to mention that mechanism has to be a test allocator. Convert a bslma::Allocator pointer to an test allocator object which forwards allocation calls to the object pointed to by the specified mechanism. If mechanism is 0, then the currently installed default allocator is used instead. Postcondition: 0 == mechanism || this->mechanism() == mechanism.

template<class TYPE>
bslma::StdTestAllocator< TYPE >::StdTestAllocator ( const StdTestAllocator< TYPE > &  original  ) 

Create a proxy object using the same mechanism as the specified original. Postcondition: this->mechanism() == rhs.mechanism().

template<class TYPE>
template<class ANY_TYPE >
bslma::StdTestAllocator< TYPE >::StdTestAllocator ( const StdTestAllocator< ANY_TYPE > &  rhs  ) 

Create a proxy object sharing the same mechanism object as the specified rhs. The newly constructed test allocator will compare equal to rhs, even though they are instantiated on different types. Postcondition: this->mechanism() == rhs.mechanism().

template<class TYPE>
bslma::StdTestAllocator< TYPE >::~StdTestAllocator (  ) 

Destroy this object. Note that this does not delete the object pointed to by mechanism(). Also note that this method's definition is compiler generated.


Member Function Documentation

template<class TYPE>
bslma::StdTestAllocator< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( StdTestAllocator< TYPE >  ,
bsl::is_trivially_copyable   
)
template<class TYPE>
bslma::StdTestAllocator< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( StdTestAllocator< TYPE >  ,
bslmf::IsBitwiseMoveable   
)
template<class TYPE>
bslma::StdTestAllocator< TYPE >::BSLMF_NESTED_TRAIT_DECLARATION ( StdTestAllocator< TYPE >  ,
bslmf::IsBitwiseEqualityComparable   
)

Declare nested type traits for this class.

template<class TYPE>
StdTestAllocator& bslma::StdTestAllocator< TYPE >::operator= ( const StdTestAllocator< TYPE > &  rhs  ) 

Assign to this object the value of the specified rhs. Postcondition: this->mechanism() == rhs->mechanism(). Note that this does not delete the object pointed to by the previous value of mechanism(). Also note that this method's definition is compiler generated.

template<class TYPE>
pointer bslma::StdTestAllocator< TYPE >::allocate ( size_type  n,
const void *  hint = 0 
)

Allocate enough (properly aligned) space for the specified n objects of (template parameter) TYPE by calling allocate on the mechanism object. The optionally specified hint argument is ignored by this test allocator type. The behavior is undefined unless n <= max_size().

template<class TYPE>
void bslma::StdTestAllocator< TYPE >::deallocate ( pointer  p,
size_type  n = 1 
)

Return memory previously allocated with allocate to the underlying mechanism object by calling deallocate on the mechanism object with the specified p. The optionally specified n argument is ignored by this test allocator type.

template<class TYPE>
template<class ELEMENT_TYPE >
void bslma::StdTestAllocator< TYPE >::construct ( ELEMENT_TYPE *  address,
const TYPE &  val 
)

Copy-construct an object of (template parameter) TYPE from the specified val at the memory address specified by p. Do not directly allocate memory. The behavior is undefined unless p is not properly aligned for objects of the given TYPE.

template<class TYPE>
template<class ELEMENT_TYPE >
void bslma::StdTestAllocator< TYPE >::destroy ( ELEMENT_TYPE *  address  ) 

Call the TYPE destructor for the object pointed to by the specified p. Do not directly deallocate any memory.

template<class TYPE>
pointer bslma::StdTestAllocator< TYPE >::address ( reference  x  )  const

Return the address of the object referred to by the specified x, even if the (template parameter) TYPE overloads the unary operator&.

template<class TYPE>
const_pointer bslma::StdTestAllocator< TYPE >::address ( const_reference  x  )  const

Return the address of the object referred to by the specified x, even if the (template parameter) TYPE overloads the unary operator&.

template<class TYPE>
size_type bslma::StdTestAllocator< TYPE >::max_size (  )  const

Return the maximum number of elements of (template parameter) TYPE that can be allocated using this test allocator. Note that there is no guarantee that attempts at allocating fewer elements than the value returned by max_size will not throw.

template<class TYPE>
TestAllocator* bslma::StdTestAllocator< TYPE >::mechanism (  )  const

Return a pointer to the mechanism object to which this proxy forwards allocation and deallocation calls.


The documentation for this class was generated from the following file: