Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes

bdlc::PackedIntArrayImp< STORAGE > Class Template Reference

#include <bdlc_packedintarray.h>

List of all members.

Public Types

typedef
STORAGE::EightByteStorageType 
ElementType

Public Member Functions

 PackedIntArrayImp (bslma::Allocator *basicAllocator=0)
 PackedIntArrayImp (bsl::size_t numElements, ElementType value=0, bslma::Allocator *basicAllocator=0)
 PackedIntArrayImp (const PackedIntArrayImp &original, bslma::Allocator *basicAllocator=0)
 ~PackedIntArrayImp ()
PackedIntArrayImpoperator= (const PackedIntArrayImp &rhs)
void append (ElementType value)
void append (const PackedIntArrayImp &srcArray)
void append (const PackedIntArrayImp &srcArray, bsl::size_t srcIndex, bsl::size_t numElements)
template<class STREAM >
STREAM & bdexStreamIn (STREAM &stream, int version)
void insert (bsl::size_t dstIndex, ElementType value)
void insert (bsl::size_t dstIndex, const PackedIntArrayImp &srcArray)
void insert (bsl::size_t dstIndex, const PackedIntArrayImp &srcArray, bsl::size_t srcIndex, bsl::size_t numElements)
void pop_back ()
void push_back (ElementType value)
void remove (bsl::size_t dstIndex)
void remove (bsl::size_t dstIndex, bsl::size_t numElements)
void removeAll ()
void replace (bsl::size_t dstIndex, ElementType value)
void replace (bsl::size_t dstIndex, const PackedIntArrayImp &srcArray, bsl::size_t srcIndex, bsl::size_t numElements)
void reserveCapacityImp (bsl::size_t requiredCapacityInBytes)
void reserveCapacity (bsl::size_t numElements)
void reserveCapacity (bsl::size_t numElements, ElementType maxValue)
void reserveCapacity (bsl::size_t numElements, ElementType minValue, ElementType maxValue)
void resize (bsl::size_t numElements)
void swap (PackedIntArrayImp &other)
ElementType operator[] (bsl::size_t index) const
bslma::Allocatorallocator () const
template<class STREAM >
STREAM & bdexStreamOut (STREAM &stream, int version) const
int bytesPerElement () const
bsl::size_t capacity () const
bool isEmpty () const
bool isEqual (const PackedIntArrayImp &other) const
bsl::size_t length () const
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const

Static Public Member Functions

static int maxSupportedBdexVersion (int serializationVersion)

Static Public Attributes

static const bsl::size_t k_MAX_CAPACITY = 0x7fffffff

Detailed Description

template<class STORAGE>
class bdlc::PackedIntArrayImp< STORAGE >

This space-efficient value-semantic array class represents a sequence of STORAGE::EightByteStorageType elements; STORAGE::EightByteStorageType 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.

See Component bdlc_packedintarray


Member Typedef Documentation

template<class STORAGE >
typedef STORAGE::EightByteStorageType bdlc::PackedIntArrayImp< STORAGE >::ElementType

Constructor & Destructor Documentation

template<class STORAGE >
bdlc::PackedIntArrayImp< STORAGE >::PackedIntArrayImp ( bslma::Allocator basicAllocator = 0  )  [explicit]

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

