#include <Array_Base.h>
Inheritance diagram for ACE_Array_Base< T >:
Public Types | |
typedef T | TYPE |
typedef ACE_Array_Iterator< T > | ITERATOR |
Public Member Functions | |
ACE_Array_Base (size_t size=0, ACE_Allocator *the_allocator=0) | |
Dynamically create an uninitialized array. | |
ACE_Array_Base (size_t size, const T &default_value, ACE_Allocator *the_allocator=0) | |
Dynamically initialize the entire array to the . | |
ACE_Array_Base (const ACE_Array_Base< T > &s) | |
void | operator= (const ACE_Array_Base< T > &s) |
~ACE_Array_Base (void) | |
Clean up the array (e.g., delete dynamically allocated memory). | |
T & | operator[] (size_t slot) |
const T & | operator[] (size_t slot) const |
int | set (const T &new_item, size_t slot) |
int | get (T &item, size_t slot) const |
size_t | size (void) const |
Returns the of the array. | |
int | size (size_t new_size) |
size_t | max_size (void) const |
Returns the of the array. | |
int | max_size (size_t new_size) |
Protected Member Functions | |
int | in_range (size_t slot) const |
Protected Attributes | |
size_t | max_size_ |
size_t | cur_size_ |
T * | array_ |
Pointer to the array's storage buffer. | |
ACE_Allocator * | allocator_ |
Allocation strategy of the ACE_Array_Base. | |
Friends | |
class | ACE_Array_Iterator< T > |
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 40 of file Array_Base.h.
|
Reimplemented in ACE_Array< T >, ACE_Array< ACE_Get_Opt_Long_Option * >, and ACE_Array< ACE_INET_Addr >. Definition at line 46 of file Array_Base.h. |
|
Reimplemented in ACE_Array< T >, ACE_Array< ACE_Get_Opt_Long_Option * >, and ACE_Array< ACE_INET_Addr >. Definition at line 45 of file Array_Base.h. |
|
Dynamically create an uninitialized array.
Definition at line 23 of file Array_Base.cpp. References ACE_ALLOCATOR, ACE_Array_Base< T >::array_, and ACE_Allocator::instance().
00025 : max_size_ (size), 00026 cur_size_ (size), 00027 allocator_ (alloc) 00028 { 00029 if (this->allocator_ == 0) 00030 this->allocator_ = ACE_Allocator::instance (); 00031 00032 if (size != 0) 00033 { 00034 ACE_ALLOCATOR (this->array_, 00035 (T *) this->allocator_->malloc (size * sizeof (T))); 00036 for (size_t i = 0; i < size; ++i) 00037 new (&array_[i]) T; 00038 } 00039 else 00040 this->array_ = 0; 00041 } |
|
Dynamically initialize the entire array to the .
Definition at line 44 of file Array_Base.cpp. References ACE_ALLOCATOR, ACE_Array_Base< T >::array_, and ACE_Allocator::instance().
00047 : max_size_ (size), 00048 cur_size_ (size), 00049 allocator_ (alloc) 00050 { 00051 if (this->allocator_ == 0) 00052 this->allocator_ = ACE_Allocator::instance (); 00053 00054 if (size != 0) 00055 { 00056 ACE_ALLOCATOR (this->array_, 00057 (T *) this->allocator_->malloc (size * sizeof (T))); 00058 for (size_t i = 0; i < size; ++i) 00059 new (&array_[i]) T (default_value); 00060 } 00061 else 00062 this->array_ = 0; 00063 } |
|
The copy constructor performs initialization by making an exact copy of the contents of parameter , i.e., *this == s will return true. Definition at line 68 of file Array_Base.cpp. References ACE_ALLOCATOR, ACE_Array_Base< T >::array_, ACE_Allocator::instance(), and ACE_Array_Base< T >::size().
00069 : max_size_ (s.size ()), 00070 cur_size_ (s.size ()), 00071 allocator_ (s.allocator_) 00072 { 00073 if (this->allocator_ == 0) 00074 this->allocator_ = ACE_Allocator::instance (); 00075 00076 ACE_ALLOCATOR (this->array_, 00077 (T *) this->allocator_->malloc (s.size () * sizeof (T))); 00078 for (size_t i = 0; i < this->size (); i++) 00079 new (&this->array_[i]) T (s.array_[i]); 00080 } |
|
Clean up the array (e.g., delete dynamically allocated memory).
Definition at line 10 of file Array_Base.inl. References ACE_DES_ARRAY_FREE.
00011 { 00012 ACE_DES_ARRAY_FREE (this->array_, 00013 this->max_size_, 00014 this->allocator_->free, 00015 T); 00016 } |
|
Get an item in the array at location . Returns -1 if 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. Definition at line 132 of file Array_Base.cpp. References ACE_Array_Base< T >::array_, and ACE_Array_Base< T >::in_range().
|
|
Returns 1 if is within range, i.e., 0 >= < , else returns 0. Definition at line 31 of file Array_Base.inl. References ACE_Array_Base< T >::cur_size_. Referenced by ACE_Array_Base< T >::get(), and ACE_Array_Base< T >::set().
00032 { 00033 return index < this->cur_size_; 00034 } |
|
Changes the size of the array to match . It copies the old contents into the new array. Return -1 on failure. It does not affect new_size Definition at line 146 of file Array_Base.cpp. References ACE_ALLOCATOR_RETURN, ACE_DES_ARRAY_FREE, ACE_Array_Base< T >::array_, ACE_Array_Base< T >::cur_size_, and ACE_Array_Base< T >::max_size_.
00147 { 00148 if (new_size > this->max_size_) 00149 { 00150 T *tmp = 0; 00151 00152 ACE_ALLOCATOR_RETURN (tmp, 00153 (T *) this->allocator_->malloc (new_size * sizeof (T)), 00154 -1); 00155 for (size_t i = 0; i < this->cur_size_; ++i) 00156 new (&tmp[i]) T (this->array_[i]); 00157 00158 // Initialize the new portion of the array that exceeds the 00159 // previously allocated section. 00160 for (size_t j = this->cur_size_; j < new_size; j++) 00161 new (&tmp[j]) T; 00162 00163 ACE_DES_ARRAY_FREE (this->array_, 00164 this->max_size_, 00165 this->allocator_->free, 00166 T); 00167 this->array_ = tmp; 00168 this->max_size_ = new_size; 00169 this->cur_size_ = new_size; 00170 } 00171 00172 return 0; 00173 } |
|
Returns the of the array.
Definition at line 25 of file Array_Base.inl. References ACE_Array_Base< T >::max_size_. Referenced by ACE_Vector< T, DEFAULT_SIZE >::ACE_Vector(), ACE_DLL_Handle::get_dll_names(), ACE_DLL_Handle::open(), ACE_Vector< T, DEFAULT_SIZE >::push_back(), ACE_Vector< T, DEFAULT_SIZE >::resize(), and ACE_Array_Base< T >::size().
00026 { 00027 return this->max_size_; 00028 } |
|
Assignment operator performs an assignment by making an exact copy of the contents of parameter , i.e., *this == s will return true. Note that if the of is >= than <s.max_size_> we can copy it without reallocating. However, if is < <s.max_size_> we must delete the , reallocate a new , and then copy the contents of . Definition at line 85 of file Array_Base.cpp. References ACE_ALLOCATOR, ACE_DES_ARRAY_FREE, ACE_DES_ARRAY_NOFREE, ACE_Array_Base< T >::array_, ACE_Array_Base< T >::cur_size_, ACE_Array_Base< T >::max_size_, and ACE_Array_Base< T >::size(). Referenced by ACE_Array< T >::operator=().
00086 { 00087 // Check for "self-assignment". 00088 00089 if (this != &s) 00090 { 00091 if (this->max_size_ < s.size ()) 00092 { 00093 ACE_DES_ARRAY_FREE (this->array_, 00094 this->max_size_, 00095 this->allocator_->free, 00096 T); 00097 ACE_ALLOCATOR (this->array_, 00098 (T *) this->allocator_->malloc (s.size () * sizeof (T))); 00099 this->max_size_ = s.size (); 00100 } 00101 else 00102 { 00103 ACE_DES_ARRAY_NOFREE (this->array_, 00104 s.size (), 00105 T); 00106 } 00107 00108 this->cur_size_ = s.size (); 00109 00110 for (size_t i = 0; i < this->size (); i++) 00111 new (&this->array_[i]) T (s.array_[i]); 00112 } 00113 } |
|
Get item in the array at location . Doesn't perform range checking. Definition at line 43 of file Array_Base.inl. References ACE_Array_Base< T >::array_.
00044 { 00045 return this->array_[index]; 00046 } |
|
Set item in the array at location . Doesn't perform range checking. Definition at line 37 of file Array_Base.inl. References ACE_Array_Base< T >::array_.
00038 { 00039 return this->array_[index]; 00040 } |
|
Set an item in the array at location . Returns -1 if is not in range, else returns 0. Definition at line 118 of file Array_Base.cpp. References ACE_Array_Base< T >::array_, and ACE_Array_Base< T >::in_range(). Referenced by ACE_DLL_Handle::get_dll_names(), and ACE_DLL_Handle::open().
|
|
Changes the size of the array to match . It copies the old contents into the new array. Return -1 on failure. Definition at line 176 of file Array_Base.cpp. References ACE_Array_Base< T >::cur_size_, and ACE_Array_Base< T >::max_size().
|
|
Returns the of the array.
Reimplemented in ACE_Vector< T, DEFAULT_SIZE >. Definition at line 19 of file Array_Base.inl. References ACE_Array_Base< T >::cur_size_. Referenced by ACE_Array_Base< T >::ACE_Array_Base(), ACE_DLL_Handle::get_dll_names(), ACE_DLL_Handle::open(), ACE_Array_Base< T >::operator=(), ACE_Array< T >::operator==(), ACE_Vector< T, DEFAULT_SIZE >::push_back(), and ACE_Vector< T, DEFAULT_SIZE >::resize().
00020 { 00021 return this->cur_size_; 00022 } |
|
Definition at line 146 of file Array_Base.h. |
|
Allocation strategy of the ACE_Array_Base.
Definition at line 144 of file Array_Base.h. |
|
Pointer to the array's storage buffer.
Definition at line 141 of file Array_Base.h. Referenced by ACE_Array_Base< T >::ACE_Array_Base(), ACE_Array_Base< T >::get(), ACE_Array_Base< T >::max_size(), ACE_Array_Base< T >::operator=(), ACE_Array_Base< T >::operator[](), and ACE_Array_Base< T >::set(). |
|
Current size of the array. This starts out being == to . However, if we are assigned a smaller array, then will become less than . The purpose of keeping track of both sizes is to avoid reallocating memory if we don't have to. Definition at line 138 of file Array_Base.h. Referenced by ACE_Array_Base< T >::in_range(), ACE_Array_Base< T >::max_size(), ACE_Array_Base< T >::operator=(), and ACE_Array_Base< T >::size(). |
|
Maximum size of the array, i.e., the total number of elements in . Definition at line 129 of file Array_Base.h. Referenced by ACE_Array_Base< T >::max_size(), and ACE_Array_Base< T >::operator=(). |