From 4deaf37597910f07464d7b1b7b68011e70430816 Mon Sep 17 00:00:00 2001 From: parsons Date: Mon, 16 Aug 1999 19:56:59 +0000 Subject: (un)bounded wstring sequence classes. --- TAO/tao/Sequence_T.cpp | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) (limited to 'TAO/tao/Sequence_T.cpp') diff --git a/TAO/tao/Sequence_T.cpp b/TAO/tao/Sequence_T.cpp index 291aa27fb9b..7d068cfbc0a 100644 --- a/TAO/tao/Sequence_T.cpp +++ b/TAO/tao/Sequence_T.cpp @@ -1054,4 +1054,147 @@ TAO_Bounded_String_Sequence::_shrink_buffer (CORBA::ULong nl, } } +// ************************************************************* +// Operations for class TAO_Bounded_WString_Sequence +// ************************************************************* + +template +TAO_Bounded_WString_Sequence:: +TAO_Bounded_WString_Sequence (void) + : TAO_Bounded_Base_Sequence (MAX, + TAO_Bounded_String_WSequence::allocbuf(MAX)) +{ +} + +template +TAO_Bounded_WString_Sequence:: +TAO_Bounded_WString_Sequence (const TAO_Bounded_WString_Sequence &rhs) + : TAO_Bounded_Base_Sequence (rhs) +{ + CORBA::WChar **tmp1 = + TAO_Bounded_WString_Sequence::allocbuf (this->maximum_); + CORBA::WChar ** const tmp2 = + ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST, + rhs.buffer_); + + for (CORBA::ULong i=0; i < rhs.length_; i++) + tmp1[i] = CORBA::wstring_dup (tmp2[i]); + + this->buffer_ = tmp1; +} + +template TAO_Bounded_WString_Sequence& +TAO_Bounded_WString_Sequence::operator= +(const TAO_Bounded_WString_Sequence &rhs) +{ + if (this == &rhs) + return *this; + + if (this->release_) + { + CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **, + this->buffer_); + + for (CORBA::ULong i = 0; i < this->length_; ++i) + { + CORBA::wstring_free (tmp[i]); + tmp[i] = 0; + } + // No need to reallocate because the buffer is supposed to be of + // size. + } + else + this->buffer_ = + TAO_Bounded_WString_Sequence::allocbuf (rhs.maximum_); + + TAO_Bounded_Base_Sequence::operator= (rhs); + + CORBA::WChar **tmp1 = ACE_reinterpret_cast (CORBA::WChar **, + this->buffer_); + CORBA::WChar ** const tmp2 = + ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST, + rhs.buffer_); + + for (CORBA::ULong i = 0; i < rhs.length_; i++) + tmp1[i] = CORBA::wstring_dup (tmp2[i]); + return *this; +} + +template TAO_SeqElem_WString_Manager +TAO_Bounded_WString_Sequence::operator[] (CORBA::ULong slot) const +{ + ACE_ASSERT (slot < this->maximum_); + CORBA::WChar **const tmp = + ACE_reinterpret_cast (CORBA::WChar **ACE_CAST_CONST, + this->buffer_); + return TAO_SeqElem_WString_Manager (tmp + slot, + this->release_); +} + +template CORBA::WChar ** +TAO_Bounded_WString_Sequence::allocbuf (CORBA::ULong) +{ + CORBA::WChar **buf = 0; + + ACE_NEW_RETURN (buf, char *[MAX], 0); + + for (CORBA::ULong i = 0; i < MAX; i++) + buf[i] = 0; + + return buf; +} + +template void +TAO_Bounded_WString_Sequence::freebuf (CORBA::WChar* *buffer) +{ + // How much do we deallocate? Easy! always creates MAX + // elements and initialize them to 0 (they say NULL, yuck!). So we + // can be complaint and call CORBA::wstring_free() on each one. + + for (CORBA::ULong i = 0; i < MAX; ++i) + { + if (buffer[i] != 0) + { + CORBA::wstring_free (buffer[i]); + buffer[i] = 0; + } + } + + delete [] buffer; +} + +template void +TAO_Bounded_WString_Sequence::_allocate_buffer (CORBA::ULong /* length */) +{ + // For this class memory is never reallocated so the implementation + // is *really* simple. + this->buffer_ = + TAO_Bounded_WString_Sequence::allocbuf (MAX); +} + +template void +TAO_Bounded_WString_Sequence::_deallocate_buffer (void) +{ + if (this->release_ == 0) + return; + CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **, + this->buffer_); + TAO_Bounded_WString_Sequence::freebuf (tmp); + this->buffer_ = 0; +} + +template void +TAO_Bounded_WString_Sequence::_shrink_buffer (CORBA::ULong nl, + CORBA::ULong ol) +{ + CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **, + this->buffer_); + + for (CORBA::ULong i = nl; i < ol; ++i) + { + CORBA::wstring_free (tmp[i]); + tmp[i] = 0; + } +} + #endif /* TAO_SEQUENCE_T_C */ -- cgit v1.2.1