Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends

ACE_Array_Base< T > Class Template Reference

Implement a simple dynamic array. More...

#include <Array_Base.h>

Inheritance diagram for ACE_Array_Base< T >:
Inheritance graph
[legend]
Collaboration diagram for ACE_Array_Base< T >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef T TYPE
typedef ACE_Array_Iterator< T > ITERATOR
typedef T value_type
typedef value_typeiterator
typedef value_type const * const_iterator
typedef value_typereference
typedef value_type const & const_reference
typedef value_typepointer
typedef value_type const * const_pointer
typedef ptrdiff_t difference_type
typedef ACE_Allocator::size_type size_type

Public Member Functions

ACE_DECLARE_STL_REVERSE_ITERATORS ACE_Array_Base (size_type size=0, ACE_Allocator *the_allocator=0)
 Dynamically create an uninitialized array.
 ACE_Array_Base (size_type size, T const &default_value, ACE_Allocator *the_allocator=0)
 Dynamically initialize the entire array to the <default_value>.
 ACE_Array_Base (ACE_Array_Base< T > const &s)
void operator= (ACE_Array_Base< T > const &s)
 ~ACE_Array_Base (void)
 Clean up the array (e.g., delete dynamically allocated memory).
T & operator[] (size_type slot)
T const & operator[] (size_type slot) const
int set (T const &new_item, size_type slot)
int get (T &item, size_type slot) const
size_type size (void) const
 Returns the <cur_size_> of the array.
int size (size_type new_size)
size_type max_size (void) const
 Returns the <max_size_> of the array.
int max_size (size_type new_size)
void swap (ACE_Array_Base< T > &array)
Forward Iterator Accessors

Forward iterator accessors.

iterator begin (void)
iterator end (void)
const_iterator begin (void) const
const_iterator end (void) const
Reverse Iterator Accessors

Reverse iterator accessors.

reverse_iterator rbegin (void)
reverse_iterator rend (void)
const_reverse_iterator rbegin (void) const
const_reverse_iterator rend (void) const

Protected Member Functions

bool in_range (size_type slot) const

Protected Attributes

size_type max_size_
size_type cur_size_
value_typearray_
 Pointer to the array's storage buffer.
ACE_Allocatorallocator_
 Allocation strategy of the ACE_Array_Base.

Friends

class ACE_Array_Iterator< T >

Detailed Description

template<class T>
class ACE_Array_Base< T >

Implement a simple dynamic array.

This parametric class implements a simple dynamic array; resizing must be controlled by the user. No comparison or find operations are implemented.

Definition at line 43 of file Array_Base.h.


Member Typedef Documentation

template<class T>
typedef value_type const* ACE_Array_Base< T >::const_iterator

Definition at line 54 of file Array_Base.h.

template<class T>
typedef value_type const* ACE_Array_Base< T >::const_pointer

Definition at line 58 of file Array_Base.h.

template<class T>
typedef value_type const& ACE_Array_Base< T >::const_reference

Definition at line 56 of file Array_Base.h.

template<class T>
typedef ptrdiff_t ACE_Array_Base< T >::difference_type

Definition at line 59 of file Array_Base.h.

template<class T>
typedef ACE_Array_Iterator<T> ACE_Array_Base< T >::ITERATOR
template<class T>
typedef value_type* ACE_Array_Base< T >::iterator

Definition at line 53 of file Array_Base.h.

template<class T>
typedef value_type* ACE_Array_Base< T >::pointer

Definition at line 57 of file Array_Base.h.

template<class T>
typedef value_type& ACE_Array_Base< T >::reference

Definition at line 55 of file Array_Base.h.

template<class T>
typedef ACE_Allocator::size_type ACE_Array_Base< T >::size_type

Definition at line 60 of file Array_Base.h.

template<class T>
typedef T ACE_Array_Base< T >::TYPE
template<class T>
typedef T ACE_Array_Base< T >::value_type

Definition at line 52 of file Array_Base.h.


Constructor & Destructor Documentation

template<class T>
ACE_DECLARE_STL_REVERSE_ITERATORS ACE_Array_Base< T >::ACE_Array_Base ( size_type  size = 0,
ACE_Allocator the_allocator = 0 
)

