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

#include <bdlc_packedintarray.h>

Public Types

typedef TYPE value_type
 
typedef PackedIntArrayConstIterator< TYPE > const_iterator
 

Public Member Functions

 PackedIntArray (bslma::Allocator *basicAllocator=0)
 
 PackedIntArray (bsl::size_t numElements, TYPE value=0, bslma::Allocator *basicAllocator=0)
 
 PackedIntArray (const PackedIntArray &original, bslma::Allocator *basicAllocator=0)
 
 ~PackedIntArray ()
 Destroy this object.
 
PackedIntArrayoperator= (const PackedIntArray &rhs)
 
void append (TYPE value)
 
void append (const PackedIntArray &srcArray)
 
void append (const PackedIntArray &srcArray, bsl::size_t srcIndex, bsl::size_t numElements)
 
template<class STREAM >
STREAM & bdexStreamIn (STREAM &stream, int version)
 
void insert (bsl::size_t dstIndex, TYPE value)
 
const_iterator insert (const_iterator dst, TYPE value)
 
void insert (bsl::size_t dstIndex, const PackedIntArray &srcArray)
 
void insert (bsl::size_t dstIndex, const PackedIntArray &srcArray, bsl::size_t srcIndex, bsl::size_t numElements)
 
void pop_back ()
 
void push_back (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, TYPE value)
 
void replace (bsl::size_t dstIndex, const PackedIntArray &srcArray, bsl::size_t srcIndex, bsl::size_t numElements)
 
void reserveCapacity (bsl::size_t numElements)
 
void reserveCapacity (bsl::size_t numElements, TYPE maxValue)
 
void reserveCapacity (bsl::size_t numElements, TYPE minValue, TYPE maxValue)
 
void resize (bsl::size_t numElements)
 
void swap (PackedIntArray &other)
 
TYPE operator[] (bsl::size_t index) const
 
bslma::Allocatorallocator () const
 Return the allocator used by this array to supply memory.
 
TYPE back () const
 
template<class STREAM >
STREAM & bdexStreamOut (STREAM &stream, int version) const
 
const_iterator begin () const
 
int bytesPerElement () const
 
bsl::size_t capacity () const
 
const_iterator end () const
 
TYPE front () const
 
bool isEmpty () const
 
bool isEqual (const PackedIntArray &other) const
 
bsl::size_t length () const
 Return number of elements in this array.
 
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
 

Static Public Member Functions

static int maxSupportedBdexVersion (int serializationVersion)
 

Detailed Description

template<class TYPE>
class bdlc::PackedIntArray< TYPE >

This space-efficient value-semantic array class represents a sequence of TYPE elements; TYPE must be convertible to either a signed or unsigned 64-bit integer using static_cast . The interface provides functionality similar to a vector<int> however 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<int> are not invalidated upon reallocation.

See bdlc_packedintarray

Member Typedef Documentation

◆ const_iterator

template<class TYPE >
typedef PackedIntArrayConstIterator<TYPE> bdlc::PackedIntArray< TYPE >::const_iterator

◆ value_type

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

Constructor & Destructor Documentation

◆ PackedIntArray() [1/3]

template<class TYPE >
bdlc::PackedIntArray< TYPE >::PackedIntArray ( bslma::Allocator basicAllocator = 0)
inlineexplicit

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

◆ PackedIntArray() [2/3]

