ACE_Vector< T, DEFAULT_SIZE > Class Template Reference

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

#include <Vector_T.h>

Inheritance diagram for ACE_Vector< T, DEFAULT_SIZE >:

Inheritance graph
[legend]
Collaboration diagram for ACE_Vector< T, DEFAULT_SIZE >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Vector_Iterator<
T, DEFAULT_SIZE > 
Iterator

Public Member Functions

 ACE_Vector (const size_t init_size=DEFAULT_SIZE, ACE_Allocator *alloc=0)
 ~ACE_Vector ()
size_t capacity (void) const
size_t size (void) const
void clear (void)
void resize (const size_t new_size, const T &t)
void push_back (const T &elem)
void pop_back (void)
void dump (void) const
bool operator== (const ACE_Vector< T, DEFAULT_SIZE > &s) const
 Equality comparison operator.

bool operator!= (const ACE_Vector< T, DEFAULT_SIZE > &s) const
 Inequality comparison operator.


Protected Attributes

size_t length_
size_t curr_max_size_

Friends

class ACE_Vector_Iterator< T, DEFAULT_SIZE >

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

Definition at line 70 of file Vector_T.h.


Member Typedef Documentation

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

A short name for iterator for ACE_Vector.

Definition at line 76 of file Vector_T.h.


Constructor & Destructor Documentation

template<class T, size_t DEFAULT_SIZE>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL 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

Definition at line 8 of file Vector_T.inl.

References ACE_Vector< T, DEFAULT_SIZE >::curr_max_size_, and ACE_Array_Base< T >::max_size().

00010   : ACE_Array<T> (init_size == 0 ? DEFAULT_SIZE : init_size, alloc)
00011 {
00012   length_ = 0;
00013   curr_max_size_ = this->max_size ();
00014 }

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

Destructor.

Definition at line 17 of file Vector_T.inl.

00018 {
00019 }


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

Definition at line 22 of file Vector_T.inl.

References ACE_Vector< T, DEFAULT_SIZE >::curr_max_size_.

00023 {
00024   return curr_max_size_;
00025 }

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.

Definition at line 34 of file Vector_T.inl.

00035 {
00036   length_ = 0;
00037 }

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.

Definition at line 46 of file Vector_T.cpp.

References ACE_Vector< T, DEFAULT_SIZE >::size().

00047 {
00048 #if defined (ACE_HAS_DUMP)
00049 #if 0
00050   // Can't do this unless the vector is an object with a dump
00051   // function.
00052   for (size_t i = 0; i < this->size (); ++i)
00053     (*this)[i].dump ();
00054 #endif /* 0 */
00055 #endif /* ACE_HAS_DUMP */
00056 }

template<class T, size_t DEFAULT_SIZE>
ACE_INLINE bool ACE_Vector< T, DEFAULT_SIZE >::operator!= const ACE_Vector< T, DEFAULT_SIZE > &  s  )  const
 

Inequality comparison operator.

Compare this vector with

  • s for inequality such that *this !=
  • s is always the complement of the boolean return value of *this ==
  • s.

Definition at line 49 of file Vector_T.inl.

00050 {
00051   return !(*this == s);
00052 }

template<class T, size_t DEFAULT_SIZE>
bool ACE_Vector< T, DEFAULT_SIZE >::operator== const ACE_Vector< T, DEFAULT_SIZE > &  s  )  const
 

Equality comparison operator.

Compare this vector with

  • s for equality. Two vectors are equal if their sizes are equal and all the elements are equal.

Definition at line 60 of file Vector_T.cpp.

References ACE_Vector< T, DEFAULT_SIZE >::size().

00061 {
00062   if (this == &s)
00063     return true;
00064   else if (this->size () != s.size ())
00065     return false;
00066 
00067   const size_t len = s.size ();
00068   for (size_t slot = 0; slot < len; ++slot)
00069     if ((*this)[slot] != s[slot])
00070       return false;
00071 
00072   return true;
00073 }

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.

Definition at line 40 of file Vector_T.inl.

00041 {
00042   if (length_ > 0)
00043     --length_;
00044 }

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.

Definition at line 34 of file Vector_T.cpp.

References ACE_Vector< T, DEFAULT_SIZE >::curr_max_size_, ACE_Array_Base< T >::max_size(), and ACE_Array_Base< T >::size().

00035 {
00036   if (length_ == curr_max_size_)
00037     {
00038       ACE_Array<T>::size (curr_max_size_ * 2);
00039       curr_max_size_ = this->max_size ();
00040     }
00041   ++length_;
00042   (*this)[length_-1] = elem;
00043 }

template<class T, size_t DEFAULT_SIZE>
ACE_BEGIN_VERSIONED_NAMESPACE_DECL 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).

Definition at line 21 of file Vector_T.cpp.

References ACE_Vector< T, DEFAULT_SIZE >::curr_max_size_, ACE_Array_Base< T >::max_size(), and ACE_Array_Base< T >::size().

00023 {
00024   ACE_Array<T>::size (new_size);
00025   if (new_size > length_)
00026     for (size_t i = length_; i < new_size; ++i)
00027       (*this)[i]=t;
00028 
00029   curr_max_size_ = this->max_size ();
00030   length_ = new_size;
00031 }

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< T >.

Definition at line 28 of file Vector_T.inl.

Referenced by ACE_Vector< T, DEFAULT_SIZE >::dump(), and ACE_Vector< T, DEFAULT_SIZE >::operator==().

00029 {
00030   return length_;
00031 }


Friends And Related Function Documentation

template<class T, size_t DEFAULT_SIZE = ACE_VECTOR_DEFAULT_SIZE>
friend class ACE_Vector_Iterator< T, DEFAULT_SIZE > [friend]
 

Definition at line 200 of file Vector_T.h.


Member Data Documentation

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

Current capacity (buffer size) of the vector.

Definition at line 198 of file Vector_T.h.

Referenced by ACE_Vector< T, DEFAULT_SIZE >::ACE_Vector(), ACE_Vector< T, DEFAULT_SIZE >::capacity(), ACE_Vector< T, DEFAULT_SIZE >::push_back(), and ACE_Vector< T, DEFAULT_SIZE >::resize().

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

Dynamic size (length) of the vector.

Definition at line 193 of file Vector_T.h.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:32:22 2006 for ACE by doxygen 1.3.6