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

TAO_Bounded_String_Sequence Class Template Reference

Bounded sequence of strings. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Bounded_String_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Bounded_String_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Bounded_String_Sequence (void)
 TAO_Bounded_String_Sequence (CORBA::ULong length, char **value, CORBA::Boolean release=0)
 TAO_Bounded_String_Sequence (const TAO_Bounded_String_Sequence< MAX > &)
TAO_Bounded_String_Sequence & operator= (const TAO_Bounded_String_Sequence< MAX > &)
 ~TAO_Bounded_String_Sequence (void)
TAO_SeqElem_String_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, char **value, CORBA::Boolean release=0)

Static Public Methods

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

Detailed Description

template<size_t MAX>
class TAO_Bounded_String_Sequence< MAX >

Bounded sequence of strings.

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

Definition at line 1383 of file Sequence_T.h.


Constructor & Destructor Documentation

template<size_t MAX>
TAO_Bounded_String_Sequence< MAX >::TAO_Bounded_String_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 2460 of file Sequence_T.cpp.

02461   : TAO_Bounded_Base_Sequence (
02462         MAX,
02463         TAO_Bounded_String_Sequence<MAX>::allocbuf(MAX)
02464       )
02465 {
02466 }

template<size_t MAX>
ACE_INLINE TAO_Bounded_String_Sequence< MAX >::TAO_Bounded_String_Sequence CORBA::ULong    length,
char **    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 1021 of file Sequence_T.i.

01024   : TAO_Bounded_Base_Sequence (MAX, length, value, release)
01025 {
01026 }

template<size_t MAX>
TAO_Bounded_String_Sequence< MAX >::TAO_Bounded_String_Sequence const TAO_Bounded_String_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 2469 of file Sequence_T.cpp.

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

02472   : TAO_Bounded_Base_Sequence (rhs)
02473 {
02474   if (rhs.buffer_ != 0)
02475     {
02476       char **tmp1 =
02477         TAO_Bounded_String_Sequence<MAX>::allocbuf (this->maximum_);
02478 
02479       char ** const tmp2 =
02480         ACE_reinterpret_cast (char ** ACE_CAST_CONST,
02481                               rhs.buffer_);
02482 
02483       for (CORBA::ULong i=0; i < rhs.length_; i++)
02484         {
02485           tmp1[i] = CORBA::string_dup (tmp2[i]);
02486         }
02487 
02488       this->buffer_ = tmp1;
02489     }
02490   else
02491     {
02492       this->buffer_ = 0;
02493     }
02494 }

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

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

Definition at line 1014 of file Sequence_T.i.

References _deallocate_buffer.

01015 {
01016   this->_deallocate_buffer ();
01017 }


Member Function Documentation

template<size_t MAX>
void TAO_Bounded_String_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 2593 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

02594 {
02595   // For this class memory is never reallocated so the implementation
02596   // is *really* simple.
02597   this->buffer_ =
02598     TAO_Bounded_String_Sequence<MAX>::allocbuf (MAX);
02599 }

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

Must deallocate the buffer and then set it to zero.

Implements TAO_Base_Sequence.

Definition at line 2602 of file Sequence_T.cpp.

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

Referenced by replace, and ~TAO_Bounded_String_Sequence.

02603 {
02604   if (this->release_ == 0)
02605     {
02606       return;
02607     }
02608 
02609   char **tmp = ACE_reinterpret_cast (char **, 
02610                                      this->buffer_);
02611   TAO_Bounded_String_Sequence<MAX>::freebuf (tmp);
02612   this->buffer_ = 0;
02613 }

template<size_t MAX>
void TAO_Bounded_String_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 2616 of file Sequence_T.cpp.

References CORBA::string_free.

02618 {
02619   char **tmp = ACE_reinterpret_cast (char **,
02620                                      this->buffer_);
02621 
02622   for (CORBA::ULong i = nl; i < ol; ++i)
02623     {
02624       CORBA::string_free (tmp[i]);
02625       tmp[i] = 0;
02626     }
02627 }