template<class STORAGE >
bdlc::PackedIntArrayImp< STORAGE >::PackedIntArrayImp ( bsl::size_t  numElements,
ElementType  value = 0,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create a PackedIntArrayImp 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.

template<class STORAGE >
bdlc::PackedIntArrayImp< STORAGE >::PackedIntArrayImp ( const PackedIntArrayImp< STORAGE > &  original,
bslma::Allocator basicAllocator = 0 
)

Create a PackedIntArrayImp 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.

template<class STORAGE >
bdlc::PackedIntArrayImp< STORAGE >::~PackedIntArrayImp (  ) 

Destroy this object


Member Function Documentation

template<class STORAGE >
static int bdlc::PackedIntArrayImp< STORAGE >::maxSupportedBdexVersion ( int  serializationVersion  )  [static]

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.

template<class STORAGE >
PackedIntArrayImp& bdlc::PackedIntArrayImp< STORAGE >::operator= ( const PackedIntArrayImp< STORAGE > &  rhs  ) 

Assign to this array the value of the specified rhs array, and return a reference providing modifiable access to this array.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::append ( ElementType  value  ) 

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

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::append ( const PackedIntArrayImp< STORAGE > &  srcArray  ) 

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.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::append ( const PackedIntArrayImp< STORAGE > &  srcArray,
bsl::size_t  srcIndex,
bsl::size_t  numElements 
)

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.

template<class STORAGE >
template<class STREAM >
STREAM& bdlc::PackedIntArrayImp< STORAGE >::bdexStreamIn ( STREAM &  stream,
int  version 
)

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.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::insert ( bsl::size_t  dstIndex,
ElementType  value 
)

Insert into this array, at the specified dstIndex, an element of specified value, shifting any elements originally at or above dstIndex up by one. The behavior is undefined unless dstIndex <= length().

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::insert ( bsl::size_t  dstIndex,
const PackedIntArrayImp< STORAGE > &  srcArray 
)

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.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::insert ( bsl::size_t  dstIndex,
const PackedIntArrayImp< STORAGE > &  srcArray,
bsl::size_t  srcIndex,
bsl::size_t  numElements 
)

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.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::pop_back (  ) 

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

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::push_back ( ElementType  value  ) 

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

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

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

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::removeAll (  ) 

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

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::replace ( bsl::size_t  dstIndex,
ElementType  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 STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::replace ( bsl::size_t  dstIndex,
const PackedIntArrayImp< STORAGE > &  srcArray,
bsl::size_t  srcIndex,
bsl::size_t  numElements 
)

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.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::reserveCapacityImp ( bsl::size_t  requiredCapacityInBytes  ) 

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

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::reserveCapacity ( bsl::size_t  numElements  ) 

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

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::reserveCapacity ( bsl::size_t  numElements,
ElementType  maxValue 
)

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.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::reserveCapacity ( bsl::size_t  numElements,
ElementType  minValue,
ElementType  maxValue 
)

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.

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::resize ( bsl::size_t  numElements  ) 

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

template<class STORAGE >
void bdlc::PackedIntArrayImp< STORAGE >::swap ( PackedIntArrayImp< STORAGE > &  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 STORAGE >
ElementType bdlc::PackedIntArrayImp< STORAGE >::operator[] ( bsl::size_t  index  )  const

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

template<class STORAGE >
bslma::Allocator* bdlc::PackedIntArrayImp< STORAGE >::allocator (  )  const

Return the allocator used by this array to supply memory.

template<class STORAGE >
template<class STREAM >
STREAM& bdlc::PackedIntArrayImp< STORAGE >::bdexStreamOut ( STREAM &  stream,
int  version 
) const

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.

template<class STORAGE >
int bdlc::PackedIntArrayImp< STORAGE >::bytesPerElement (  )  const

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

template<class STORAGE >
bsl::size_t bdlc::PackedIntArrayImp< STORAGE >::capacity (  )  const

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

template<class STORAGE >
bool bdlc::PackedIntArrayImp< STORAGE >::isEmpty (  )  const

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

template<class STORAGE >
bool bdlc::PackedIntArrayImp< STORAGE >::isEqual ( const PackedIntArrayImp< STORAGE > &  other  )  const

Return true if this and the specified other array have the same value, and false otherwise. Two PackedIntArrayImp 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 STORAGE >
bsl::size_t bdlc::PackedIntArrayImp< STORAGE >::length (  )  const

Return number of elements in this array.

template<class STORAGE >
bsl::ostream& bdlc::PackedIntArrayImp< STORAGE >::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.


Member Data Documentation

template<class STORAGE >
const bsl::size_t bdlc::PackedIntArrayImp< STORAGE >::k_MAX_CAPACITY = 0x7fffffff [static]

maximum capacity


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