Dynamically create an uninitialized array.

template<class T>
ACE_Array_Base< T >::ACE_Array_Base ( size_type  size,
T const &  default_value,
ACE_Allocator the_allocator = 0 
)

Dynamically initialize the entire array to the <default_value>.

template<class T>
ACE_Array_Base< T >::ACE_Array_Base ( ACE_Array_Base< T > const &  s  ) 

The copy constructor performs initialization by making an exact copy of the contents of parameter <s>, i.e., *this == s will return true.

Definition at line 70 of file Array_Base.cpp.

  : max_size_ (s.size ()),
    cur_size_ (s.size ()),
    allocator_ (s.allocator_)
{
  if (this->allocator_ == 0)
    this->allocator_ = ACE_Allocator::instance ();

  ACE_ALLOCATOR (this->array_,
                 (T *) this->allocator_->malloc (s.size () * sizeof (T)));
  for (size_type i = 0; i < this->size (); ++i)
    new (&this->array_[i]) T (s.array_[i]);
}

template<class T >
ACE_Array_Base< T >::~ACE_Array_Base ( void   )  [inline]

Clean up the array (e.g., delete dynamically allocated memory).

Definition at line 9 of file Array_Base.inl.

{
  ACE_DES_ARRAY_FREE (this->array_,
                      this->max_size_,
                      this->allocator_->free,
                      T);
}


Member Function Documentation

template<class T >
ACE_Array_Base< T >::iterator ACE_Array_Base< T >::begin ( void   )  [inline]

Definition at line 19 of file Array_Base.inl.

{
  return this->array_;
}

template<class T >
ACE_Array_Base< T >::const_iterator ACE_Array_Base< T >::begin ( void   )  const [inline]

Definition at line 33 of file Array_Base.inl.

{
  return this->array_;
}

template<class T >
ACE_Array_Base< T >::iterator ACE_Array_Base< T >::end ( void   )  [inline]

Definition at line 26 of file Array_Base.inl.

{
  return this->array_ + this->cur_size_;
}

template<class T >
ACE_Array_Base< T >::const_iterator ACE_Array_Base< T >::end ( void   )  const [inline]

Definition at line 40 of file Array_Base.inl.

{
  return this->array_ + this->cur_size_;
}

template<class T>
int ACE_Array_Base< T >::get ( T &  item,
size_type  slot 
) const

Get an item in the array at location slot. Returns -1 if slot is not in range, else returns 0. Note that this function copies the item. If you want to avoid the copy, you can use the const operator [], but then you'll be responsible for range checking.

template<class T>
bool ACE_Array_Base< T >::in_range ( size_type  slot  )  const [protected]

Returns 1 if slot is within range, i.e., 0 >= slot < cur_size_, else returns 0.

template<class T>
int ACE_Array_Base< T >::max_size ( size_type  new_size  ) 

Changes the size of the array to match new_size. It copies the old contents into the new array. Return -1 on failure. It does not affect new_size

template<class T >
ACE_Array_Base< T >::size_type ACE_Array_Base< T >::max_size ( void   )  const [inline]

Returns the <max_size_> of the array.

Definition at line 80 of file Array_Base.inl.

{
  return this->max_size_;
}

template<class T>
void ACE_Array_Base< T >::operator= ( ACE_Array_Base< T > const &  s  ) 

Assignment operator performs an assignment by making an exact copy of the contents of parameter <s>, i.e., *this == s will return true. Note that if the <max_size_> of <array_> is >= than <s.max_size_> we can copy it without reallocating. However, if <max_size_> is < <s.max_size_> we must delete the <array_>, reallocate a new <array_>, and then copy the contents of <s>.

Definition at line 87 of file Array_Base.cpp.

