#include <Array_Base.h>
Inheritance diagram for ACE_Array_Base< T >:
Public Types | |
typedef T | TYPE |
typedef ACE_Array_Iterator< T > | ITERATOR |
typedef T | value_type |
typedef value_type * | iterator |
typedef value_type const * | const_iterator |
typedef value_type & | reference |
typedef value_type const & | const_reference |
typedef value_type * | pointer |
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_type * | 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 43 of file Array_Base.h.
typedef value_type const* ACE_Array_Base< T >::const_iterator |
Definition at line 54 of file Array_Base.h.
typedef value_type const* ACE_Array_Base< T >::const_pointer |
Definition at line 58 of file Array_Base.h.
typedef value_type const& ACE_Array_Base< T >::const_reference |
Definition at line 56 of file Array_Base.h.
typedef ptrdiff_t ACE_Array_Base< T >::difference_type |
Definition at line 59 of file Array_Base.h.
typedef value_type* ACE_Array_Base< T >::iterator |
Definition at line 53 of file Array_Base.h.
typedef ACE_Array_Iterator<T> ACE_Array_Base< T >::ITERATOR |
Reimplemented in ACE_Array< T >, ACE_Array< ACE_Get_Opt::ACE_Get_Opt_Long_Option * >, and ACE_Array< ACE_INET_Addr >.
Definition at line 49 of file Array_Base.h.
typedef value_type* ACE_Array_Base< T >::pointer |
Definition at line 57 of file Array_Base.h.
typedef value_type& ACE_Array_Base< T >::reference |
Definition at line 55 of file Array_Base.h.
typedef ACE_Allocator::size_type ACE_Array_Base< T >::size_type |
Definition at line 60 of file Array_Base.h.
typedef T ACE_Array_Base< T >::TYPE |
Reimplemented in ACE_Array< T >, ACE_Array< ACE_Get_Opt::ACE_Get_Opt_Long_Option * >, and ACE_Array< ACE_INET_Addr >.
Definition at line 48 of file Array_Base.h.
typedef T ACE_Array_Base< T >::value_type |
Definition at line 52 of file Array_Base.h.
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.
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>.
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.
References ACE_ALLOCATOR, ACE_Array_Base< T >::allocator_, ACE_Array_Base< T >::array_, ACE_Allocator::instance(), and ACE_Array_Base< T >::size().
00071 : max_size_ (s.size ()), 00072 cur_size_ (s.size ()), 00073 allocator_ (s.allocator_) 00074 { 00075 if (this->allocator_ == 0) 00076 this->allocator_ = ACE_Allocator::instance (); 00077 00078 ACE_ALLOCATOR (this->array_, 00079 (T *) this->allocator_->malloc (s.size () * sizeof (T))); 00080 for (size_type i = 0; i < this->size (); ++i) 00081 new (&this->array_[i]) T (s.array_[i]); 00082 }
ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_Array_Base< T >::~ACE_Array_Base | ( | void | ) |
Clean up the array (e.g., delete dynamically allocated memory).
Definition at line 9 of file Array_Base.inl.
References ACE_DES_ARRAY_FREE.
00010 { 00011 ACE_DES_ARRAY_FREE (this->array_, 00012 this->max_size_, 00013 this->allocator_->free, 00014 T); 00015 }
ACE_INLINE ACE_Array_Base< T >::const_iterator ACE_Array_Base< T >::begin | ( | void | ) | const |
Definition at line 33 of file Array_Base.inl.
References ACE_Array_Base< T >::array_.
00034 { 00035 return this->array_; 00036 }
ACE_INLINE ACE_Array_Base< T >::iterator ACE_Array_Base< T >::begin | ( | void | ) |
Definition at line 19 of file Array_Base.inl.
References ACE_Array_Base< T >::array_.
Referenced by ACE_Select_Reactor_Handler_Repository::unbind_all().
00020 { 00021 return this->array_; 00022 }
ACE_INLINE ACE_Array_Base< T >::const_iterator ACE_Array_Base< T >::end | ( | void | ) | const |
Definition at line 40 of file Array_Base.inl.
References ACE_Array_Base< T >::array_, and ACE_Array_Base< T >::cur_size_.
ACE_INLINE ACE_Array_Base< T >::iterator ACE_Array_Base< T >::end | ( | void | ) |
Definition at line 26 of file Array_Base.inl.
References ACE_Array_Base< T >::array_, and ACE_Array_Base< T >::cur_size_.
Referenced by ACE_Select_Reactor_Handler_Repository::unbind(), and ACE_Select_Reactor_Handler_Repository::unbind_all().
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.
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.
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
ACE_INLINE ACE_Array_Base< T >::size_type ACE_Array_Base< T >::max_size | ( | void | ) | const |
Returns the <max_size_> of the array.
Definition at line 80 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(), and ACE_Vector< T, DEFAULT_SIZE >::push_back().
00081 { 00082 return this->max_size_; 00083 }
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.
References ACE_DES_ARRAY_NOFREE, ACE_Array_Base< T >::array_, ACE_Array_Base< T >::cur_size_, ACE_Array_Base< T >::size(), and ACE_Array_Base< T >::swap().
Referenced by ACE_Array< T >::operator=().
00088 { 00089 // Check for "self-assignment". 00090 00091 if (this != &s) 00092 { 00093 if (this->max_size_ < s.size ()) 00094 { 00095 // Need to reallocate memory. 00096 00097 // Strongly exception-safe assignment. 00098 // 00099 // Note that we're swapping the allocators here, too. 00100 // Should we? Probably. "*this" should be a duplicate of 00101 // the "right hand side". 00102 ACE_Array_Base<T> tmp (s); 00103 this->swap (tmp); 00104 } 00105 else 00106 { 00107 // Underlying array is large enough. No need to reallocate 00108 // memory. 00109 // 00110 // "*this" still owns the memory for the underlying array. 00111 // Do not swap out the allocator. 00112 // 00113 // @@ Why don't we just drop the explicit destructor and 00114 // placement operator new() calls with a straight 00115 // element-by-element assignment? Is the existing 00116 // approach more efficient? 00117 // -Ossama 00118 00119 ACE_DES_ARRAY_NOFREE (this->array_, 00120 s.size (), 00121 T); 00122 00123 this->cur_size_ = s.size (); 00124 00125 for (size_type i = 0; i < this->size (); ++i) 00126 new (&this->array_[i]) T (s.array_[i]); 00127 } 00128 } 00129 }
T const& ACE_Array_Base< T >::operator[] | ( | size_type | slot | ) | const |
Get item in the array at location slot. Doesn't perform range checking.
T& ACE_Array_Base< T >::operator[] | ( | size_type | slot | ) |
Set item in the array at location slot. Doesn't perform range checking.
ACE_INLINE ACE_Array_Base< T >::const_reverse_iterator ACE_Array_Base< T >::rbegin | ( | void | ) | const |
ACE_INLINE ACE_Array_Base< T >::reverse_iterator ACE_Array_Base< T >::rbegin | ( | void | ) |
ACE_INLINE ACE_Array_Base< T >::const_reverse_iterator ACE_Array_Base< T >::rend | ( | void | ) | const |
ACE_INLINE ACE_Array_Base< T >::reverse_iterator ACE_Array_Base< T >::rend | ( | void | ) |
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.
Referenced by ACE_DLL_Handle::get_dll_names(), and ACE_DLL_Handle::open().
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.
ACE_INLINE ACE_Array_Base< T >::size_type ACE_Array_Base< T >::size | ( | void | ) | const |
Returns the <cur_size_> of the array.
Reimplemented in ACE_Vector< T, DEFAULT_SIZE >.
Definition at line 74 of file Array_Base.inl.
References ACE_Array_Base< T >::cur_size_.
Referenced by ACE_Array_Base< T >::ACE_Array_Base(), ACE_Multihomed_INET_Addr::ACE_Multihomed_INET_Addr(), ACE_Multihomed_INET_Addr::get_addresses(), ACE_DLL_Handle::get_dll_names(), ACE_Multihomed_INET_Addr::get_num_secondary_addresses(), ACE_Multihomed_INET_Addr::get_secondary_addresses(), ACE_DLL_Handle::open(), ACE_Array_Base< T >::operator=(), ACE_Array< T >::operator==(), ACE_Vector< T, DEFAULT_SIZE >::pop_back(), ACE_Vector< T, DEFAULT_SIZE >::push_back(), ACE_Vector< T, DEFAULT_SIZE >::resize(), ACE_Multihomed_INET_Addr::set(), ACE_Multihomed_INET_Addr::set_port_number(), and ACE_Select_Reactor_Handler_Repository::size().
00075 { 00076 return this->cur_size_; 00077 }
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.
References ACE_Array_Base< T >::allocator_, ACE_Array_Base< T >::array_, ACE_Array_Base< T >::cur_size_, and ACE_Array_Base< T >::max_size_.
Referenced by ACE_Array_Base< T >::operator=(), and ACE_Vector< T, DEFAULT_SIZE >::swap().
00207 { 00208 std::swap (this->max_size_ , rhs.max_size_); 00209 std::swap (this->cur_size_ , rhs.cur_size_); 00210 std::swap (this->array_ , rhs.array_); 00211 std::swap (this->allocator_, rhs.allocator_); 00212 }
friend class ACE_Array_Iterator< T > [friend] |
Definition at line 191 of file Array_Base.h.
ACE_Allocator* ACE_Array_Base< T >::allocator_ [protected] |
Allocation strategy of the ACE_Array_Base.
Definition at line 189 of file Array_Base.h.
Referenced by ACE_Array_Base< T >::ACE_Array_Base(), and ACE_Array_Base< T >::swap().
value_type* ACE_Array_Base< T >::array_ [protected] |
Pointer to the array's storage buffer.
Definition at line 186 of file Array_Base.h.
Referenced by ACE_Array_Base< T >::ACE_Array_Base(), ACE_Array_Base< T >::begin(), ACE_Array_Base< T >::end(), ACE_Array_Base< T >::operator=(), and ACE_Array_Base< T >::swap().
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.
Referenced by ACE_Array_Base< T >::end(), ACE_Array_Base< T >::operator=(), ACE_Array_Base< T >::size(), and ACE_Array_Base< T >::swap().
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.
Referenced by ACE_Array_Base< T >::max_size(), and ACE_Array_Base< T >::swap().