BDE 4.14.0 Production release
|
#include <bdlc_compactedarray.h>
Public Types | |
typedef TYPE | value_type |
typedef CompactedArray_ConstIterator< TYPE > | const_iterator |
Public Member Functions | |
CompactedArray (bslma::Allocator *basicAllocator=0) | |
CompactedArray (bsl::size_t numElements, const TYPE &value=TYPE(), bslma::Allocator *basicAllocator=0) | |
CompactedArray (const CompactedArray &original, bslma::Allocator *basicAllocator=0) | |
~CompactedArray () | |
Destroy this object. | |
CompactedArray & | operator= (const CompactedArray &rhs) |
void | append (const TYPE &value) |
void | append (const CompactedArray &srcArray) |
void | append (const CompactedArray &srcArray, bsl::size_t srcIndex, bsl::size_t numElements) |
void | insert (bsl::size_t dstIndex, const TYPE &value) |
const_iterator | insert (const_iterator dst, const TYPE &value) |
void | insert (bsl::size_t dstIndex, const CompactedArray &srcArray) |
void | insert (bsl::size_t dstIndex, const CompactedArray &srcArray, bsl::size_t srcIndex, bsl::size_t numElements) |
void | pop_back () |
void | push_back (const TYPE &value) |
Append to this array an element having the specified value . | |
void | remove (bsl::size_t dstIndex) |
void | remove (bsl::size_t dstIndex, bsl::size_t numElements) |
const_iterator | remove (const_iterator dstFirst, const_iterator dstLast) |
void | removeAll () |
Remove all the elements from this array. | |
void | replace (bsl::size_t dstIndex, const TYPE &value) |
void | replace (bsl::size_t dstIndex, const CompactedArray &srcArray, bsl::size_t srcIndex, bsl::size_t numElements) |
void | reserveCapacity (bsl::size_t numElements) |
void | reserveCapacity (bsl::size_t numElements, bsl::size_t numUniqueElements) |
void | resize (bsl::size_t numElements) |
void | swap (CompactedArray &other) |
const TYPE & | operator[] (bsl::size_t index) const |
bslma::Allocator * | allocator () const |
Return the allocator used by this array to supply memory. | |
const TYPE & | back () const |
const_iterator | begin () const |
bsl::size_t | capacity () const |
const_iterator | end () const |
const TYPE & | front () const |
bool | isEmpty () const |
bool | isEqual (const CompactedArray &other) const |
bsl::size_t | length () const |
Return the number of elements in this array. | |
bsl::ostream & | print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const |
const TYPE & | uniqueElement (bsl::size_t index) const |
bsl::size_t | uniqueLength () const |
Return the number of unique elements in this array. | |
This space-efficient, value-semantic array class represents a sequence of TYPE
elements. The interface provides functionality similar to a vector<TYPE>
, however, modifiable references to individual elements are not provided. This class provides accessors that return iterators that provide non-modifiable access to its elements. The returned iterators, unlike those returned by a vector<TYPE>
, are not invalidated upon reallocation.
typedef CompactedArray_ConstIterator<TYPE> bdlc::CompactedArray< TYPE >::const_iterator |
typedef TYPE bdlc::CompactedArray< TYPE >::value_type |
|
explicit |
Create an empty CompactedArray
. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
|
explicit |
Create a CompactedArray
having the specified numElements
. Optionally specify a value
to which each element will be set. If value
is not specified, TYPE()
is used. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlc::CompactedArray< TYPE >::CompactedArray | ( | const CompactedArray< TYPE > & | original, |
bslma::Allocator * | basicAllocator = 0 |
||
) |
Create a CompactedArray
having the same value as the specified original
object. Optionally specify a basicAllocator
used to supply memory. If basicAllocator
is 0, the currently installed default allocator is used.
bdlc::CompactedArray< TYPE >::~CompactedArray | ( | ) |
|
inline |
void bdlc::CompactedArray< TYPE >::append | ( | const CompactedArray< TYPE > & | srcArray | ) |
Append to this array the elements from the specified srcArray
. Note that if this array and srcArray
are the same, the behavior is as if a copy of srcArray
were passed.
void bdlc::CompactedArray< TYPE >::append | ( | const CompactedArray< TYPE > & | srcArray, |
bsl::size_t | srcIndex, | ||
bsl::size_t | numElements | ||
) |
Append to this array the specified numElements
starting at the specified srcIndex
in the specified srcArray
. The behavior is undefined unless srcIndex + numElements <= srcArray.length()
. Note that if this array and srcArray
are the same, the behavior is as if a copy of srcArray
were passed.
void bdlc::CompactedArray< TYPE >::append | ( | const TYPE & | value | ) |
Append to this array an element having the specified value
. Note that this method is logically equivalent to:
|
inline |
Return a const
reference to the element at the back of this array. The behavior is undefined unless 0 < length()
. Note that this method is logically equivalent to:
|
inline |
Return an iterator referring to the first element in this array, or the past-the-end iterator if this array is empty. The iterator remains valid as long as this array exists.
|
inline |
Return the number of elements this array can hold, without reallocation, assuming the number of unique elements within this array does not increase.
|
inline |
Return the past-the-end iterator for this array. The iterator remains valid as long as this array exists, and its length does not decrease.
|
inline |
Return a const
reference to the element at the front of this array. The behavior is undefined unless 0 < length()
. Note that this method is logically equivalent to:
void bdlc::CompactedArray< TYPE >::insert | ( | bsl::size_t | dstIndex, |
const CompactedArray< TYPE > & | srcArray | ||
) |
Insert into this array, at the specified dstIndex
, the elements from the specified srcArray
, shifting any elements originally at or above dstIndex
up by srcArray.length()
index positions. The behavior is undefined unless dstIndex <= length()
. Note that if this array and srcArray
are the same, the behavior is as if a copy of srcArray
were passed.
void bdlc::CompactedArray< TYPE >::insert | ( | bsl::size_t | dstIndex, |
const CompactedArray< TYPE > & | srcArray, | ||
bsl::size_t | srcIndex, | ||
bsl::size_t | numElements | ||
) |
Insert into this array, at the specified dstIndex
, the specified numElements
starting at the specified srcIndex
in the specified srcArray
. Elements having an index greater than or equal to dstIndex
before the insertion are shifted up by numElements
index positions. The behavior is undefined unless dstIndex <= length()
and srcIndex + numElements <= srcArray.length()
. Note that if this array and srcArray
are the same, the behavior is as if a copy of srcArray
were passed.
void bdlc::CompactedArray< TYPE >::insert | ( | bsl::size_t | dstIndex, |
const TYPE & | value | ||
) |
Insert into this array, at the specified dstIndex
, an element having the specified value
, shifting any elements originally at or above dstIndex
up by one index position. The behavior is undefined unless dstIndex <= length()
.
|
inline |
Insert into this array, at the specified dst
, an element having the specified value
, shifting any elements originally at or above dst
up by one index position. Return an iterator to the newly inserted element. The behavior is undefined unless dst
is an iterator over this array.
|
inline |
Return true
if there are no elements in this array, and false
otherwise.
|
inline |
Return true
if this and the specified other
array have the same value, and false
otherwise. Two CompactedArray
arrays have the same value if they have the same length, and all corresponding elements (those at the same indices) have the same value.
|
inline |
CompactedArray< TYPE > & bdlc::CompactedArray< TYPE >::operator= | ( | const CompactedArray< TYPE > & | rhs | ) |
Assign to this array the value of the specified rhs
array, and return a reference providing modifiable access to this array.
|
inline |
Return a const
reference to the element at the specified index
in this array. The behavior is undefined unless index < length()
.
void bdlc::CompactedArray< TYPE >::pop_back | ( | ) |
Remove the last element from this array. The behavior is undefined unless 0 < length()
.
bsl::ostream & bdlc::CompactedArray< TYPE >::print | ( | bsl::ostream & | stream, |
int | level = 0 , |
||
int | spacesPerLevel = 4 |
||
) | const |
Write the value of this array to the specified output stream
in a human-readable format, and return a reference to stream
. Optionally specify an initial indentation level
, whose absolute value is incremented recursively for nested arrays. If level
is specified, optionally specify spacesPerLevel
, whose absolute value indicates the number of spaces per indentation level for this and all of its nested arrays. If level
is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level
). If stream
is not valid on entry, this operation has no effect. Note that the format is not fully specified, and can change without notice.
|
inline |
|
inline |
Remove from this array the element at the specified dstIndex
. Each element having an index greater than dstIndex
before the removal is shifted down by one index position. The behavior is undefined unless dstIndex < length()
.
void bdlc::CompactedArray< TYPE >::remove | ( | bsl::size_t | dstIndex, |
bsl::size_t | numElements | ||
) |
Remove from this array the specified numElements
starting at the specified dstIndex
. Each element having an index greater than or equal to dstIndex + numElements
before the removal is shifted down by numElements
index positions. The behavior is undefined unless dstIndex + numElements <= length()
.
|
inline |
Remove from this array the elements starting at the specified dstFirst
iterator up to, but not including, the specified dstLast
iterator. Each element at or above dstLast
before the removal is shifted down by dstLast - dstFirst
index positions. Return an iterator to the new position of the element that was referred to by dstLast
, or end()
if dstLast == end()
. The behavior is undefined unless dstFirst
and dstLast
are iterators over this array, and dstFirst <= dstLast
.
void bdlc::CompactedArray< TYPE >::removeAll | ( | ) |
void bdlc::CompactedArray< TYPE >::replace | ( | bsl::size_t | dstIndex, |
const CompactedArray< TYPE > & | srcArray, | ||
bsl::size_t | srcIndex, | ||
bsl::size_t | numElements | ||
) |
Change the values of the specified numElements
starting at the specified dstIndex
in this array to those of the numElements
starting at the specified srcIndex
in the specified srcArray
. The behavior is undefined unless srcIndex + numElements <= srcArray.length()
and dstIndex + numElements <= length()
. Note that if this array and srcArray
are the same, the behavior is as if a copy of srcArray
were passed.
void bdlc::CompactedArray< TYPE >::replace | ( | bsl::size_t | dstIndex, |
const TYPE & | value | ||
) |
Change the value of the element at the specified dstIndex
in this array to the specified value
. The behavior is undefined unless dstIndex < length()
.
void bdlc::CompactedArray< TYPE >::reserveCapacity | ( | bsl::size_t | numElements | ) |
Make the capacity of this array at least the specified numElements
, assuming the number of unique elements within this array does not increase. This method has no effect if the current capacity meets or exceeds the required capacity. The behavior is undefined unless false == isEmpty() || 0 == numElements
. Note that the assumption of not increasing the number of unique elements implies the need for the narrow contract.
void bdlc::CompactedArray< TYPE >::reserveCapacity | ( | bsl::size_t | numElements, |
bsl::size_t | numUniqueElements | ||
) |
Make the capacity of this array at least the specified numElements
, assuming the number of unique elements in this array does not exceed the greater of the specified numUniqueElements
and uniqueLength()
. This method has no effect if the current capacity meets or exceeds the required capacity. The behavior is undefined unless numUniqueElements <= numElements
and 0 < numUniqueElements || 0 == numElements
.
void bdlc::CompactedArray< TYPE >::resize | ( | bsl::size_t | numElements | ) |
Set the length of this array to the specified numElements
. If numElements > length()
, the added elements are initialized to TYPE()
.
void bdlc::CompactedArray< TYPE >::swap | ( | CompactedArray< TYPE > & | other | ) |
Efficiently exchange the value of this array with the value of the specified other
array. This method provides the no-throw exception-safety guarantee. The behavior is undefined unless this array was created with the same allocator as other
.
|
inline |
Return a const
reference to the element at the specified index
within the sorted sequence of unique element values in this object. The behavior is undefined unless index < uniqueLength()
. Note that uniqueElement(index)
and operator@ref index
can return different objects.
|
inline |