Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# ACE_Vector Class Template Reference

Defines an STL-like vector container. More...

`#include <Vector_T.h>`

Inheritance diagram for ACE_Vector:

[legend]
Collaboration diagram for ACE_Vector:

[legend]
List of all members.

## Public Types
typedef ACE_Array_Iterator< T > | Iterator
| A short name for iterator for ACE_Vector. More...
## Public Methods
| ACE_Vector (const size_t init_size=DEFAULT_SIZE, ACE_Allocator *alloc=0)
| General constructor. More...
| ~ACE_Vector ()
| Destructor. More...
size_t | capacity (void) const
| Returns the current vector capacity, that is, the currently allocated buffer size. More...
size_t | size (void) const
| Returns the vector's dynamic size / actual current size of the vector. More...
void | clear (void)
| Clears out the vector. More...
void | resize (const size_t new_size, const T &t)
| Resizes the vector to the new capacity. More...
void | push_back (const T &elem)
| Appends a new element to the vector ("push back"). More...
void | pop_back (void)
| Deletes the last element from the vector ("pop back"). More...
void | dump (void) const
| This function dumps the content of the vector. More...
## Protected Attributes
size_t | length_
| Dynamic size (length) of the vector. More...
size_t | curr_max_size_
| Current capacity (buffer size) of the vector. More...

## Detailed Description

### template<class T, size_t DEFAULT_SIZE = ACE_VECTOR_DEFAULT_SIZE>
class ACE_Vector< T, DEFAULT_SIZE >

Defines an STL-like vector container.

This is an STL-like template vector container, a wrapper around ACE_Array. It provides at least the basic std::vector look and feel: push_back(), clear(), resize(), capacity(). This template class uses the copy semantic paradigm, though it is okay to use reference counted smart pointers (see ACE_Ptr<T>) with this template class.

Requirements and Performance Characteristics

- Internal Structure ACE_Array
- Duplicates allowed? Yes
- Random access allowed? No
- Search speed N/A
- Insert/replace speed Linear
- Iterator still valid after change to container? Yes
- Frees memory for removed elements? No
- Items inserted by Value
- Requirements for contained type
  1. Default constructor
  2. Copy constructor
  3. operator=

## Member Typedef Documentation

template<class T, size_t DEFAULT_SIZE = ACE_VECTOR_DEFAULT_SIZE>
typedef ACE_Array_Iterator<T> ACE_Vector::Iterator

| A short name for iterator for ACE_Vector.

## Constructor & Destructor Documentation

template<class T, size_t DEFAULT_SIZE>
ACE_INLINE ACE_Vector< T, DEFAULT_SIZE >::ACE_Vector | ( | const size_t | init_size = DEFAULT_SIZE,
|  | ACE_Allocator * | alloc = 0
| ) |

  | General constructor. Parameters:
  init_size | Initial size of the vector with the default value of DEFAULT_SIZE
  alloc | Pointer to an ACE allocator. If it is NULL then the default ACE allocator is used

template<class T, size_t DEFAULT_SIZE>
ACE_INLINE ACE_Vector< T, DEFAULT_SIZE >::~ACE_Vector | ( |  | ) |

| Destructor.

## Member Function Documentation

template<class T, size_t DEFAULT_SIZE>
ACE_INLINE size_t ACE_Vector< T, DEFAULT_SIZE >::capacity | ( | void |  | ) | const

| Returns the current vector capacity, that is, the currently allocated buffer size. Returns: Current buffer size of the vector

template<class T, size_t DEFAULT_SIZE>
ACE_INLINE void ACE_Vector< T, DEFAULT_SIZE >::clear | ( | void |  | ) |

| Clears out the vector. It does not reallocate the vector's buffer, it is just sets the vector's dynamic size to 0.

template<class T, size_t DEFAULT_SIZE>
void ACE_Vector< T, DEFAULT_SIZE >::dump | ( | void |  | ) | const

| This function dumps the content of the vector. TO BE MOVED out of this class. It needs to be implemented as a global template function that accepts a const ACE_Vector<T>, in order to make instances of this class compile on Linux, AIX. G++ and xlC have template instantiation algoriths, which are different from the one in Visual C++. The algorithms try to instantiate ALL methods declared in the template class, regardless of whether the functions are used or not. That is, all of the classes, that are used as elements in ACE_Vector's, have to have the dump() methods defined in them (seems to be overkill). This function calls T::dump() for each element of the vector.

template<class T, size_t DEFAULT_SIZE>
ACE_INLINE void ACE_Vector< T, DEFAULT_SIZE >::pop_back | ( | void |  | ) |

| Deletes the last element from the vector ("pop back"). What this function really does is decrement the dynamic size of the vector. The vector's buffer does not get reallocated for performance.

template<class T, size_t DEFAULT_SIZE>
void ACE_Vector< T, DEFAULT_SIZE >::push_back | ( | const T & | elem | ) |

  | Appends a new element to the vector ("push back"). If the dynamic size of the vector is equal to the capacity of the vector (vector is at capacity), the vector automatically doubles its capacity. Parameters:
  elem | A reference to the new element to be appended. By default, this parameters gets initialized with the default value of the class T.

template<class T, size_t DEFAULT_SIZE>
void ACE_Vector< T, DEFAULT_SIZE >::resize | ( | const size_t | new_size,
|  | const T & | t
| ) |

  | Resizes the vector to the new capacity. If the vector's current capacity is smaller than the size to be specified, then the buffer gets reallocated. If the new capacity is less than the current capacity of the vector, the buffer size stays the same. Parameters:
  new_size | New capacity of the vector
  t | A filler value (of the class T) for initializing the elements of the vector with. By default, if this parameter is not specified, the default value of the class T will be used (for more detail, see the initialization clause for this parameter).

template<class T, size_t DEFAULT_SIZE>
ACE_INLINE size_t ACE_Vector< T, DEFAULT_SIZE >::size | ( | void |  | ) | const

| Returns the vector's dynamic size / actual current size of the vector. Do not confuse it with ACE_Array::size(), which returns the array's capacity. Unfortunately, ACE is not very consistent with the function names. Returns: Dynamic size / actual current size of the vector. Reimplemented from ACE_Array_Base.

## Member Data Documentation

template<class T, size_t DEFAULT_SIZE = ACE_VECTOR_DEFAULT_SIZE>
size_t ACE_Vector::curr_max_size_`[protected]`

| Current capacity (buffer size) of the vector.

template<class T, size_t DEFAULT_SIZE = ACE_VECTOR_DEFAULT_SIZE>
size_t ACE_Vector::length_`[protected]`

| Dynamic size (length) of the vector.

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

- Vector_T.h
- Vector_T.cpp
- Vector_T.i