Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

TAO_Unbounded_WString_Sequence Class Reference

Unbounded sequence of wstrings. More...

#include <Sequence.h>

Inheritance diagram for TAO_Unbounded_WString_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Unbounded_WString_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Unbounded_WString_Sequence (void)
 TAO_Unbounded_WString_Sequence (CORBA::ULong maximum)
 TAO_Unbounded_WString_Sequence (CORBA::ULong maximum, CORBA::ULong length, CORBA::WChar **data, CORBA::Boolean release=0)
 TAO_Unbounded_WString_Sequence (const TAO_Unbounded_WString_Sequence &)
 ~TAO_Unbounded_WString_Sequence (void)
 The destructor releases all object reference members and frees all string members. More...

TAO_Unbounded_WString_Sequence & operator= (const TAO_Unbounded_WString_Sequence &)
TAO_SeqElem_WString_Manager operator[] (CORBA::ULong slot) const
 Read-write accessor. More...

CORBA::WChar ** get_buffer (CORBA::Boolean orphan=0)
const CORBA::WChar ** get_buffer (void) const
virtual void _allocate_buffer (CORBA::ULong length)
virtual void _deallocate_buffer (void)
 Must deallocate the buffer and then set it to zero. More...

virtual void _shrink_buffer (CORBA::ULong new_length, CORBA::ULong old_length)
void replace (CORBA::ULong maximum, CORBA::ULong length, CORBA::WChar **data, CORBA::Boolean release=0)

Static Public Methods

CORBA::WChar ** allocbuf (CORBA::ULong)
void freebuf (CORBA::WChar **)

Detailed Description

Unbounded sequence of wstrings.

IDL sequences of wstrings must automatically duplicate and release their members based on some global <release> flag.

Definition at line 384 of file Sequence.h.


Constructor & Destructor Documentation

ACE_INLINE TAO_Unbounded_WString_Sequence::TAO_Unbounded_WString_Sequence void   
 

{orbos/97-05-15:16.8} The default constructor initializes object reference members to appropriately typed nil object references and wstring members to NULL; all other members are initialized via their default constructors.

{orbos/97-05-15:16.11} For both bounded and unbounded sequences, the default constructor (as shown in the example above) sets the sequence length equal to 0.

Definition at line 185 of file Sequence.i.

00186 {
00187 }

TAO_Unbounded_WString_Sequence::TAO_Unbounded_WString_Sequence CORBA::ULong    maximum
 

Unbounded sequences provide a constructor that allows only the initial value of the maximum length to be set (the ``maximum constructor'' shown in the example above). This allows applications to control how much buffer space is initially allocated by the sequence. This constructor also sets the length to 0 and the release flag to TRUE.

Definition at line 348 of file Sequence.cpp.

ACE_INLINE TAO_Unbounded_WString_Sequence::TAO_Unbounded_WString_Sequence CORBA::ULong    maximum,
CORBA::ULong    length,
CORBA::WChar **    data,
CORBA::Boolean    release = 0
 

The ``T *data'' constructor (as shown in the example above) allows the length and contents of a bounded or unbounded sequence to be set. For unbounded sequences, it also allows the initial value of the maximum length to be set. For this constructor, ownership of the contents vector is determined by the release parameter---FALSE means the caller owns the storage, while TRUE means that the sequence assumes ownership of the storage. If release is TRUE, the contents vector must have been allocated using the sequence allocbuf function, and the sequence will pass it to freebuf when finished with it.

Definition at line 191 of file Sequence.i.

00195   : TAO_Unbounded_Base_Sequence (maximum, length, value, release)
00196 {
00197 }

TAO_Unbounded_WString_Sequence::TAO_Unbounded_WString_Sequence const TAO_Unbounded_WString_Sequence &   
 

The copy constructor performs a deep copy from the existing structure to create a new structure, including calling _duplicate on all object reference members and performing the necessary heap allocations for all string members.

The copy constructor creates a new sequence with the same maximum and length as the given sequence, copies each of its current elements (items zero through length-1), and sets the release flag to TRUE.

Definition at line 358 of file Sequence.cpp.

References allocbuf, TAO_Base_Sequence::buffer_, and CORBA::wstring_dup.