template<class TYPE >
bdlc::PackedIntArray< TYPE >::PackedIntArray ( bsl::size_t  numElements,
TYPE  value = 0,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create a PackedIntArray having the specified numElements. Optionally specify a value to which each element will be set. If value is not specified, 0 is used. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ PackedIntArray() [3/3]

template<class TYPE >
bdlc::PackedIntArray< TYPE >::PackedIntArray ( const PackedIntArray< TYPE > &  original,
bslma::Allocator basicAllocator = 0 
)
inline

Create a PackedIntArray having the same value as the specified original one. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~PackedIntArray()

template<class TYPE >
bdlc::PackedIntArray< TYPE >::~PackedIntArray ( )
inline

Member Function Documentation

◆ allocator()

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

◆ append() [1/3]

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::append ( const PackedIntArray< TYPE > &  srcArray)
inline

Append the sequence of values represented by the specified srcArray to the end of this array. 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::PackedIntArray< TYPE >::append ( const PackedIntArray< TYPE > &  srcArray,
bsl::size_t  srcIndex,
bsl::size_t  numElements 
)
inline

Append the sequence of values of the specified numElements starting at the specified srcIndex in the specified srcArray to the end of this array. 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::PackedIntArray< TYPE >::append ( TYPE  value)
inline

Append an element having the specified value to the end of this array.

◆ back()

template<class TYPE >
TYPE bdlc::PackedIntArray< TYPE >::back ( ) const
inline

Return the value of the element at the back of this array. The behavior is undefined unless 0 < length(). Note that this function is logically equivalent to:

bsl::size_t length() const
Return number of elements in this array.
Definition bdlc_packedintarray.h:2586
TYPE operator[](bsl::size_t index) const
Definition bdlc_packedintarray.h:2501

◆ bdexStreamIn()

template<class TYPE >
template<class STREAM >
STREAM & bdlc::PackedIntArray< TYPE >::bdexStreamIn ( STREAM &  stream,
int  version 
)
inline

Assign to this object the value read from the specified input stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, this object is unaltered and stream is invalidated but otherwise unmodified. If version is supported but stream becomes invalid during this operation, this object has an undefined, but valid, state. Note that no version is read from stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ bdexStreamOut()

template<class TYPE >
template<class STREAM >
STREAM & bdlc::PackedIntArray< TYPE >::bdexStreamOut ( STREAM &  stream,
int  version 
) const
inline

Write this value to the specified output stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, stream is invalidated but otherwise unmodified. Note that version is not written to stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ begin()

template<class TYPE >
PackedIntArray< TYPE >::const_iterator bdlc::PackedIntArray< 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). This reference remains valid as long as this array exists.

◆ bytesPerElement()

template<class TYPE >
int bdlc::PackedIntArray< TYPE >::bytesPerElement ( ) const
inline

Return the number of bytes currently used to store each element in this array.

◆ capacity()

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

Return the number of elements this array can hold in terms of the current data type used to store its elements.

◆ end()

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

Return an iterator referring to one element beyond the last element in this array. This reference remains valid as long as this array exists, and length does not decrease.

◆ front()

template<class TYPE >
TYPE bdlc::PackedIntArray< TYPE >::front ( ) const
inline

Return the value of the element at the front of this array. The behavior is undefined unless 0 < length(). Note that this function is logically equivalent to:

◆ insert() [1/4]

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::insert ( bsl::size_t  dstIndex,
const PackedIntArray< TYPE > &  srcArray 
)
inline

Insert into this array, at the specified dstIndex, the sequence of values represented by the specified srcArray, shifting any elements originally at or above dstIndex up by srcArray.length() indices higher. 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::PackedIntArray< TYPE >::insert ( bsl::size_t  dstIndex,
const PackedIntArray< TYPE > &  srcArray,
bsl::size_t  srcIndex,
bsl::size_t  numElements 
)
inline

Insert into this array, at the specified dstIndex, the specified numElements values in the specified srcArray starting at the specified srcIndex. Elements greater than or equal to dstIndex are shifted up numElements 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::PackedIntArray< TYPE >::insert ( bsl::size_t  dstIndex,
TYPE  value 
)
inline

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. The behavior is undefined unless dstIndex <= length().

◆ insert() [4/4]

