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

TAO_Bounded_WString_Sequence Class Template Reference

Bounded sequence of wstrings. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Bounded_WString_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Bounded_WString_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Bounded_WString_Sequence (void)
 TAO_Bounded_WString_Sequence (CORBA::ULong length, CORBA::WChar **value, CORBA::Boolean release=0)
 TAO_Bounded_WString_Sequence (const TAO_Bounded_WString_Sequence< MAX > &)
TAO_Bounded_WString_Sequence & operator= (const TAO_Bounded_WString_Sequence< MAX > &)
 ~TAO_Bounded_WString_Sequence (void)
TAO_SeqElem_WString_Manager operator[] (CORBA::ULong slot) const
 read-write accessor. More...

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 length, CORBA::WChar **value, CORBA::Boolean release=0)

Static Public Methods

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

Detailed Description

template<size_t MAX>
class TAO_Bounded_WString_Sequence< MAX >

Bounded sequence of wstrings.

As its unbounded counterpart it duplicates and releases strings (via CORBA::wstring_dup and CORBA::wstring_free) under the control of a per sequence flag, but the capacity of the sequence is bound on the type.

Definition at line 1491 of file Sequence_T.h.


Constructor & Destructor Documentation

template<size_t MAX>
TAO_Bounded_WString_Sequence< MAX >::TAO_Bounded_WString_Sequence void   
 

{SPEC} For bounded sequences, the maximum length is part of the type and cannot be set or modified, while for unbounded sequences, the default constructor also sets the maximum length to 0. The default constructor for a bounded sequence always allocates a contents vector, so it always sets the release flag to TRUE.

Definition at line 2648 of file Sequence_T.cpp.

02649   : TAO_Bounded_Base_Sequence (
02650         MAX,
02651         TAO_Bounded_WString_Sequence<MAX>::allocbuf(MAX)
02652       )
02653 {
02654 }

template<size_t MAX>
ACE_INLINE TAO_Bounded_WString_Sequence< MAX >::TAO_Bounded_WString_Sequence CORBA::ULong    length,
CORBA::WChar **    value,
CORBA::Boolean    release = 0
 

{SPEC} 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 1040 of file Sequence_T.i.

01043   : TAO_Bounded_Base_Sequence (MAX, length, value, release)
01044 {
01045 }

template<size_t MAX>
TAO_Bounded_WString_Sequence< MAX >::TAO_Bounded_WString_Sequence const TAO_Bounded_WString_Sequence< MAX > &   
 

{SPEC} Management Functions'' on page 16. 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 2657 of file Sequence_T.cpp.

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

02660   : TAO_Bounded_Base_Sequence (rhs)
02661 {
02662   if (rhs.buffer_ != 0)
02663     {
02664       CORBA::WChar **tmp1 =
02665         TAO_Bounded_WString_Sequence<MAX>::allocbuf (this->maximum_);
02666 
02667       CORBA::WChar ** const tmp2 =
02668         ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST,
02669                               rhs.buffer_);
02670 
02671       for (CORBA::ULong i=0; i < rhs.length_; ++i)
02672         {
02673           tmp1[i] = CORBA::wstring_dup (tmp2[i]);
02674         }
02675 
02676       this->buffer_ = tmp1;
02677     }
02678   else
02679     {
02680       this->buffer_ = 0;
02681     }
02682 }

template<size_t MAX>
ACE_INLINE TAO_Bounded_WString_Sequence< MAX >::~TAO_Bounded_WString_Sequence void   
 

{SPEC} If release=TRUE, the destructor destroys each of the current elements (items zero through length-1).

Definition at line 1033 of file Sequence_T.i.

References _deallocate_buffer.

01034 {
01035   this->_deallocate_buffer ();
01036 }


Member Function Documentation

template<size_t MAX>
void TAO_Bounded_WString_Sequence< MAX >::_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 2783 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

02784 {
02785   // For this class memory is never reallocated so the implementation
02786   // is *really* simple.
02787   this->buffer_ =
02788     TAO_Bounded_WString_Sequence<MAX>::allocbuf (MAX);
02789 }

template<size_t MAX>
void TAO_Bounded_WString_Sequence< MAX >::_deallocate_buffer void    [virtual]
 

Must deallocate the buffer and then set it to zero.

Implements TAO_Base_Sequence.

Definition at line 2792 of file Sequence_T.cpp.

References TAO_Base_Sequence::buffer_, freebuf, and TAO_Base_Sequence::release_.

Referenced by replace, and ~TAO_Bounded_WString_Sequence.

02793 {
02794   if (this->release_ == 0)
02795     {
02796       return;
02797     }
02798 
02799   CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **,
02800                                              this->buffer_);
02801   TAO_Bounded_WString_Sequence<MAX>::freebuf (tmp);
02802   this->buffer_ = 0;
02803 }

template<size_t MAX>
void TAO_Bounded_WString_Sequence< MAX >::_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 2806 of file Sequence_T.cpp.

References CORBA::wstring_free.