template<size_t MAX>
char ** TAO_Bounded_String_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 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 2558 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Bounded_String_Sequence.

02559 {
02560   char **buf = 0;
02561   ACE_NEW_RETURN (buf, 
02562                   char *[MAX], 
02563                   0);
02564 
02565   for (CORBA::ULong i = 0; i < MAX; ++i)
02566     {
02567       buf[i] = 0;
02568     }
02569 
02570   return buf;
02571 }

template<size_t MAX>
void TAO_Bounded_String_Sequence< MAX >::freebuf char **    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 string_free(), and object reference elements, which are freed using release(). The freebuf function will ignore null pointers passed to it.

Definition at line 2574 of file Sequence_T.cpp.

References CORBA::string_free.

Referenced by _deallocate_buffer.

02575 {
02576   // How much do we deallocate? Easy! <allocbuf> always creates MAX
02577   // elements and initialize them to 0 (they say NULL, yuck!).  So we
02578   // can be complaint and call CORBA::string_free() on each one.
02579 
02580   for (CORBA::ULong i = 0; i < MAX; ++i)
02581     {
02582       if (buffer[i] != 0)
02583         {
02584           CORBA::string_free (buffer[i]);
02585           buffer[i] = 0;
02586         }
02587     }
02588 
02589   delete [] buffer;
02590 }

template<size_t MAX>
TAO_Bounded_String_Sequence< MAX > & TAO_Bounded_String_Sequence< MAX >::operator= const TAO_Bounded_String_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 2497 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::string_dup, and CORBA::string_free.

02500 {
02501   if (this == &rhs)
02502     {
02503       return *this;
02504     }
02505 
02506   if (this->release_)
02507     {
02508       char **tmp = ACE_reinterpret_cast (char **, 
02509                                          this->buffer_);
02510 
02511       for (CORBA::ULong i = 0; i < this->length_; ++i)
02512         {
02513           CORBA::string_free (tmp[i]);
02514           tmp[i] = 0;
02515         }
02516       // No need to reallocate because the buffer is supposed to be of
02517       // <MAX> size.
02518     }
02519   else
02520     {
02521       if (rhs.maximum_ == 0)
02522         {
02523           this->buffer_ = 0;
02524         }
02525       else
02526         {
02527           this->buffer_ =
02528             TAO_Bounded_String_Sequence<MAX>::allocbuf (rhs.maximum_);
02529         }
02530     }
02531 
02532   TAO_Bounded_Base_Sequence::operator= (rhs);
02533 
02534   char **tmp1 = ACE_reinterpret_cast (char **, 
02535                                       this->buffer_);
02536   char ** const tmp2 = ACE_reinterpret_cast (char ** ACE_CAST_CONST,
02537                                              rhs.buffer_);
02538 
02539   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
02540     {
02541       tmp1[i] = CORBA::string_dup (tmp2[i]);
02542     }
02543 
02544   return *this;
02545 }

template<size_t MAX>
TAO_SeqElem_String_Manager TAO_Bounded_String_Sequence< MAX >::operator[] CORBA::ULong    slot const
 

read-write accessor.

Definition at line 2548 of file Sequence_T.cpp.

References ACE_ASSERT, and TAO_Base_Sequence::maximum_.

02549 {
02550   ACE_ASSERT (slot < this->maximum_);
02551   char **const tmp = ACE_reinterpret_cast (char **ACE_CAST_CONST,
02552                                            this->buffer_);
02553   return TAO_SeqElem_String_Manager (tmp + slot,
02554                                      this->release_);
02555 }

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

Definition at line 2630 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_.

02633 {
02634   ACE_ASSERT (length < this->maximum_);
02635   this->_deallocate_buffer ();
02636   this->length_ = length;
02637 
02638   // If 'release' is 1, caller is responsible for allocating new buffer
02639   // with CORBA::string_alloc.
02640   this->buffer_ = data;
02641   this->release_ = release;
02642 }


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