{
  // Check for "self-assignment".

  if (this != &s)
    {
      if (this->max_size_ < s.size ())
        {
          // Need to reallocate memory.

          // Strongly exception-safe assignment.
          //
          // Note that we're swapping the allocators here, too.
          // Should we?  Probably.  "*this" should be a duplicate of
          // the "right hand side".
          ACE_Array_Base<T> tmp (s);
          this->swap (tmp);
        }
      else
        {
          // Underlying array is large enough.  No need to reallocate
          // memory.
          //
          // "*this" still owns the memory for the underlying array.
          // Do not swap out the allocator.
          //
          // @@ Why don't we just drop the explicit destructor and
          //    placement operator new() calls with a straight
          //    element-by-element assignment?  Is the existing
          //    approach more efficient?
          //        -Ossama

          ACE_DES_ARRAY_NOFREE (this->array_,
                                s.size (),
                                T);

          this->cur_size_ = s.size ();

          for (size_type i = 0; i < this->size (); ++i)
            new (&this->array_[i]) T (s.array_[i]);
        }
    }
}

template<class T>
T& ACE_Array_Base< T >::operator[] ( size_type  slot  ) 

Set item in the array at location slot. Doesn't perform range checking.

template<class T>
T const& ACE_Array_Base< T >::operator[] ( size_type  slot  )  const

Get item in the array at location slot. Doesn't perform range checking.

template<class T >
ACE_Array_Base< T >::const_reverse_iterator ACE_Array_Base< T >::rbegin ( void   )  const [inline]

Definition at line 61 of file Array_Base.inl.

{
  return const_reverse_iterator (this->end ());
}

template<class T >
ACE_Array_Base< T >::reverse_iterator ACE_Array_Base< T >::rbegin ( void   )  [inline]

Definition at line 47 of file Array_Base.inl.

{
  return reverse_iterator (this->end ());
}

template<class T >
ACE_Array_Base< T >::reverse_iterator ACE_Array_Base< T >::rend ( void   )  [inline]

Definition at line 54 of file Array_Base.inl.

{
  return reverse_iterator (this->begin ());
}

template<class T >
ACE_Array_Base< T >::const_reverse_iterator ACE_Array_Base< T >::rend ( void   )  const [inline]

Definition at line 68 of file Array_Base.inl.

{
  return const_reverse_iterator (this->begin ());
}

template<class T>
int ACE_Array_Base< T >::set ( T const &  new_item,
size_type  slot 
)

Set an item in the array at location slot. Returns -1 if slot is not in range, else returns 0.

template<class T>
int ACE_Array_Base< T >::size ( size_type  new_size  ) 

Changes the size of the array to match new_size. It copies the old contents into the new array. Return -1 on failure.

template<class T >
ACE_Array_Base< T >::size_type ACE_Array_Base< T >::size ( void   )  const [inline]

Returns the <cur_size_> of the array.

Reimplemented in ACE_Vector< T, DEFAULT_SIZE >.

Definition at line 74 of file Array_Base.inl.

{
  return this->cur_size_;
}

template<class T>
void ACE_Array_Base< T >::swap ( ACE_Array_Base< T > &  array  ) 

Swap the contents of this array with the given array in an exception-safe manner.

Definition at line 206 of file Array_Base.cpp.

{
  std::swap (this->max_size_ , rhs.max_size_);
  std::swap (this->cur_size_ , rhs.cur_size_);
  std::swap (this->array_    , rhs.array_);
  std::swap (this->allocator_, rhs.allocator_);
}


Friends And Related Function Documentation

template<class T>
friend class ACE_Array_Iterator< T > [friend]

Definition at line 191 of file Array_Base.h.


Member Data Documentation

template<class T>
ACE_Allocator* ACE_Array_Base< T >::allocator_ [protected]

Allocation strategy of the ACE_Array_Base.

Definition at line 189 of file Array_Base.h.

template<class T>
value_type* ACE_Array_Base< T >::array_ [protected]

Pointer to the array's storage buffer.

Definition at line 186 of file Array_Base.h.

template<class T>
size_type ACE_Array_Base< T >::cur_size_ [protected]

Current size of the array. This starts out being == to <max_size_>. However, if we are assigned a smaller array, then <cur_size_> will become less than <max_size_>. The purpose of keeping track of both sizes is to avoid reallocating memory if we don't have to.

Definition at line 183 of file Array_Base.h.

template<class T>
size_type ACE_Array_Base< T >::max_size_ [protected]

Maximum size of the array, i.e., the total number of T elements in array_.

Definition at line 174 of file Array_Base.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines