#include <Array_Base.h>
Inheritance diagram for ACE_Array_Base:


Public Types | |
| typedef T | TYPE |
| typedef ACE_Array_Iterator< T > | ITERATOR |
Public Methods | |
| ACE_Array_Base (size_t size=0, ACE_Allocator *alloc=0) | |
| Dynamically create an uninitialized array. More... | |
| ACE_Array_Base (size_t size, const T &default_value, ACE_Allocator *alloc=0) | |
| Dynamically initialize the entire array to the <default_value>. More... | |
| 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). More... | |
| T & | operator[] (size_t slot) |
| Set item in the array at location <slot>. Doesn't perform range checking. More... | |
| const T & | operator[] (size_t slot) const |
| Get item in the array at location <slot>. Doesn't perform range checking. More... | |
| int | set (const T &new_item, size_t slot) |
| Set an item in the array at location <slot>. Returns -1 if <slot> is not in range, else returns 0. More... | |
| int | get (T &item, size_t slot) const |
| size_t | size (void) const |
| Returns the <cur_size_> of the array. More... | |
| int | size (size_t new_size) |
| size_t | max_size (void) const |
| Returns the <max_size_> of the array. More... | |
| int | max_size (size_t new_size) |
Private Methods | |
| int | in_range (size_t slot) const |
| Returns 1 if <slot> is within range, i.e., 0 >= <slot> < <cur_size_>, else returns 0. More... | |
Private Attributes | |
| size_t | max_size_ |
| Maximum size of the array, i.e., the total number of <T> elements in <array_>. More... | |
| size_t | cur_size_ |
| T * | array_ |
| Pointer to the array's storage buffer. More... | |
| ACE_Allocator * | allocator_ |
| Allocation strategy of the ACE_Array_Base. More... | |
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 41 of file Array_Base.h.
|
|||||
|
Reimplemented in ACE_Array. Definition at line 47 of file Array_Base.h. |
|
|||||
|
Reimplemented in ACE_Array. Definition at line 46 of file Array_Base.h. |
|
||||||||||||||||
|
Dynamically create an uninitialized array.
Definition at line 23 of file Array_Base.cpp. References ACE_ALLOCATOR, allocator_, array_, ACE_Allocator::instance, and size.
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 <default_value>.
Definition at line 44 of file Array_Base.cpp. References ACE_ALLOCATOR, allocator_, array_, ACE_Allocator::instance, and size.
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 <s>, i.e., *this == s will return true. Definition at line 68 of file Array_Base.cpp. References ACE_ALLOCATOR, allocator_, array_, ACE_Allocator::instance, and 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 7 of file Array_Base.inl. References ACE_DES_ARRAY_FREE.
00008 {
00009 ACE_DES_ARRAY_FREE (this->array_,
00010 this->max_size_,
00011 this->allocator_->free,
00012 T);
00013 }
|
|
||||||||||||||||
|
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. Definition at line 132 of file Array_Base.cpp. References array_, and in_range.
|
|
||||||||||
|
Returns 1 if <slot> is within range, i.e., 0 >= <slot> < <cur_size_>, else returns 0.
Definition at line 28 of file Array_Base.inl. References cur_size_.
00029 {
00030 return index < this->cur_size_;
00031 }
|
|
||||||||||
|
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 Definition at line 146 of file Array_Base.cpp. References ACE_ALLOCATOR_RETURN, ACE_DES_ARRAY_FREE, array_, cur_size_, and max_size_.
00147 {
00148 if (new_size > this->max_size_)
00149 {
00150 T *tmp;
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 <max_size_> of the array.
Definition at line 22 of file Array_Base.inl. References max_size_. Referenced by ACE_Vector::ACE_Vector, ACE_Vector::push_back, ACE_Vector::resize, and size.
00023 {
00024 return this->max_size_;
00025 }
|
|
||||||||||
|
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 85 of file Array_Base.cpp. References ACE_ALLOCATOR, ACE_DES_ARRAY_FREE, ACE_DES_ARRAY_NOFREE, array_, cur_size_, max_size_, and size. Referenced by ACE_Array::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 <slot>. Doesn't perform range checking.
Definition at line 40 of file Array_Base.inl. References array_.
00041 {
00042 return this->array_[index];
00043 }
|
|
||||||||||
|
Set item in the array at location <slot>. Doesn't perform range checking.
Definition at line 34 of file Array_Base.inl. References array_.
00035 {
00036 return this->array_[index];
00037 }
|
|
||||||||||||||||
|
Set an item in the array at location <slot>. Returns -1 if <slot> is not in range, else returns 0.
Definition at line 118 of file Array_Base.cpp. References array_, and in_range.
|
|
||||||||||
|
Changes the size of the array to match <new_size>. It copies the old contents into the new array. Return -1 on failure. Definition at line 176 of file Array_Base.cpp. References cur_size_, and max_size.
|
|
||||||||||
|
Returns the <cur_size_> of the array.
Reimplemented in ACE_Vector. Definition at line 16 of file Array_Base.inl. References cur_size_. Referenced by ACE_Array_Base, operator=, ACE_Array::operator==, ACE_Vector::push_back, and ACE_Vector::resize.
00017 {
00018 return this->cur_size_;
00019 }
|
|
|||||
|
Definition at line 147 of file Array_Base.h. |
|
|||||
|
Allocation strategy of the ACE_Array_Base.
Definition at line 145 of file Array_Base.h. Referenced by ACE_Array_Base. |
|
|||||
|
Pointer to the array's storage buffer.
Definition at line 142 of file Array_Base.h. Referenced by ACE_Array_Base, get, max_size, operator=, operator[], and set. |
|
|||||
|
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 139 of file Array_Base.h. |
|
|||||
|
Maximum size of the array, i.e., the total number of <T> elements in <array_>.
Definition at line 130 of file Array_Base.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002