00361   : TAO_Unbounded_Base_Sequence (rhs)
00362 {
00363   if (rhs.buffer_ != 0)
00364     {
00365       CORBA::WChar* *tmp1 =
00366         TAO_Unbounded_WString_Sequence::allocbuf (this->maximum_);
00367 
00368       CORBA::WChar ** const tmp2 =
00369         ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST,
00370                               rhs.buffer_);
00371 
00372       for (CORBA::ULong i = 0; i < rhs.length_; ++i)
00373         {
00374           tmp1[i] = CORBA::wstring_dup (tmp2[i]);
00375         }
00376 
00377       this->buffer_ = tmp1;
00378     }
00379   else
00380     {
00381       this->buffer_ = 0;
00382     }
00383 }

TAO_Unbounded_WString_Sequence::~TAO_Unbounded_WString_Sequence void   
 

The destructor releases all object reference members and frees all string members.

Definition at line 385 of file Sequence.cpp.

References _deallocate_buffer.

00386 {
00387   this->_deallocate_buffer ();
00388 }


Member Function Documentation

void TAO_Unbounded_WString_Sequence::_allocate_buffer CORBA::ULong    length [virtual]
 

Ensure that the buffer contains space for at least <length> elements. The constructor must be called for any new elements, the old ones (if any) must be copied into the buffer using operator= and then their destructors must be called. Finally the old buffer must be released.

Implements TAO_Base_Sequence.

Definition at line 543 of file Sequence.cpp.

References allocbuf, TAO_Base_Sequence::buffer_, TAO_Unbounded_Base_Sequence::length, TAO_Base_Sequence::length_, TAO_Base_Sequence::release_, and CORBA::wstring_dup.

00544 {
00545   CORBA::WChar* *tmp = TAO_Unbounded_WString_Sequence::allocbuf (length);
00546 
00547   if (this->buffer_ != 0)
00548     {
00549       CORBA::WChar* *old = ACE_reinterpret_cast (CORBA::WChar **,
00550                                                  this->buffer_);
00551 
00552       for (CORBA::ULong i = 0; i < this->length_; ++i)
00553         {
00554           // Only call duplicate when we did not own the previous
00555           // buffer, since after this method we own it we must also
00556           // own the objects.  If we already own the objects there is
00557           // no need to copy them, if we did we would also have to
00558           // remove the old instances.
00559           if (!this->release_)
00560             {
00561               tmp [i] = CORBA::wstring_dup (old[i]);
00562             }
00563           else
00564             {
00565               tmp [i] = old[i];
00566             }
00567         }
00568 
00569       if (this->release_)
00570         {
00571           delete [] old;
00572         }
00573     }
00574 
00575   this->buffer_ = tmp;
00576 }

void TAO_Unbounded_WString_Sequence::_deallocate_buffer void    [virtual]
 

Must deallocate the buffer and then set it to zero.

Implements TAO_Base_Sequence.

Definition at line 579 of file Sequence.cpp.

References TAO_Base_Sequence::buffer_, freebuf, TAO_Base_Sequence::length_, TAO_Base_Sequence::release_, and CORBA::wstring_free.

Referenced by ~TAO_Unbounded_WString_Sequence.

00580 {
00581   if (this->buffer_ == 0 || this->release_ == 0)
00582     {
00583       return;
00584     }
00585 
00586   CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **,
00587                                              this->buffer_);
00588 
00589   for (CORBA::ULong i = 0; i < this->length_; ++i)
00590     {
00591       CORBA::wstring_free (tmp[i]);
00592       tmp[i] = 0;
00593     }
00594 
00595   TAO_Unbounded_WString_Sequence::freebuf (tmp);
00596   this->buffer_ = 0;
00597 }

void TAO_Unbounded_WString_Sequence::_shrink_buffer CORBA::ULong    new_length,
CORBA::ULong    old_length
[virtual]
 

Some sequences (of objects and strings) require some cleanup if the sequence is shrunk. The spec requires the destructor to release the objects only from position <0> to <length-1>; so shrink and then delete could result in a memory leak.

Reimplemented from TAO_Base_Sequence.

Definition at line 600 of file Sequence.cpp.

