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

TAO_Unbounded_Pseudo_Sequence Class Template Reference

Parametric sequence for pseudo objects. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Unbounded_Pseudo_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Unbounded_Pseudo_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Unbounded_Pseudo_Sequence (void)
 default ctor. More...

 TAO_Unbounded_Pseudo_Sequence (CORBA::ULong max)
 Constructor with a "hint" for the maximum capacity. More...

 TAO_Unbounded_Pseudo_Sequence (CORBA::ULong maximum, CORBA::ULong length, T **data, CORBA::Boolean release=0)
 Constructor with a given buffer. More...

 TAO_Unbounded_Pseudo_Sequence (const TAO_Unbounded_Pseudo_Sequence< T, T_var > &)
 Copy ctor, deep copies. More...

 ~TAO_Unbounded_Pseudo_Sequence (void)
 dtor releases all the contained elements. More...

TAO_Unbounded_Pseudo_Sequence<
T, T_var > & 
operator= (const TAO_Unbounded_Pseudo_Sequence< T, T_var > &)
TAO_Pseudo_Object_Manager<
T, T_var > 
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)

Static Public Methods

T ** allocbuf (CORBA::ULong)
 The allocbuf function allocates a vector of T elements that can be passed to the T *data constructor. More...

void freebuf (T **)
 Release all the elements. More...


Detailed Description

template<class T, class T_var>
class TAO_Unbounded_Pseudo_Sequence< T, T_var >

Parametric sequence for pseudo objects.

Some IDL types (including pseudo objects) require that sequences on them have a "manager" class, in charge of handling the object lifetime. This parametric class implements those sequences. In general the sequence is similar to Object_Sequente, except for some TAO internal details. The complete documentation of each method is provided in TAO_Unbounded_Object_Sequece

Definition at line 827 of file Sequence_T.h.


Constructor & Destructor Documentation

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

default ctor.

Definition at line 570 of file Sequence_T.i.

00571 {
00572 }

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

Constructor with a "hint" for the maximum capacity.

Definition at line 991 of file Sequence_T.cpp.

template<class T, class T_var>
ACE_INLINE TAO_Unbounded_Pseudo_Sequence< T, T_var >::TAO_Unbounded_Pseudo_Sequence CORBA::ULong    maximum,
CORBA::ULong    length,
T **    data,
CORBA::Boolean    release = 0
 

Constructor with a given buffer.

Definition at line 576 of file Sequence_T.i.

00580   : TAO_Unbounded_Base_Sequence (maximum, length, value, release)
00581 {
00582 }

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

Copy ctor, deep copies.

Definition at line 1000 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

01003   : TAO_Unbounded_Base_Sequence (rhs)
01004 {
01005   if (rhs.buffer_ != 0)
01006     {
01007       T **tmp1 =
01008         TAO_Unbounded_Pseudo_Sequence<T,T_var>::allocbuf (this->maximum_);
01009 
01010       T ** const tmp2 =
01011         ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
01012                               rhs.buffer_);
01013 
01014       for (CORBA::ULong i = 0; i < rhs.length_; ++i)
01015         {
01016           tmp1[i] = T::_duplicate (tmp2[i]);
01017         }
01018 
01019       this->buffer_ = tmp1;
01020     }
01021   else
01022     {
01023       this->buffer_ = 0;
01024     }
01025 }

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

dtor releases all the contained elements.

Definition at line 1028 of file Sequence_T.cpp.

References _deallocate_buffer.

01029 {
01030   this->_deallocate_buffer ();
01031 }


Member Function Documentation

template<class T, class T_var>
void TAO_Unbounded_Pseudo_Sequence< T, T_var >::_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 1129 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_.

01130 {
01131   T **tmp = TAO_Unbounded_Pseudo_Sequence<T,T_var>::allocbuf (length);
01132 
01133   if (this->buffer_ != 0)
01134     {
01135       T **old = ACE_reinterpret_cast (T**, 
01136                                       this->buffer_);
01137 
01138       for (CORBA::ULong i = 0; i < this->length_; ++i)
01139         // Only call duplicate when we did not own the previous
01140         // buffer, since after this method we own it we must also own
01141         // the objects.  If we already own the objects there is no
01142         // need to copy them, if we did we would also have to remove
01143         // the old instances.
01144         if (!this->release_)
01145           {
01146             tmp[i] = T::_duplicate (old[i]);
01147           }
01148         else
01149           {
01150             tmp[i] = old[i];
01151           }
01152 
01153       if (this->release_)
01154         {
01155           delete [] old;
01156         }
01157     }
01158   this->buffer_ = tmp;
01159 }

template<class T, class T_var>
void TAO_Unbounded_Pseudo_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 1162 of file Sequence_T.cpp.

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

