BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlc::CompactedArray< TYPE > Class Template Reference

#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.
 
CompactedArrayoperator= (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::Allocatorallocator () 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.
 

Detailed Description

template<class TYPE>
class bdlc::CompactedArray< TYPE >

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.

See bdlc_compactedarray

Member Typedef Documentation

◆ const_iterator

template<class TYPE >
typedef CompactedArray_ConstIterator<TYPE> bdlc::CompactedArray< TYPE >::const_iterator

◆ value_type

template<class TYPE >
typedef TYPE bdlc::CompactedArray< TYPE >::value_type

Constructor & Destructor Documentation

◆ CompactedArray() [1/3]

template<class TYPE >
bdlc::CompactedArray< TYPE >::CompactedArray ( bslma::Allocator basicAllocator = 0)
explicit

Create an empty CompactedArray. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ CompactedArray() [2/3]

template<class TYPE >
bdlc::CompactedArray< TYPE >::CompactedArray ( bsl::size_t  numElements,
const TYPE &  value = TYPE(),
bslma::Allocator basicAllocator = 0 
)
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.

◆ CompactedArray() [3/3]

template<class TYPE >
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.

◆ ~CompactedArray()

template<class TYPE >
bdlc::CompactedArray< TYPE >::~CompactedArray ( )

Member Function Documentation

◆ allocator()

template<class TYPE >
bslma::Allocator * bdlc::CompactedArray< TYPE >::allocator ( ) const
inline

◆ append() [1/3]

template<class TYPE >
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.

◆ append() [2/3]

template<class TYPE >
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.

◆ append() [3/3]

template<class TYPE >
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:

push_back(value);
void push_back(const TYPE &value)
Append to this array an element having the specified value.
Definition bdlc_compactedarray.h:1722

◆ back()

template<class TYPE >
const TYPE & bdlc::CompactedArray< TYPE >::back ( ) const
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:

bsl::size_t length() const
Return the number of elements in this array.
Definition bdlc_compactedarray.h:2002
const TYPE & operator[](bsl::size_t index) const
Definition bdlc_compactedarray.h:1932

◆ begin()

template<class TYPE >
CompactedArray< TYPE >::const_iterator bdlc::CompactedArray< TYPE >::begin ( ) const
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.

◆ capacity()

template<class TYPE >
bsl::size_t bdlc::CompactedArray< TYPE >::capacity ( ) const
inline

Return the number of elements this array can hold, without reallocation, assuming the number of unique elements within this array does not increase.

◆ end()

template<class TYPE >
CompactedArray< TYPE >::const_iterator bdlc::CompactedArray< TYPE >::end ( ) const
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.

◆ front()

template<class TYPE >
const TYPE & bdlc::CompactedArray< TYPE >::front ( ) const
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:

◆ insert() [1/4]

template<class TYPE >
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.

◆ insert() [2/4]

template<class TYPE >
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.

◆ insert() [3/4]

template<class TYPE >
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().

◆ insert() [4/4]

template<class TYPE >
CompactedArray< TYPE >::const_iterator bdlc::CompactedArray< TYPE >::insert ( const_iterator  dst,
const TYPE &  value 
)
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.

◆ isEmpty()

template<class TYPE >
bool bdlc::CompactedArray< TYPE >::isEmpty ( ) const
inline

Return true if there are no elements in this array, and false otherwise.

◆ isEqual()

template<class TYPE >
bool bdlc::CompactedArray< TYPE >::isEqual ( const CompactedArray< TYPE > &  other) const
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.

◆ length()

template<class TYPE >
bsl::size_t bdlc::CompactedArray< TYPE >::length ( ) const
inline

◆ operator=()

template<class TYPE >
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.

◆ operator[]()

template<class TYPE >
const TYPE & bdlc::CompactedArray< TYPE >::operator[] ( bsl::size_t  index) const
inline

Return a const reference to the element at the specified index in this array. The behavior is undefined unless index < length().

◆ pop_back()

template<class TYPE >
void bdlc::CompactedArray< TYPE >::pop_back ( )

Remove the last element from this array. The behavior is undefined unless 0 < length().

◆ print()

template<class TYPE >
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.

◆ push_back()

template<class TYPE >
void bdlc::CompactedArray< TYPE >::push_back ( const TYPE &  value)
inline

◆ remove() [1/3]

template<class TYPE >
void bdlc::CompactedArray< TYPE >::remove ( bsl::size_t  dstIndex)
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().

◆ remove() [2/3]

template<class TYPE >
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().

◆ remove() [3/3]

template<class TYPE >
CompactedArray< TYPE >::const_iterator bdlc::CompactedArray< TYPE >::remove ( const_iterator  dstFirst,
const_iterator  dstLast 
)
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.

◆ removeAll()

template<class TYPE >
void bdlc::CompactedArray< TYPE >::removeAll ( )

◆ replace() [1/2]

template<class TYPE >
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.

◆ replace() [2/2]

template<class TYPE >
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().

◆ reserveCapacity() [1/2]

template<class TYPE >
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.

◆ reserveCapacity() [2/2]

template<class TYPE >
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.

◆ resize()

template<class TYPE >
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().

◆ swap()

template<class 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.

◆ uniqueElement()

template<class TYPE >
const TYPE & bdlc::CompactedArray< TYPE >::uniqueElement ( bsl::size_t  index) const
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.

◆ uniqueLength()

template<class TYPE >
bsl::size_t bdlc::CompactedArray< TYPE >::uniqueLength ( ) const
inline

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