References CORBA::wstring_free.

00602 {
00603   CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **,
00604                                              this->buffer_);
00605   for (CORBA::ULong i = nl; i < ol; ++i)
00606     {
00607       CORBA::wstring_free (tmp[i]);
00608       tmp[i] = 0;
00609     }
00610 }

CORBA::WChar ** TAO_Unbounded_WString_Sequence::allocbuf CORBA::ULong    [static]
 

The allocbuf function allocates a vector of T elements that can be passed to the T *data constructor. The length of the vector is given by the nelems function argument. The allocbuf function initializes each element using its default constructor, except for strings, which are initialized to null pointers, and object references, which are initialized to suitably typed nil object references. A null pointer is returned if allocbuf for some reason cannot allocate the requested vector. Vectors allocated by allocbuf should be freed using the freebuf function.

Definition at line 459 of file Sequence.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, get_buffer, operator=, and TAO_Unbounded_WString_Sequence.

00460 {
00461   CORBA::WChar **buf;
00462   ACE_NEW_RETURN (buf,
00463                   CORBA::WChar *[nelems],
00464                   0);
00465 
00466   for (CORBA::ULong i=0; i < nelems; ++i)
00467     {
00468       buf[i] = 0;
00469     }
00470 
00471   return buf;
00472 }

void TAO_Unbounded_WString_Sequence::freebuf CORBA::WChar **    [static]
 

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.

Definition at line 475 of file Sequence.cpp.

Referenced by _deallocate_buffer, and operator=.

00476 {
00477   if (buffer == 0)
00478     {
00479       return;
00480     }
00481 
00482   // {orbos/97-05-15:16.11}
00483   // The freebuf function ensures that the destructor for each element
00484   // is called before the buffer is destroyed, except for string
00485   // elements, which are freed using wstring_free(), and object
00486   // reference elements, which are freed using release(). The freebuf
00487   // function will ignore null pointers passed to it.
00488 
00489   // @@ How are we supposed to implement that! We don't know the
00490   // length of the buffer here.
00491   //  Mark the length in the first four bytes? For the moment we let
00492   //  that be.
00493 
00494   delete [] buffer;
00495 }

const CORBA::WChar ** TAO_Unbounded_WString_Sequence::get_buffer void    const
 

Definition at line 536 of file Sequence.cpp.

00537 {
00538   return ACE_reinterpret_cast (const CORBA::WChar** ACE_CAST_CONST,
00539                                this->buffer_);
00540 }

CORBA::WChar ** TAO_Unbounded_WString_Sequence::get_buffer CORBA::Boolean    orphan = 0
 

Definition at line 498 of file Sequence.cpp.

References allocbuf, TAO_Base_Sequence::buffer_, TAO_Base_Sequence::length_, TAO_Base_Sequence::maximum_, and TAO_Base_Sequence::release_.

00499 {
00500   CORBA::WChar* *result = 0;
00501 
00502   if (orphan == 0)
00503     {
00504       // We retain ownership.
00505       if (this->buffer_ == 0)
00506         {
00507           result = allocbuf (this->length_);
00508           this->buffer_ = result;
00509                 this->release_ = 1;
00510         }
00511       else
00512         {
00513           result = ACE_reinterpret_cast (CORBA::WChar**,
00514                                          this->buffer_);
00515         }
00516     }
00517   else // if (orphan == 1)
00518     {
00519       if (this->release_ != 0)
00520         {
00521           // We set the state back to default and relinquish
00522           // ownership.
00523           result = ACE_reinterpret_cast (CORBA::WChar**,
00524                                          this->buffer_);
00525           this->maximum_ = 0;
00526           this->length_ = 0;
00527           this->buffer_ = 0;
00528           this->release_ = 0;
00529         }
00530     }
00531 
00532   return result;
00533 }

TAO_Unbounded_WString_Sequence & TAO_Unbounded_WString_Sequence::operator= const TAO_Unbounded_WString_Sequence &   
 

The assignment operator first releases all object reference members and frees all wstring members, and then performs a deep­copy to create a new structure.

