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

TAO_Unbounded_Object_Sequence Class Template Reference

Parametric sequence for types that require managers. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Unbounded_Object_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Unbounded_Object_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Unbounded_Object_Sequence (void)
 TAO_Unbounded_Object_Sequence (CORBA::ULong max)
 TAO_Unbounded_Object_Sequence (CORBA::ULong maximum, CORBA::ULong length, T **data, CORBA::Boolean release=0)
 TAO_Unbounded_Object_Sequence (const TAO_Unbounded_Object_Sequence< T, T_var > &)
 ~TAO_Unbounded_Object_Sequence (void)
 The destructor releases all object reference memebrs and frees all string members. More...

TAO_Unbounded_Object_Sequence<
T, T_var > & 
operator= (const TAO_Unbounded_Object_Sequence< T, T_var > &)
TAO_Object_Manager< T, T_var > operator[] (CORBA::ULong slot) const
 read-write accessor. More...

virtual void _allocate_buffer (CORBA::ULong length)
 No default to workaround egcs problem with templates and namespaces. More...

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)
virtual void _downcast (void *target, CORBA_Object *src ACE_ENV_ARG_DECL_WITH_DEFAULTS)
 Used for sequences of objects to downcast a recently demarshalled object reference into the right type. More...

virtual CORBA_Object_upcast (void *src) const
 Used for sequences of object to convert from the derived type into the Object class. More...


Static Public Methods

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

Detailed Description

template<class T, class T_var>
class TAO_Unbounded_Object_Sequence< T, T_var >

Parametric sequence for types that require managers.

Some IDL types require that sequences on them have a "manager" class, in charge of handling the object lifetime, examples are pseudo objects, object references, valuetypes, and strings.

Definition at line 622 of file Sequence_T.h.


Constructor & Destructor Documentation

template<class T, class T_var>
ACE_INLINE TAO_Unbounded_Object_Sequence< T, T_var >::TAO_Unbounded_Object_Sequence void   
 

{orbos/97-05-15:16.8} The default constructor initializes object reference members to appropriately typed nil object references and string 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 515 of file Sequence_T.i.

00516 {
00517 }

template<class T, class T_var>
TAO_Unbounded_Object_Sequence< T, T_var >::TAO_Unbounded_Object_Sequence CORBA::ULong    max
 

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 579 of file Sequence_T.cpp.

template<class T, class T_var>
ACE_INLINE TAO_Unbounded_Object_Sequence< T, T_var >::TAO_Unbounded_Object_Sequence CORBA::ULong    maximum,
CORBA::ULong    length,
T **    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 521 of file Sequence_T.i.

00525   : TAO_Unbounded_Base_Sequence (maximum, length, value, release)
00526 {
00527 }

template<class T, class T_var>
TAO_Unbounded_Object_Sequence< T, T_var >::TAO_Unbounded_Object_Sequence const TAO_Unbounded_Object_Sequence< T, T_var > &   
 

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 590 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

00593   : TAO_Unbounded_Base_Sequence (rhs)
00594 {
00595   if (rhs.buffer_ != 0)
00596     {
00597       T **tmp1 =
00598         TAO_Unbounded_Object_Sequence<T,T_var>::allocbuf (this->maximum_);
00599       T ** const tmp2 =
00600         ACE_reinterpret_cast (T ** ACE_CAST_CONST, rhs.buffer_);
00601 
00602       for (CORBA::ULong i = 0; i < rhs.length_; ++i)
00603         {
00604           tmp1[i] = T_var::tao_duplicate (tmp2[i]);
00605         }
00606 
00607       this->buffer_ = tmp1;
00608     }
00609   else
00610     {
00611       this->buffer_ = 0;
00612     }
00613 }

template<class T, class T_var>
TAO_Unbounded_Object_Sequence< T, T_var >::~TAO_Unbounded_Object_Sequence void   
 

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

Definition at line 616 of file Sequence_T.cpp.