02808 {
02809   CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **,
02810                                              this->buffer_);
02811 
02812   for (CORBA::ULong i = nl; i < ol; ++i)
02813     {
02814       CORBA::wstring_free (tmp[i]);
02815       tmp[i] = 0;
02816     }
02817 }

template<size_t MAX>
CORBA::WChar ** TAO_Bounded_WString_Sequence< MAX >::allocbuf CORBA::ULong    length [static]
 

{SPEC} 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 (w)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 2748 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Bounded_WString_Sequence.

02749 {
02750   CORBA::WChar **buf = 0;
02751   ACE_NEW_RETURN (buf, 
02752                   CORBA::WChar *[MAX], 
02753                   0);
02754 
02755   for (CORBA::ULong i = 0; i < MAX; ++i)
02756     {
02757       buf[i] = 0;
02758     }
02759 
02760   return buf;
02761 }

template<size_t MAX>
void TAO_Bounded_WString_Sequence< MAX >::freebuf CORBA::WChar **    buffer [static]
 

{SPEC} 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 2764 of file Sequence_T.cpp.

References CORBA::wstring_free.

Referenced by _deallocate_buffer.

02765 {
02766   // How much do we deallocate? Easy! <allocbuf> always creates MAX
02767   // elements and initialize them to 0 (they say NULL, yuck!).  So we
02768   // can be complaint and call CORBA::wstring_free() on each one.
02769 
02770   for (CORBA::ULong i = 0; i < MAX; ++i)
02771     {
02772       if (buffer[i] != 0)
02773         {
02774           CORBA::wstring_free (buffer[i]);
02775           buffer[i] = 0;
02776         }
02777     }
02778 
02779   delete [] buffer;
02780 }

template<size_t MAX>
TAO_Bounded_WString_Sequence< MAX > & TAO_Bounded_WString_Sequence< MAX >::operator= const TAO_Bounded_WString_Sequence< MAX > &   
 

{SPEC} 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.

Definition at line 2685 of file Sequence_T.cpp.

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

02688 {
02689   if (this == &rhs)
02690     {
02691       return *this;
02692     }
02693 
02694   if (this->release_)
02695     {
02696       CORBA::WChar **tmp = ACE_reinterpret_cast (CORBA::WChar **,
02697                                                  this->buffer_);
02698 
02699       for (CORBA::ULong i = 0; i < this->length_; ++i)
02700         {
02701           CORBA::wstring_free (tmp[i]);
02702           tmp[i] = 0;
02703         }
02704       // No need to reallocate because the buffer is supposed to be of
02705       // <MAX> size.
02706     }
02707   else
02708     {
02709       if (rhs.maximum_ == 0)
02710         {
02711           this->buffer_ = 0;
02712         }
02713       else
02714         {
02715           this->buffer_ =
02716             TAO_Bounded_WString_Sequence<MAX>::allocbuf (rhs.maximum_);
02717         }
02718     }
02719 
02720   TAO_Bounded_Base_Sequence::operator= (rhs);
02721 
02722   CORBA::WChar **tmp1 = ACE_reinterpret_cast (CORBA::WChar **,
02723                                               this->buffer_);
02724   CORBA::WChar ** const tmp2 =
02725     ACE_reinterpret_cast (CORBA::WChar ** ACE_CAST_CONST,
02726                           rhs.buffer_);
02727 
02728   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
02729     {
02730       tmp1[i] = CORBA::wstring_dup (tmp2[i]);
02731     }
02732 
02733   return *this;
02734 }

template<size_t MAX>
TAO_SeqElem_WString_Manager TAO_Bounded_WString_Sequence< MAX >::operator[] CORBA::ULong    slot const
 

read-write accessor.

Definition at line 2737 of file Sequence_T.cpp.

References ACE_ASSERT, and TAO_Base_Sequence::maximum_.

02738 {
02739   ACE_ASSERT (slot < this->maximum_);
02740   CORBA::WChar **const tmp =
02741     ACE_reinterpret_cast (CORBA::WChar **ACE_CAST_CONST,
02742                           this->buffer_);
02743   return TAO_SeqElem_WString_Manager (tmp + slot,
02744                                       this->release_);
02745 }

template<size_t MAX>
void TAO_Bounded_WString_Sequence< MAX >::replace CORBA::ULong    length,
CORBA::WChar **    value,
CORBA::Boolean    release = 0
 

Definition at line 2820 of file Sequence_T.cpp.

References _deallocate_buffer, ACE_ASSERT, TAO_Base_Sequence::buffer_, TAO_Bounded_Base_Sequence::length, TAO_Base_Sequence::length_, TAO_Base_Sequence::maximum_, TAO_Base_Sequence::release, and TAO_Base_Sequence::release_.

02823 { 
02824   ACE_ASSERT (length < this->maximum_);
02825   this->_deallocate_buffer ();
02826   this->length_ = length;
02827 
02828   // If 'release' is 1, caller is responsible for allocating new buffer
02829   // with CORBA::wstring_alloc.
02830   this->buffer_ = data;
02831   this->release_ = release;
02832 }


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