The assignment operator deep­copies its parameter, releasing old storage if necessary. It behaves as if the original sequence is destroyed via its destructor and then the source sequence copied using the copy constructor. If release=TRUE, the destructor destroys each of the current elements (items zero through length--1). For an unbounded sequence, if a reallocation is necessary due to a change in the length and the sequence was created using the release=TRUE parameter in its constructor, the sequence will deallocate the old storage. If release is FALSE under these circumstances, old storage will not be freed before the reallocation is performed. After reallocation, the release flag is always set to TRUE.

Definition at line 392 of file Sequence.cpp.

References allocbuf, TAO_Base_Sequence::buffer_, freebuf, TAO_Base_Sequence::length_, TAO_Base_Sequence::maximum_, TAO_Base_Sequence::operator=, TAO_Base_Sequence::release_, CORBA::wstring_dup, and CORBA::wstring_free.

00393 {
00394   if (this == &rhs)
00395     {
00396       return *this;
00397     }
00398 
00399   if (this->release_)
00400     {
00401       CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **,
00402                                                  this->buffer_);
00403 
00404       for (CORBA::ULong i = 0; i < this->length_; ++i)
00405         {
00406           CORBA::wstring_free (tmp[i]);
00407           tmp[i] = 0;
00408         }
00409 
00410       if (this->maximum_ < rhs.maximum_)
00411         {
00412           // free the older buffer
00413           TAO_Unbounded_WString_Sequence::freebuf (tmp);
00414           this->buffer_ =
00415             TAO_Unbounded_WString_Sequence::allocbuf (rhs.maximum_);
00416         }
00417     }
00418   else
00419     {
00420       if (rhs.maximum_ == 0)
00421         {
00422           this->buffer_ = 0;
00423         }
00424       else
00425         {
00426           this->buffer_ =
00427             TAO_Unbounded_WString_Sequence::allocbuf (rhs.maximum_);
00428         }
00429     }
00430 
00431   TAO_Unbounded_Base_Sequence::operator= (rhs);
00432 
00433   CORBA::WChar **tmp1 = ACE_reinterpret_cast (CORBA::WChar **,
00434                                               this->buffer_);
00435   CORBA::WChar ** const tmp2 = 
00436     ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST,
00437                           rhs.buffer_);
00438 
00439   for (CORBA::ULong i=0; i < rhs.length_; ++i)
00440     {
00441       tmp1[i] = CORBA::wstring_dup (tmp2[i]);
00442     }
00443 
00444   return *this;
00445 }

TAO_SeqElem_WString_Manager TAO_Unbounded_WString_Sequence::operator[] CORBA::ULong    slot const
 

Read-write accessor.

Definition at line 448 of file Sequence.cpp.

References ACE_ASSERT, and TAO_Base_Sequence::maximum_.

00449 {
00450   ACE_ASSERT (slot < this->maximum_);
00451   CORBA::WChar **const tmp =
00452     ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST,
00453                           this->buffer_);
00454   return TAO_SeqElem_WString_Manager (tmp + slot,
00455                                       this->release_);
00456 }

void TAO_Unbounded_WString_Sequence::replace CORBA::ULong    maximum,
CORBA::ULong    length,
CORBA::WChar **    data,
CORBA::Boolean    release = 0
 

Definition at line 613 of file Sequence.cpp.

References TAO_Base_Sequence::buffer_, TAO_Unbounded_Base_Sequence::length, TAO_Base_Sequence::length_, TAO_Base_Sequence::maximum, TAO_Base_Sequence::maximum_, TAO_Base_Sequence::release, TAO_Base_Sequence::release_, and CORBA::wstring_free.

00617 {
00618   if (this->release_ == 1)
00619     {
00620       CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **, 
00621                                                  this->buffer_);
00622 
00623       for (CORBA::ULong i = 0; i < this->length_; ++i)
00624         {
00625           CORBA::wstring_free (tmp[i]);
00626           tmp[i] = 0;
00627         }
00628     }
00629 
00630   this->maximum_ = maximum;
00631   this->length_ = length;
00632 
00633   // If 'release' is 1, it is the caller's responsibility to allocate
00634   // 'data' with CORBA::wstring_alloc. 
00635   this->buffer_ = data;
00636   this->release_ = release;
00637 }


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 15:45:49 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002