summaryrefslogtreecommitdiff
path: root/TAO/tao/Sequence.cpp
diff options
context:
space:
mode:
authorparsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-08-16 19:56:59 +0000
committerparsons <parsons@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-08-16 19:56:59 +0000
commit4deaf37597910f07464d7b1b7b68011e70430816 (patch)
treeac71bd9d103cba7cb7d2cdabffbd86137386c0e8 /TAO/tao/Sequence.cpp
parent3c21fd0b77aea662ad15575b4c36d20501fa0356 (diff)
downloadATCD-4deaf37597910f07464d7b1b7b68011e70430816.tar.gz
(un)bounded wstring sequence classes.
Diffstat (limited to 'TAO/tao/Sequence.cpp')
-rw-r--r--TAO/tao/Sequence.cpp216
1 files changed, 216 insertions, 0 deletions
diff --git a/TAO/tao/Sequence.cpp b/TAO/tao/Sequence.cpp
index 359b0228d31..72b2c1d8338 100644
--- a/TAO/tao/Sequence.cpp
+++ b/TAO/tao/Sequence.cpp
@@ -259,6 +259,222 @@ TAO_Unbounded_String_Sequence::_shrink_buffer (CORBA::ULong nl,
}
}
+// *************************************************************
+
+// constructor for unbounded seq
+TAO_Unbounded_WString_Sequence::
+TAO_Unbounded_WString_Sequence (CORBA::ULong maximum)
+ : TAO_Unbounded_Base_Sequence (maximum,
+ TAO_Unbounded_WString_Sequence::allocbuf (maximum))
+{
+}
+
+TAO_Unbounded_WString_Sequence::
+TAO_Unbounded_WString_Sequence (const TAO_Unbounded_WString_Sequence &rhs)
+ : TAO_Unbounded_Base_Sequence (rhs)
+{
+ CORBA::WChar* *tmp1 = TAO_Unbounded_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;
+}
+
+TAO_Unbounded_WString_Sequence::~TAO_Unbounded_WString_Sequence (void)
+{
+ this->_deallocate_buffer ();
+}
+
+TAO_Unbounded_WString_Sequence&
+TAO_Unbounded_WString_Sequence::
+operator= (const TAO_Unbounded_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;
+ }
+
+ if (this->maximum_ < rhs.maximum_)
+ {
+ // free the older buffer
+ TAO_Unbounded_WString_Sequence::freebuf (tmp);
+ this->buffer_ =
+ TAO_Unbounded_WString_Sequence::allocbuf (rhs.maximum_);
+ }
+ }
+ else
+ this->buffer_ =
+ TAO_Unbounded_WString_Sequence::allocbuf (rhs.maximum_);
+
+ TAO_Unbounded_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;
+}
+
+TAO_SeqElem_WString_Manager
+TAO_Unbounded_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_);
+}
+
+CORBA::WChar* *
+TAO_Unbounded_WString_Sequence::allocbuf (CORBA::ULong nelems)
+{
+ CORBA::WChar* *buf = new CORBA::WChar*[nelems];
+ for (CORBA::ULong i=0; i < nelems; i++)
+ buf[i] = 0;
+ return buf;
+}
+
+void
+TAO_Unbounded_WString_Sequence::freebuf (CORBA::WChar* *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 wstring_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;
+}
+
+CORBA::WChar**
+TAO_Unbounded_WString_Sequence::get_buffer (CORBA::Boolean orphan)
+{
+ CORBA::WChar* *result = 0;
+ if (orphan == 0)
+ {
+ // We retain ownership.
+ if (this->buffer_ == 0)
+ {
+ result = allocbuf (this->length_);
+ this->buffer_ = result;
+ }
+ else
+ {
+ result = ACE_reinterpret_cast (CORBA::WChar**,
+ this->buffer_);
+ }
+ }
+ else // if (orphan == 1)
+ {
+ if (this->release_ != 0)
+ {
+ // We set the state back to default and relinquish
+ // ownership.
+ result = ACE_reinterpret_cast (CORBA::WChar**,
+ this->buffer_);
+ this->maximum_ = 0;
+ this->length_ = 0;
+ this->buffer_ = 0;
+ this->release_ = 0;
+ }
+ }
+ return result;
+}
+
+const CORBA::WChar**
+TAO_Unbounded_WString_Sequence::get_buffer (void) const
+{
+ return ACE_reinterpret_cast (const CORBA::WChar** ACE_CAST_CONST,
+ this->buffer_);
+}
+
+void
+TAO_Unbounded_WString_Sequence::_allocate_buffer (CORBA::ULong length)
+{
+ CORBA::WChar* *tmp = TAO_Unbounded_WString_Sequence::allocbuf (length);
+
+ if (this->buffer_ != 0)
+ {
+ CORBA::WChar* *old = ACE_reinterpret_cast (CORBA::WChar **,
+ 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] = CORBA::wstring_dup (old[i]);
+ else
+ tmp [i] = old[i];
+
+ if (this->release_)
+ delete[] old;
+ }
+ this->buffer_ = tmp;
+}
+
+void
+TAO_Unbounded_WString_Sequence::_deallocate_buffer (void)
+{
+ if (this->buffer_ == 0 || this->release_ == 0)
+ return;
+
+ 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;
+ }
+
+ TAO_Unbounded_WString_Sequence::freebuf (tmp);
+ this->buffer_ = 0;
+}
+
+void
+TAO_Unbounded_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;
+ }
+}
+
// ****************************************************************
#if defined (TAO_NO_COPY_OCTET_SEQUENCES)