template<class TYPE, class ALLOCATOR>
class bslma::AutoRawDeleter< TYPE, ALLOCATOR >
This class implements a range proctor that, unless its release
method has previously been invoked, automatically deletes the contiguous sequence of managed objects upon destruction by iterating on each (managed) object, first invoking the object's destructor, and then free memory by invoking the deallocate
method of an allocator (or pool) of parameterized ALLOCATOR
type supplied to it at construction. The sequence of managed objects of parameterized TYPE
must have been created using memory provided by this allocator (or pool), which must remain valid throughout the lifetime of this range proctor. Note that when the length of this object is non-zero, it must refer to a non-null array of objects.
See bslma_autorawdeleter
template<class TYPE , class ALLOCATOR >
bslma::AutoRawDeleter< TYPE, ALLOCATOR >::AutoRawDeleter |
( |
TYPE ** |
origin, |
|
|
ALLOCATOR * |
allocator, |
|
|
int |
length = 0 |
|
) |
| |
|
inline |
Create an auto raw deleter to manage an array of objects at the specified origin
, and that uses the specified allocator
to delete the sequence of objects managed by this range proctor (if not released – see release
) upon destruction. Optionally specify length
to define its range, which by default is empty (i.e., length = 0
). The sequence of objects may extend in either direction from origin
. A positive length
represents the sequence of objects starting at origin
and extending "up" to length
(not including the object at the index position origin + length
). A negative length
represents the sequence of objects starting at one position below origin
and extending "down" to the absolute value of length
(including the object at index position origin + length
). If length
is 0, then this range proctor manages no objects. If origin
is non-zero, all objects within the proctored range (if any) must be constructed using memory supplied by allocator
. The behavior is undefined unless allocator
is non-zero, and, if origin
is 0, 'length is also 0. Note that when length
is non-positive, the object at the origin is not managed by this range proctor. For example, if origin
is at the index position 2, a length
of 2 signifies that the objects at positions 2 and 3 are managed, whereas a length
of -2 signifies that the objects at positions 0 and 1 are managed:
|<----->| |<----->|
___ ___ ___ ___ ___ ___ ___ ___ ___ ___
| 0 | 1 | 2 | 3 | 4 | | 0 | 1 | 2 | 3 | 4 |
`===^===^===^===^===' `===^===^===^===^==='
^------------ origin ^------------ origin
int length() const
Definition bslma_autorawdeleter.h:609
template<class TYPE , class ALLOCATOR >
Increase by one the (signed) length of the sequence of objects managed by this range proctor. The behavior is undefined unless the origin of the sequence of objects managed by this proctor is non-zero. The behavior is undefined unless the origin or this range proctor is non-zero. Note that if the length of this proctor is currently negative, the number of managed objects will decrease by one, whereas if the length is non-negative, the number of managed objects will increase by one.
template<class TYPE , class ALLOCATOR >
Decrease by one the (signed) length of the sequence of objects managed by this range proctor. The behavior is undefined unless the origin of the sequence of objects managed by this proctor is non-zero. The behavior is undefined unless the origin or this range proctor is non-zero. Note that if the length of this proctor is currently positive, the number of managed objects will decrease by one, whereas if the length is non-positive, the number of managed objects will increase by one.
template<class TYPE , class ALLOCATOR >
Release from management the sequence of objects currently managed by this range proctor by setting the length of the managed sequence to 0. All objects currently under management will become unmanaged (i.e., when the proctor goes out of scope and it was not assigned another sequence of objects to manage by invoking reset
, no objects will be deleted). If no objects are currently being managed, this method has no effect. Note that the origin is not affected.