Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions

bdlc::CompactedArray< TYPE > Class Template Reference

#include <bdlc_compactedarray.h>

List of all members.

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 ()
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)
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 ()
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
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
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

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 Component bdlc_compactedarray


Member Typedef Documentation

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

The type for elements.

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

Constructor & Destructor Documentation

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.

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.

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.

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

Destroy this object


Member Function Documentation

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

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);
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.

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.

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().

template<class TYPE>
const_iterator bdlc::CompactedArray< TYPE >::insert ( const_iterator  dst,
const TYPE &  value 
)

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.

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.

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.

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

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

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

Append to this array an element having the specified value.

template<class TYPE>
void bdlc::CompactedArray< TYPE >::remove ( bsl::size_t  dstIndex  ) 

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().

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().

template<class TYPE>
const_iterator bdlc::CompactedArray< TYPE >::remove ( const_iterator  dstFirst,
const_iterator  dstLast 
)

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.

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

Remove all the elements from this array.

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().

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.

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.

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.

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().

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.

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

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

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

Return the allocator used by this array to supply memory.

template<class TYPE>
const TYPE& bdlc::CompactedArray< TYPE >::back (  )  const

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:

template<class TYPE>
const_iterator bdlc::CompactedArray< TYPE >::begin (  )  const

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.

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

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

template<class TYPE>
const_iterator bdlc::CompactedArray< TYPE >::end (  )  const

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.

template<class TYPE>
const TYPE& bdlc::CompactedArray< TYPE >::front (  )  const

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:

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

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

template<class TYPE>
bool bdlc::CompactedArray< TYPE >::isEqual ( const CompactedArray< TYPE > &  other  )  const

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.

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

Return the number of elements in this array.

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.

template<class TYPE>
const TYPE& bdlc::CompactedArray< TYPE >::uniqueElement ( bsl::size_t  index  )  const

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[](index) can return different objects.

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

Return the number of unique elements in this array.


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