template<class TYPE >
PackedIntArray< TYPE >::const_iterator bdlc::PackedIntArray< TYPE >::insert ( const_iterator  dst,
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. Return an iterator to the newly inserted element.

◆ isEmpty()

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

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

◆ isEqual()

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

Return true if this and the specified other array have the same value, and false otherwise. Two PackedIntArray 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::PackedIntArray< TYPE >::length ( ) const
inline

◆ maxSupportedBdexVersion()

template<class TYPE >
int bdlc::PackedIntArray< TYPE >::maxSupportedBdexVersion ( int  serializationVersion)
inlinestatic

Return the version to be used with the bdexStreamOut method corresponding to the specified serializationVersion. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

◆ operator=()

template<class TYPE >
PackedIntArray< TYPE > & bdlc::PackedIntArray< TYPE >::operator= ( const PackedIntArray< TYPE > &  rhs)
inline

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 >
TYPE bdlc::PackedIntArray< TYPE >::operator[] ( bsl::size_t  index) const
inline

Return the value of the element at the specified index. The behavior is undefined unless index < length().

◆ pop_back()

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::pop_back ( )
inline

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

◆ print()

template<class TYPE >
bsl::ostream & bdlc::PackedIntArray< 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::PackedIntArray< TYPE >::push_back ( TYPE  value)
inline

Append an element having the specified value to the end of this array.

◆ remove() [1/3]

template<class TYPE >
void bdlc::PackedIntArray< 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::PackedIntArray< TYPE >::remove ( bsl::size_t  dstIndex,
bsl::size_t  numElements 
)
inline

Remove from this array, starting at the specified dstIndex, the specified numElements, shifting the elements of this array that are at dstIndex + numElements or above to numElements indices lower. The behavior is undefined unless dstIndex + numElements <= length().

◆ remove() [3/3]

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

Remove from this array the elements starting from the specified dstFirst up to, but not including, the specified dstLast, shifting the elements of this array that are at or above dstLast to dstLast - dstFirst indices lower. 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 <= dstLast.

◆ removeAll()

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::removeAll ( )
inline

Remove all the elements from this array and set the storage required per element to one byte.

◆ replace() [1/2]

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::replace ( bsl::size_t  dstIndex,
const PackedIntArray< TYPE > &  srcArray,
bsl::size_t  srcIndex,
bsl::size_t  numElements 
)
inline

Change the values of the specified numElements elements in this array beginning at the specified dstIndex to those of the numElements values in the specified srcArray beginning at the specified srcIndex. 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::PackedIntArray< TYPE >::replace ( bsl::size_t  dstIndex,
TYPE  value 
)
inline

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/3]

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::reserveCapacity ( bsl::size_t  numElements)
inline

Make the capacity of this array at least the specified numElements. This method has no effect if the current capacity meets or exceeds the required capacity.

◆ reserveCapacity() [2/3]

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::reserveCapacity ( bsl::size_t  numElements,
TYPE  maxValue 
)
inline

Make the capacity of this array at least the specified numElements. The specified maxValue denotes the maximum element value that will be subsequently added to this array. After this call numElements having values in the range [0, maxValue] are guaranteed to not cause a reallocation. This method has no effect if the current capacity meets or exceeds the required capacity. The behavior is undefined unless 0 <= maxValue.

◆ reserveCapacity() [3/3]

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::reserveCapacity ( bsl::size_t  numElements,
TYPE  minValue,
TYPE  maxValue 
)
inline

Make the capacity of this array at least the specified numElements. The specified minValue and maxValue denote, respectively, the minimum and maximum elements values that will be subsequently added to this array. After this call numElements having values in the range [minValue, maxValue] are guaranteed to not cause a reallocation. This method has no effect if the current capacity meets or exceeds the required capacity. The behavior is undefined unless minValue <= maxValue.

◆ resize()

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::resize ( bsl::size_t  numElements)
inline

Set the length of this array to the specified numElements. If numElements > length(), the added elements are initialized to 0.

◆ swap()

template<class TYPE >
void bdlc::PackedIntArray< TYPE >::swap ( PackedIntArray< TYPE > &  other)
inline

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.


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