References _deallocate_buffer.

00617 {
00618   this->_deallocate_buffer ();
00619 }


Member Function Documentation

template<class T, class T_var>
void TAO_Unbounded_Object_Sequence< T, T_var >::_allocate_buffer CORBA::ULong    length [virtual]
 

No default to workaround egcs problem with templates and namespaces.

Implements TAO_Base_Sequence.

Definition at line 715 of file Sequence_T.cpp.

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

00716 {
00717   T **tmp = TAO_Unbounded_Object_Sequence<T,T_var>::allocbuf (length);
00718 
00719   if (this->buffer_ != 0)
00720     {
00721       T **old = ACE_reinterpret_cast (T**, 
00722                                       this->buffer_);
00723 
00724       for (CORBA::ULong i = 0; i < this->length_; ++i)
00725         // Only call duplicate when we did not own the previous
00726         // buffer, since after this method we own it we must also own
00727         // the objects.  If we already own the objects there is no
00728         // need to copy them, if we did we would also have to remove
00729         // the old instances.
00730         if (!this->release_)
00731           {
00732             tmp[i] = T_var::tao_duplicate (old[i]);
00733           }
00734         else
00735           {
00736             tmp[i] = old[i];
00737           }
00738 
00739       if (this->release_)
00740         {
00741           delete [] old;
00742         }
00743     }
00744 
00745   this->buffer_ = tmp;
00746 }

template<class T, class T_var>
void TAO_Unbounded_Object_Sequence< T, T_var >::_deallocate_buffer void    [virtual]
 

Must deallocate the buffer and then set it to zero.

Implements TAO_Base_Sequence.

Definition at line 749 of file Sequence_T.cpp.

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

Referenced by ~TAO_Unbounded_Object_Sequence.

00750 {
00751   if (this->buffer_ == 0 || this->release_ == 0)
00752     {
00753       return;
00754     }
00755 
00756   T **tmp = ACE_reinterpret_cast (T**, 
00757                                   this->buffer_);
00758 
00759   for (CORBA::ULong i = 0; i < this->length_; ++i)
00760     {
00761       T_var::tao_release (tmp[i]);
00762       tmp[i] = T_var::tao_nil ();
00763     }
00764 
00765   TAO_Unbounded_Object_Sequence<T,T_var>::freebuf (tmp);
00766   this->buffer_ = 0;
00767 }

template<class T, class T_var>
void TAO_Unbounded_Object_Sequence< T, T_var >::_downcast void *    target,
CORBA_Object *src    ACE_ENV_ARG_DECL_WITH_DEFAULTS
[virtual]
 

Used for sequences of objects to downcast a recently demarshalled object reference into the right type.

Reimplemented from TAO_Base_Sequence.

Definition at line 783 of file Sequence_T.cpp.

References ACE_CHECK, ACE_ENV_ARG_DECL, and ACE_ENV_ARG_PARAMETER.

00786 {
00787   T **tmp = ACE_static_cast (T**, 
00788                              target);
00789 
00790   *tmp = T_var::tao_narrow (src 
00791                             ACE_ENV_ARG_PARAMETER);
00792 
00793   ACE_CHECK;
00794 }

template<class T, class T_var>
void TAO_Unbounded_Object_Sequence< T, T_var >::_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 770 of file Sequence_T.cpp.

00772 {
00773   T **tmp = ACE_static_cast (T**, this->buffer_);
00774 
00775   for (CORBA::ULong i = nl; i < ol; ++i)
00776     {
00777       T_var::tao_release (tmp[i]);
00778       tmp[i] = T_var::tao_nil ();
00779     }
00780 }

template<class T, class T_var>
CORBA_Object * TAO_Unbounded_Object_Sequence< T, T_var >::_upcast void *    src const [virtual]
 

Used for sequences of object to convert from the derived type into the Object class.

Reimplemented from TAO_Base_Sequence.

Definition at line 797 of file Sequence_T.cpp.