Referenced by ~TAO_Unbounded_Pseudo_Sequence.

01163 {
01164   if (this->buffer_ == 0 || this->release_ == 0)
01165     {
01166       return;
01167     }
01168 
01169   T **tmp = ACE_reinterpret_cast (T**, 
01170                                   this->buffer_);
01171 
01172   for (CORBA::ULong i = 0; i < this->length_; ++i)
01173     {
01174       CORBA::release (tmp[i]);
01175       tmp[i] = T::_nil ();
01176     }
01177 
01178   TAO_Unbounded_Pseudo_Sequence<T,T_var>::freebuf (tmp);
01179   this->buffer_ = 0;
01180 }

template<class T, class T_var>
void TAO_Unbounded_Pseudo_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 1183 of file Sequence_T.cpp.

References CORBA::release.

01185 {
01186   T **tmp = ACE_static_cast (T**, this->buffer_);
01187 
01188   for (CORBA::ULong i = nl; i < ol; ++i)
01189     {
01190       CORBA::release (tmp[i]);
01191       tmp[i] = T::_nil ();
01192     }
01193 }

template<class T, class T_var>
T ** TAO_Unbounded_Pseudo_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.

Definition at line 1090 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Unbounded_Pseudo_Sequence.

01091 {
01092   T **buf = 0;
01093   ACE_NEW_RETURN (buf, 
01094                   T*[nelems], 
01095                   0);
01096 
01097   for (CORBA::ULong i = 0; i < nelems; i++)
01098     {
01099       buf[i] = T::_nil ();
01100     }
01101 
01102   return buf;
01103 }

template<class T, class T_var>
void TAO_Unbounded_Pseudo_Sequence< T, T_var >::freebuf T **    [static]
 

Release all the elements.

Definition at line 1106 of file Sequence_T.cpp.

Referenced by _deallocate_buffer, and operator=.

01107 {
01108   if (buffer == 0)
01109     {
01110       return;
01111     }
01112 
01113   // {orbos/97-05-15:16.11} The freebuf function ensures that the
01114   // destructor for each element is called before the buffer is
01115   // destroyed, except for string elements, which are freed using
01116   // string_free(), and object reference elements, which are freed
01117   // using release(). The freebuf function will ignore null pointers
01118   // passed to it.
01119 
01120   // @@ How are we supposed to implement that! We don't know the
01121   // length of the buffer here.
01122   // Mark the length in the first four bytes? For the moment we let
01123   // that be.
01124 
01125   delete [] buffer;
01126 }

template<class T, class T_var>
TAO_Unbounded_Pseudo_Sequence< T, T_var > & TAO_Unbounded_Pseudo_Sequence< T, T_var >::operator= const TAO_Unbounded_Pseudo_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.

Definition at line 1036 of file Sequence_T.cpp.

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

01037 {
01038   if (this == &rhs)
01039     {
01040       return *this;
01041     }
01042 
01043   if (this->release_)
01044     {
01045       T **tmp = ACE_reinterpret_cast (T **,
01046                                       this->buffer_);
01047 
01048       for (CORBA::ULong i = 0; i < this->length_; ++i)
01049         {
01050           CORBA::release (tmp[i]);
01051           tmp[i] = T::_nil ();
01052         }
01053 
01054       if (this->maximum_ < rhs.maximum_)
01055         {
01056           TAO_Unbounded_Pseudo_Sequence<T,T_var>::freebuf (tmp);
01057           this->buffer_ =
01058             TAO_Unbounded_Pseudo_Sequence<T,T_var>::allocbuf (rhs.maximum_);
01059         }
01060     }
01061   else
01062     {
01063       if (rhs.maximum_ == 0)
01064         {
01065           this->buffer_ = 0;
01066         }
01067       else
01068         {
01069           this->buffer_ =
01070             TAO_Unbounded_Pseudo_Sequence<T,T_var>::allocbuf (rhs.maximum_);
01071         }
01072     }
01073 
01074   TAO_Unbounded_Base_Sequence::operator= (rhs);
01075 
01076   T **tmp1 = ACE_reinterpret_cast (T **, 
01077                                    this->buffer_);
01078   T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
01079                                           rhs.buffer_);
01080 
01081   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
01082     {
01083       tmp1[i] = T::_duplicate (tmp2[i]);
01084     }
01085 
01086   return *this;
01087 }

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

read-write accessor.

Definition at line 585 of file Sequence_T.i.

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

00586 {
00587   ACE_ASSERT (slot < this->maximum_);
00588   T ** const tmp = ACE_reinterpret_cast (T ** ACE_CAST_CONST, this->buffer_);
00589   return TAO_Pseudo_Object_Manager<T,T_var> (tmp + slot, this->release_);
00590 }


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