diff options
author | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-07-01 14:03:46 +0000 |
---|---|---|
committer | parsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-07-01 14:03:46 +0000 |
commit | 01809ab09a0859a7dc64e522d563023d6e3f6f40 (patch) | |
tree | 58d906c92639203a6a5645f685d67830e3356265 /TAO/tao/Sequence_T.cpp | |
parent | 2a398e7caeaf541292a898ce494343a23039ee59 (diff) | |
download | ATCD-01809ab09a0859a7dc64e522d563023d6e3f6f40.tar.gz |
ChangeLogTag: Mon Jul 1 09:02:32 2002 Jeff Parsons <parsons@cs.wustl.edu>
Diffstat (limited to 'TAO/tao/Sequence_T.cpp')
-rw-r--r-- | TAO/tao/Sequence_T.cpp | 660 |
1 files changed, 557 insertions, 103 deletions
diff --git a/TAO/tao/Sequence_T.cpp b/TAO/tao/Sequence_T.cpp index f22c7350642..dece80234c5 100644 --- a/TAO/tao/Sequence_T.cpp +++ b/TAO/tao/Sequence_T.cpp @@ -403,9 +403,88 @@ TAO_Pseudo_Object_Manager<T,T_var>::operator=(const T_var &p) // class TAO_Valuetype_Manager // ************************************************************* -template <class T, class T_var> TAO_Valuetype_Manager<T,T_var>& -TAO_Valuetype_Manager<T,T_var>:: - operator= (const TAO_Valuetype_Manager<T,T_var> &rhs) +template <class T, class T_var> +TAO_Valuetype_Manager<T,T_var> & +TAO_Valuetype_Manager<T,T_var>::operator= ( + const TAO_Valuetype_Manager<T,T_var> &rhs + ) +{ + if (this == &rhs) + { + return *this; + } + + if (this->release_) + { + T_var::tao_remove_ref (*this->ptr_); + *this->ptr_ = *rhs.ptr_; + T_var::tao_add_ref (*this->ptr_); + } + else + { + *this->ptr_ = *rhs.ptr_; + } + + return *this; +} + +template <class T, class T_var> +TAO_Valuetype_Manager<T,T_var> & +TAO_Valuetype_Manager<T,T_var>::operator= (T *p) +{ + if (this->release_) + { + // The semantics of the elements of a sequence are the same as + // that of a var variable. Therefore we will not duplicate the + // user provided pointer before assigning it to the internal + // variable. + T_var::tao_remove_ref (*this->ptr_); + *this->ptr_ = p; + } + else + { + *this->ptr_ = p; + } + + return *this; +} + +template <class T, class T_var> +TAO_Valuetype_Manager<T,T_var> & +TAO_Valuetype_Manager<T,T_var>::operator= (const T_var &p) +{ + if (this->release_) + { + // The semantics of the elements of a sequence are the same as + // that of a var variable. Therefore we duplicate p's + // pointer before assigning it to the internal + // variable. + if (*this->ptr_ != 0) + { + (*this->ptr_)->_remove_ref (); + } + + T_var::tao_remove_ref (*this->ptr_); + *this->ptr_ = p.in (); + T_var::tao_add_ref (*this->ptr_); + } + else + { + *this->ptr_ = p.in (); + } + + return *this; +} + +// ************************************************************* +// class TAO_Abstract_Manager +// ************************************************************* + +template <class T, class T_var> +TAO_Abstract_Manager<T,T_var> & +TAO_Abstract_Manager<T,T_var>::operator= ( + const TAO_Abstract_Manager<T,T_var> &rhs + ) { if (this == &rhs) { @@ -434,8 +513,9 @@ TAO_Valuetype_Manager<T,T_var>:: return *this; } -template <class T, class T_var>TAO_Valuetype_Manager<T,T_var> & -TAO_Valuetype_Manager<T,T_var>::operator=(T* p) +template <class T, class T_var> +TAO_Abstract_Manager<T,T_var> & +TAO_Abstract_Manager<T,T_var>::operator= (T *p) { if (this->release_) { @@ -458,8 +538,9 @@ TAO_Valuetype_Manager<T,T_var>::operator=(T* p) return *this; } -template <class T, class T_var>TAO_Valuetype_Manager<T,T_var> & -TAO_Valuetype_Manager<T,T_var>::operator=(const T_var &p) +template <class T, class T_var> +TAO_Abstract_Manager<T,T_var> & +TAO_Abstract_Manager<T,T_var>::operator= (const T_var &p) { if (this->release_) { @@ -1278,37 +1359,33 @@ TAO_Bounded_Pseudo_Sequence<T, T_var,MAX>::_shrink_buffer (CORBA::ULong nl, // Constructor for unbounded sequence. template <class T, class T_var> -TAO_Unbounded_Valuetype_Sequence<T,T_var>::TAO_Unbounded_Valuetype_Sequence ( +TAO_Unbounded_Valuetype_Sequence<T, T_var>::TAO_Unbounded_Valuetype_Sequence ( CORBA::ULong maximum ) : TAO_Unbounded_Base_Sequence ( maximum, - TAO_Unbounded_Valuetype_Sequence<T,T_var>::allocbuf (maximum) + TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (maximum) ) { } template <class T, class T_var> -TAO_Unbounded_Valuetype_Sequence<T,T_var>::TAO_Unbounded_Valuetype_Sequence ( - const TAO_Unbounded_Valuetype_Sequence<T,T_var> &rhs +TAO_Unbounded_Valuetype_Sequence<T, T_var>::TAO_Unbounded_Valuetype_Sequence ( + const TAO_Unbounded_Valuetype_Sequence<T, T_var> &rhs ) : TAO_Unbounded_Base_Sequence (rhs) { if (rhs.buffer_ != 0) { T **tmp1 = - TAO_Unbounded_Valuetype_Sequence<T,T_var>::allocbuf (this->maximum_); + TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (this->maximum_); T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, rhs.buffer_); for (CORBA::ULong i = 0; i < rhs.length_; ++i) { - if (tmp2[i] != 0) - { - tmp2[i]->_add_ref (); - } - + T_var::tao_add_ref (tmp2[i]); tmp1[i] = tmp2[i]; } @@ -1321,15 +1398,18 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::TAO_Unbounded_Valuetype_Sequence ( } template<class T, class T_var> -TAO_Unbounded_Valuetype_Sequence<T,T_var>::~TAO_Unbounded_Valuetype_Sequence (void) +TAO_Unbounded_Valuetype_Sequence<T, T_var>::~TAO_Unbounded_Valuetype_Sequence ( + void + ) { this->_deallocate_buffer (); } // assignment operator -template <class T, class T_var>TAO_Unbounded_Valuetype_Sequence<T,T_var>& -TAO_Unbounded_Valuetype_Sequence<T,T_var>::operator= ( - const TAO_Unbounded_Valuetype_Sequence<T,T_var> &rhs +template <class T, class T_var> +TAO_Unbounded_Valuetype_Sequence<T, T_var>& +TAO_Unbounded_Valuetype_Sequence<T, T_var>::operator= ( + const TAO_Unbounded_Valuetype_Sequence<T, T_var> &rhs ) { if (this == &rhs) @@ -1344,19 +1424,15 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::operator= ( for (CORBA::ULong i = 0; i < this->length_; ++i) { - if (tmp[i] != 0) - { - tmp[i]->_remove_ref (); - } - + T_var::tao_remove_ref (tmp[i]); tmp[i] = 0; } if (this->maximum_ < rhs.maximum_) { - TAO_Unbounded_Valuetype_Sequence<T,T_var>::freebuf (tmp); + TAO_Unbounded_Valuetype_Sequence<T, T_var>::freebuf (tmp); this->buffer_ = - TAO_Unbounded_Valuetype_Sequence<T,T_var>::allocbuf (rhs.maximum_); + TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (rhs.maximum_); } } else @@ -1368,7 +1444,9 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::operator= ( else { this->buffer_ = - TAO_Unbounded_Valuetype_Sequence<T,T_var>::allocbuf (rhs.maximum_); + TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf ( + rhs.maximum_ + ); } } @@ -1381,19 +1459,16 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::operator= ( for (CORBA::ULong i = 0; i < rhs.length_; ++i) { - if (tmp2[i] != 0) - { - tmp2[i]->_add_ref (); - } - + T_var::tao_add_ref (tmp2[i]); tmp1[i] = tmp2[i]; } return *this; } -template <class T, class T_var> T ** -TAO_Unbounded_Valuetype_Sequence<T,T_var>::allocbuf (CORBA::ULong nelems) +template <class T, class T_var> +T ** +TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (CORBA::ULong nelems) { T **buf = 0; ACE_NEW_RETURN (buf, @@ -1408,8 +1483,9 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::allocbuf (CORBA::ULong nelems) return buf; } -template <class T, class T_var> void -TAO_Unbounded_Valuetype_Sequence<T,T_var>::freebuf (T **buffer) +template <class T, class T_var> +void +TAO_Unbounded_Valuetype_Sequence<T, T_var>::freebuf (T **buffer) { if (buffer == 0) { @@ -1431,10 +1507,13 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::freebuf (T **buffer) delete [] buffer; } -template<class T, class T_var> void -TAO_Unbounded_Valuetype_Sequence<T,T_var>::_allocate_buffer (CORBA::ULong length) +template<class T, class T_var> +void +TAO_Unbounded_Valuetype_Sequence<T, T_var>::_allocate_buffer ( + CORBA::ULong length + ) { - T **tmp = TAO_Unbounded_Valuetype_Sequence<T,T_var>::allocbuf (length); + T **tmp = TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (length); if (this->buffer_ != 0) { @@ -1449,11 +1528,7 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::_allocate_buffer (CORBA::ULong length // the old instances. if (!this->release_) { - if (old[i] != 0) - { - old[i]->_add_ref (); - } - + T_var::tao_add_ref (tmp[i]); tmp[i] = old[i]; } else @@ -1466,11 +1541,12 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::_allocate_buffer (CORBA::ULong length delete [] old; } } + this->buffer_ = tmp; } template<class T, class T_var> void -TAO_Unbounded_Valuetype_Sequence<T,T_var>::_deallocate_buffer (void) +TAO_Unbounded_Valuetype_Sequence<T, T_var>::_deallocate_buffer (void) { if (this->buffer_ == 0 || this->release_ == 0) { @@ -1482,32 +1558,24 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::_deallocate_buffer (void) for (CORBA::ULong i = 0; i < this->length_; ++i) { - if (tmp[i] != 0) - { - tmp[i]->_remove_ref (); - } - + T_var::tao_remove_ref (tmp[i]); tmp[i] = 0; } - TAO_Unbounded_Valuetype_Sequence<T,T_var>::freebuf (tmp); + TAO_Unbounded_Valuetype_Sequence<T, T_var>::freebuf (tmp); this->buffer_ = 0; } template<class T, class T_var> void -TAO_Unbounded_Valuetype_Sequence<T,T_var>::_shrink_buffer (CORBA::ULong nl, - CORBA::ULong ol) +TAO_Unbounded_Valuetype_Sequence<T ,T_var>::_shrink_buffer (CORBA::ULong nl, + CORBA::ULong ol) { T **tmp = ACE_static_cast (T**, this->buffer_); for (CORBA::ULong i = nl; i < ol; ++i) { - if (tmp[i] != 0) - { - tmp[i]->_remove_ref (); - } - + T_var::tao_remove_ref (tmp[i]); tmp[i] = 0; } } @@ -1517,37 +1585,33 @@ TAO_Unbounded_Valuetype_Sequence<T,T_var>::_shrink_buffer (CORBA::ULong nl, // ************************************************************* template <class T, class T_var, size_t MAX> -TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::TAO_Bounded_Valuetype_Sequence ( +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::TAO_Bounded_Valuetype_Sequence ( void ) : TAO_Bounded_Base_Sequence ( MAX, - TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::allocbuf (MAX) + TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::allocbuf (MAX) ) { } template <class T, class T_var, size_t MAX> -TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::TAO_Bounded_Valuetype_Sequence ( - const TAO_Bounded_Valuetype_Sequence<T, T_var,MAX> &rhs +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::TAO_Bounded_Valuetype_Sequence ( + const TAO_Bounded_Valuetype_Sequence<T, T_var, MAX> &rhs ) : TAO_Bounded_Base_Sequence (rhs) { if (rhs.buffer_ != 0) { T **tmp1 = - TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::allocbuf (MAX); + TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::allocbuf (MAX); T ** const tmp2 = ACE_reinterpret_cast (T** ACE_CAST_CONST, rhs.buffer_); for (CORBA::ULong i = 0; i < rhs.length_; i++) { - if (tmp2[i] != 0) - { - tmp2[i]->_add_ref (); - } - + T_var::tao_add_ref (tmp2[i]); tmp1[i] = tmp2[i]; } @@ -1559,9 +1623,10 @@ TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::TAO_Bounded_Valuetype_Sequence ( } } -template <class T, class T_var, size_t MAX> TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>& -TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::operator= ( - const TAO_Bounded_Valuetype_Sequence<T,T_var, MAX> &rhs +template <class T, class T_var, size_t MAX> +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>& +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::operator= ( + const TAO_Bounded_Valuetype_Sequence<T, T_var, MAX> &rhs ) { if (this == &rhs) @@ -1576,11 +1641,7 @@ TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::operator= ( for (CORBA::ULong i = 0; i < this->length_; ++i) { - if (tmp[i] != 0) - { - tmp[i]->_remove_ref (); - } - + T_var::tao_remove_ref (tmp[i]); tmp[i] = 0; } // No need to reallocate the buffer since it is always of size @@ -1595,7 +1656,9 @@ TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::operator= ( else { this->buffer_ = - TAO_Bounded_Valuetype_Sequence<T,T_var,MAX>::allocbuf (rhs.maximum_); + TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::allocbuf ( + rhs.maximum_ + ); } } @@ -1608,19 +1671,16 @@ TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::operator= ( for (CORBA::ULong i=0; i < rhs.length_; ++i) { - if (tmp2[i] != 0) - { - tmp2[i]->_add_ref (); - } - + T_var::tao_add_ref (tmp2[i]); tmp1[i] = tmp2[i]; } return *this; } -template <class T, class T_var, size_t MAX> T ** -TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::allocbuf (CORBA::ULong) +template <class T, class T_var, size_t MAX> +T ** +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::allocbuf (CORBA::ULong) { T **buf = 0; ACE_NEW_RETURN (buf, @@ -1635,8 +1695,9 @@ TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::allocbuf (CORBA::ULong) return buf; } -template <class T, class T_var, size_t MAX> void -TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::freebuf (T **buffer) +template <class T, class T_var, size_t MAX> +void +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::freebuf (T **buffer) { // How much do we deallocate? Easy! allocbuf() always creates MAX // elements and initialize them to T::_nil(). So we can be @@ -1645,11 +1706,7 @@ TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::freebuf (T **buffer) { if (buffer[i] != 0) { - if (buffer[i] != 0) - { - buffer[i]->_remove_ref (); - } - + T_var::tao_remove_ref (buffer[i]); buffer[i] = 0; } } @@ -1657,19 +1714,21 @@ TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::freebuf (T **buffer) delete [] buffer; } -template<class T, class T_var, size_t MAX> void -TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::_allocate_buffer ( +template<class T, class T_var, size_t MAX> +void +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::_allocate_buffer ( CORBA::ULong length ) { // For this class memory is never reallocated so the implementation // is *really* simple. this->buffer_ = - TAO_Bounded_Valuetype_Sequence<T, T_var,MAX>::allocbuf (length); + TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::allocbuf (length); } -template<class T, class T_var, size_t MAX> void -TAO_Bounded_Valuetype_Sequence<T,T_var,MAX>::_deallocate_buffer (void) +template<class T, class T_var, size_t MAX> +void +TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::_deallocate_buffer (void) { if (this->release_ == 0) { @@ -1678,11 +1737,12 @@ TAO_Bounded_Valuetype_Sequence<T,T_var,MAX>::_deallocate_buffer (void) T **tmp = ACE_reinterpret_cast (T **, this->buffer_); - TAO_Bounded_Valuetype_Sequence<T,T_var,MAX>::freebuf (tmp); + TAO_Bounded_Valuetype_Sequence<T, T_var, MAX>::freebuf (tmp); this->buffer_ = 0; } -template<class T, class T_var, size_t MAX> void +template<class T, class T_var, size_t MAX> +void TAO_Bounded_Valuetype_Sequence<T,T_var, MAX>::_shrink_buffer (CORBA::ULong nl, CORBA::ULong ol) { @@ -1691,12 +1751,406 @@ TAO_Bounded_Valuetype_Sequence<T,T_var, MAX>::_shrink_buffer (CORBA::ULong nl, for (CORBA::ULong i = nl; i < ol; ++i) { - if (tmp[i] != 0) + T_var::tao_remove_ref (tmp[i]); + tmp[i] = 0; + } +} + +// ************************************************************* +// Operations for class TAO_Unbounded_Abstract_Sequence +// ************************************************************* + +// Constructor for unbounded sequence. +template <class T, class T_var> +TAO_Unbounded_Abstract_Sequence<T, T_var>::TAO_Unbounded_Abstract_Sequence ( + CORBA::ULong maximum + ) + : TAO_Unbounded_Base_Sequence ( + maximum, + TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (maximum) + ) +{ +} + +template <class T, class T_var> +TAO_Unbounded_Abstract_Sequence<T, T_var>::TAO_Unbounded_Abstract_Sequence ( + const TAO_Unbounded_Abstract_Sequence<T, T_var> &rhs + ) + : TAO_Unbounded_Base_Sequence (rhs) +{ + if (rhs.buffer_ != 0) + { + T **tmp1 = + TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (this->maximum_); + T ** const tmp2 = + ACE_reinterpret_cast (T ** ACE_CAST_CONST, + rhs.buffer_); + + for (CORBA::ULong i = 0; i < rhs.length_; ++i) { - tmp[i]->_remove_ref (); + tmp1[i] = T_var::tao_duplicate (tmp2[i]); } - tmp[i] = 0; + this->buffer_ = tmp1; + } + else + { + this->buffer_ = 0; + } +} + +template<class T, class T_var> +TAO_Unbounded_Abstract_Sequence<T, T_var>::~TAO_Unbounded_Abstract_Sequence ( + void + ) +{ + this->_deallocate_buffer (); +} + +// assignment operator +template <class T, class T_var> +TAO_Unbounded_Abstract_Sequence<T, T_var>& +TAO_Unbounded_Abstract_Sequence<T, T_var>::operator= ( + const TAO_Unbounded_Abstract_Sequence<T, T_var> &rhs + ) +{ + if (this == &rhs) + { + return *this; + } + + if (this->release_) + { + T **tmp = ACE_reinterpret_cast (T **, + this->buffer_); + + for (CORBA::ULong i = 0; i < this->length_; ++i) + { + T_var::tao_release (tmp[i]); + tmp[i] = T_var::tao_nil (); + } + + if (this->maximum_ < rhs.maximum_) + { + TAO_Unbounded_Abstract_Sequence<T, T_var>::freebuf (tmp); + this->buffer_ = + TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (rhs.maximum_); + } + } + else + { + if (rhs.maximum_ == 0) + { + this->buffer_ = 0; + } + else + { + this->buffer_ = + TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf ( + rhs.maximum_ + ); + } + } + + TAO_Unbounded_Base_Sequence::operator= (rhs); + + T **tmp1 = ACE_reinterpret_cast (T **, + this->buffer_); + T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, + rhs.buffer_); + + for (CORBA::ULong i = 0; i < rhs.length_; ++i) + { + tmp1[i] = T_var::tao_duplicate (tmp2[i]); + } + + return *this; +} + +template <class T, class T_var> +T ** +TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (CORBA::ULong nelems) +{ + T **buf = 0; + ACE_NEW_RETURN (buf, + T*[nelems], + 0); + + for (CORBA::ULong i = 0; i < nelems; i++) + { + buf[i] = T_var::tao_nil (); + } + + return buf; +} + +template <class T, class T_var> +void +TAO_Unbounded_Abstract_Sequence<T, T_var>::freebuf (T **buffer) +{ + if (buffer == 0) + { + return; + } + + // {orbos/97-05-15:16.11} The freebuf function ensures that the + // destructor for each element is called before the buffer is + // destroyed, except for string elements, which are freed using + // string_free(), and object reference elements, which are freed + // using release(). The freebuf function will ignore null pointers + // passed to it. + + // @@ How are we supposed to implement that! We don't know the + // length of the buffer here. + // Mark the length in the first four bytes? For the moment we let + // that be. + + delete [] buffer; +} + +template<class T, class T_var> +void +TAO_Unbounded_Abstract_Sequence<T, T_var>::_allocate_buffer ( + CORBA::ULong length + ) +{ + T **tmp = TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (length); + + if (this->buffer_ != 0) + { + T **old = ACE_reinterpret_cast (T**, + this->buffer_); + + for (CORBA::ULong i = 0; i < this->length_; ++i) + // Only call duplicate when we did not own the previous + // buffer, since after this method we own it we must also own + // the objects. If we already own the objects there is no + // need to copy them, if we did we would also have to remove + // the old instances. + if (!this->release_) + { + tmp[i] = T_var::tao_duplicate (old[i]); + } + else + { + tmp[i] = old[i]; + } + + if (this->release_) + { + delete [] old; + } + } + + this->buffer_ = tmp; +} + +template<class T, class T_var> void +TAO_Unbounded_Abstract_Sequence<T, T_var>::_deallocate_buffer (void) +{ + if (this->buffer_ == 0 || this->release_ == 0) + { + return; + } + + T **tmp = ACE_reinterpret_cast (T**, + this->buffer_); + + for (CORBA::ULong i = 0; i < this->length_; ++i) + { + T_var::tao_release (tmp[i]); + tmp[i] = T_var::tao_nil (); + } + + TAO_Unbounded_Abstract_Sequence<T, T_var>::freebuf (tmp); + this->buffer_ = 0; +} + +template<class T, class T_var> void +TAO_Unbounded_Abstract_Sequence<T ,T_var>::_shrink_buffer (CORBA::ULong nl, + CORBA::ULong ol) +{ + T **tmp = ACE_static_cast (T**, + this->buffer_); + + for (CORBA::ULong i = nl; i < ol; ++i) + { + T_var::tao_release (tmp[i]); + tmp[i] = T_var::tao_nil (); + } +} + +// ************************************************************* +// Operations for class TAO_Bounded_Abstract_Sequence +// ************************************************************* + +template <class T, class T_var, size_t MAX> +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::TAO_Bounded_Abstract_Sequence ( + void + ) + : TAO_Bounded_Base_Sequence ( + MAX, + TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (MAX) + ) +{ +} + +template <class T, class T_var, size_t MAX> +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::TAO_Bounded_Abstract_Sequence ( + const TAO_Bounded_Abstract_Sequence<T, T_var, MAX> &rhs + ) + : TAO_Bounded_Base_Sequence (rhs) +{ + if (rhs.buffer_ != 0) + { + T **tmp1 = + TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (MAX); + + T ** const tmp2 = + ACE_reinterpret_cast (T** ACE_CAST_CONST, rhs.buffer_); + + for (CORBA::ULong i = 0; i < rhs.length_; i++) + { + tmp1[i] = T_var::tao_duplicate (tmp2[i]); + } + + this->buffer_ = tmp1; + } + else + { + this->buffer_ = 0; + } +} + +template <class T, class T_var, size_t MAX> +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>& +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::operator= ( + const TAO_Bounded_Abstract_Sequence<T, T_var, MAX> &rhs + ) +{ + if (this == &rhs) + { + return *this; + } + + if (this->release_) + { + T **tmp = ACE_reinterpret_cast (T **, + this->buffer_); + + for (CORBA::ULong i = 0; i < this->length_; ++i) + { + T_var::tao_release (tmp[i]); + tmp[i] = T_var::tao_nil (); + } + // No need to reallocate the buffer since it is always of size + // MAX + } + else + { + if (rhs.maximum_ == 0) + { + this->buffer_ = 0; + } + else + { + this->buffer_ = + TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf ( + rhs.maximum_ + ); + } + } + + TAO_Bounded_Base_Sequence::operator= (rhs); + + T **tmp1 = ACE_reinterpret_cast (T **, + this->buffer_); + T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, + rhs.buffer_); + + for (CORBA::ULong i=0; i < rhs.length_; ++i) + { + tmp1[i] = T_var::tao_duplicate (tmp2[i]); + } + + return *this; +} + +template <class T, class T_var, size_t MAX> +T ** +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (CORBA::ULong) +{ + T **buf = 0; + ACE_NEW_RETURN (buf, + T*[MAX], + 0); + + for (CORBA::ULong i = 0; i < MAX; ++i) + { + buf[i] = T_var::tao_nil (); + } + + return buf; +} + +template <class T, class T_var, size_t MAX> +void +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::freebuf (T **buffer) +{ + // How much do we deallocate? Easy! allocbuf() always creates MAX + // elements and initialize them to T::_nil(). So we can be + // complaint and call CORBA::release() on each one. + for (CORBA::ULong i = 0; i < MAX; ++i) + { + if (buffer[i] != T_var::tao_nil ()) + { + T_var::tao_release (buffer[i]); + buffer[i] = T_var::tao_nil (); + } + } + + delete [] buffer; +} + +template<class T, class T_var, size_t MAX> +void +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::_allocate_buffer ( + CORBA::ULong length + ) +{ + // For this class memory is never reallocated so the implementation + // is *really* simple. + this->buffer_ = + TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (length); +} + +template<class T, class T_var, size_t MAX> +void +TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::_deallocate_buffer (void) +{ + if (this->release_ == 0) + { + return; + } + + T **tmp = ACE_reinterpret_cast (T **, + this->buffer_); + TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::freebuf (tmp); + this->buffer_ = 0; +} + +template<class T, class T_var, size_t MAX> +void +TAO_Bounded_Abstract_Sequence<T,T_var, MAX>::_shrink_buffer (CORBA::ULong nl, + CORBA::ULong ol) +{ + T **tmp = ACE_reinterpret_cast (T **, + this->buffer_); + + for (CORBA::ULong i = nl; i < ol; ++i) + { + T_var::tao_release (tmp[i]); + tmp[i] = T_var::tao_nil (); } } |