00798 {
00799   return T_var::tao_upcast (src);
00800 }

template<class T, class T_var>
T ** TAO_Unbounded_Object_Sequence< T, T_var >::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 676 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Unbounded_Object_Sequence.

00677 {
00678   T **buf = 0;
00679   ACE_NEW_RETURN (buf, 
00680                   T*[nelems], 
00681                   0);
00682 
00683   for (CORBA::ULong i = 0; i < nelems; i++)
00684     {
00685       buf[i] = T_var::tao_nil ();
00686     }
00687 
00688   return buf;
00689 }

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

Definition at line 692 of file Sequence_T.cpp.

Referenced by _deallocate_buffer, and operator=.

00693 {
00694   if (buffer == 0)
00695     {
00696       return;
00697     }
00698 
00699   // {orbos/97-05-15:16.11} The freebuf function ensures that the
00700   // destructor for each element is called before the buffer is
00701   // destroyed, except for string elements, which are freed using
00702   // string_free(), and object reference elements, which are freed
00703   // using release(). The freebuf function will ignore null pointers
00704   // passed to it.
00705 
00706   // @@ How are we supposed to implement that! We don't know the
00707   // length of the buffer here.
00708   // Mark the length in the first four bytes? For the moment we let
00709   // that be.
00710 
00711   delete [] buffer;
00712 }

template<class T, class T_var>
TAO_Unbounded_Object_Sequence< T, T_var > & TAO_Unbounded_Object_Sequence< T, T_var >::operator= const TAO_Unbounded_Object_Sequence< T, T_var > &   
 

The assignment operator first releases all object reference members and frees all string members, and then performs a deepcopy to create a new structure.

The assignment operator deepcopies 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 624 of file Sequence_T.cpp.

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

00625 {
00626   if (this == &rhs)
00627     {
00628       return *this;
00629     }
00630 
00631   if (this->release_)
00632     {
00633       T **tmp = ACE_reinterpret_cast (T **,
00634                                       this->buffer_);
00635 
00636       for (CORBA::ULong i = 0; i < this->length_; ++i)
00637         {
00638           T_var::tao_release (tmp[i]);
00639           tmp[i] = T_var::tao_nil ();
00640         }
00641 
00642       if (this->maximum_ < rhs.maximum_)
00643         {
00644           TAO_Unbounded_Object_Sequence<T,T_var>::freebuf (tmp);
00645           this->buffer_ =
00646             TAO_Unbounded_Object_Sequence<T,T_var>::allocbuf (rhs.maximum_);
00647         }
00648     }
00649   else
00650     {
00651       if (rhs.maximum_ == 0)
00652         {
00653           this->buffer_ = 0;
00654         }
00655       else
00656         {
00657           this->buffer_ =
00658             TAO_Unbounded_Object_Sequence<T,T_var>::allocbuf (rhs.maximum_);
00659         }
00660     }
00661 
00662   TAO_Unbounded_Base_Sequence::operator= (rhs);
00663 
00664   T **tmp1 = ACE_reinterpret_cast (T **, this->buffer_);
00665   T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, rhs.buffer_);
00666 
00667   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
00668     {
00669       tmp1[i] = T_var::tao_duplicate (tmp2[i]);
00670     }
00671 
00672   return *this;
00673 }

template<class T, class T_var>
ACE_INLINE TAO_Object_Manager< T, T_var > TAO_Unbounded_Object_Sequence< T, T_var >::operator[] CORBA::ULong    slot const
 

read-write accessor.

Definition at line 530 of file Sequence_T.i.

References ACE_ASSERT, TAO_Base_Sequence::maximum_, and TAO_Base_Sequence::release_.

00531 {
00532   ACE_ASSERT (slot < this->maximum_);
00533   T ** const tmp = ACE_reinterpret_cast (T ** ACE_CAST_CONST, this->buffer_);
00534   return TAO_Object_Manager<T,T_var> (tmp + slot, this->release_);
00535 }


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