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

TAO_Unbounded_Abstract_Sequence Class Template Reference

Parametric sequence for abstract interfaces. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Unbounded_Abstract_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Unbounded_Abstract_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

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

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

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

 ~TAO_Unbounded_Abstract_Sequence (void)
 The destructor releases all object reference memebrs and frees all string members. More...

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

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_Abstract_Sequence< T, T_var >

Parametric sequence for abstract interfaces.

See also:
TAO_Unbounded_Object_Sequence

Definition at line 1052 of file Sequence_T.h.


Constructor & Destructor Documentation

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

Definition at line 701 of file Sequence_T.i.

00704 {
00705 }

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

Constructor with a "hint" for the maximum capacity.

Definition at line 1767 of file Sequence_T.cpp.

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

Constructor with a given buffer.

Definition at line 709 of file Sequence_T.i.

00715   : TAO_Unbounded_Base_Sequence (maximum, length, value, release)
00716 {
00717 }

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

Copy ctor, deep copies.

Definition at line 1778 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

01781   : TAO_Unbounded_Base_Sequence (rhs)
01782 {
01783   if (rhs.buffer_ != 0)
01784     {
01785       T **tmp1 =
01786         TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (this->maximum_);
01787       T ** const tmp2 =
01788         ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
01789                               rhs.buffer_);
01790 
01791       for (CORBA::ULong i = 0; i < rhs.length_; ++i)
01792         {
01793           tmp1[i] = T_var::tao_duplicate (tmp2[i]);
01794         }
01795 
01796       this->buffer_ = tmp1;
01797     }
01798   else
01799     {
01800       this->buffer_ = 0;
01801     }
01802 }

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

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

Definition at line 1805 of file Sequence_T.cpp.

References _deallocate_buffer.

01808 {
01809   this->_deallocate_buffer ();
01810 }


Member Function Documentation

template<class T, class T_var>
void TAO_Unbounded_Abstract_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 1915 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_.

01918 {
01919   T **tmp = TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (length);
01920 
01921   if (this->buffer_ != 0)
01922     {
01923       T **old = ACE_reinterpret_cast (T**, 
01924                                       this->buffer_);
01925 
01926       for (CORBA::ULong i = 0; i < this->length_; ++i)
01927         // Only call duplicate when we did not own the previous
01928         // buffer, since after this method we own it we must also own
01929         // the objects.  If we already own the objects there is no
01930         // need to copy them, if we did we would also have to remove
01931         // the old instances.
01932         if (!this->release_)
01933           {
01934             tmp[i] = T_var::tao_duplicate (old[i]);
01935           }
01936         else
01937           {
01938             tmp[i] = old[i];
01939           }
01940 
01941       if (this->release_)
01942         {
01943           delete [] old;
01944         }
01945     }
01946 
01947   this->buffer_ = tmp;
01948 }

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

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

Referenced by ~TAO_Unbounded_Abstract_Sequence.

01952 {
01953   if (this->buffer_ == 0 || this->release_ == 0)
01954     {
01955       return;
01956     }
01957 
01958   T **tmp = ACE_reinterpret_cast (T**, 
01959                                   this->buffer_);
01960 
01961   for (CORBA::ULong i = 0; i < this->length_; ++i)
01962     {
01963       T_var::tao_release (tmp[i]);
01964       tmp[i] = T_var::tao_nil ();
01965     }
01966 
01967   TAO_Unbounded_Abstract_Sequence<T, T_var>::freebuf (tmp);
01968   this->buffer_ = 0;
01969 }

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

01974 {
01975   T **tmp = ACE_static_cast (T**, 
01976                              this->buffer_);
01977 
01978   for (CORBA::ULong i = nl; i < ol; ++i)
01979     {
01980       T_var::tao_release (tmp[i]);
01981       tmp[i] = T_var::tao_nil ();
01982     }
01983 }

template<class T, class T_var>
T ** TAO_Unbounded_Abstract_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 1874 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Unbounded_Abstract_Sequence.

01875 {
01876   T **buf = 0;
01877   ACE_NEW_RETURN (buf, 
01878                   T*[nelems], 
01879                   0);
01880 
01881   for (CORBA::ULong i = 0; i < nelems; i++)
01882     {
01883       buf[i] = T_var::tao_nil ();
01884     }
01885 
01886   return buf;
01887 }

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

Release all the elements.

Definition at line 1891 of file Sequence_T.cpp.

Referenced by _deallocate_buffer, and operator=.

01892 {
01893   if (buffer == 0)
01894     {
01895       return;
01896     }
01897 
01898   // {orbos/97-05-15:16.11} The freebuf function ensures that the
01899   // destructor for each element is called before the buffer is
01900   // destroyed, except for string elements, which are freed using
01901   // string_free(), and object reference elements, which are freed
01902   // using release(). The freebuf function will ignore null pointers
01903   // passed to it.
01904 
01905   // @@ How are we supposed to implement that! We don't know the
01906   // length of the buffer here.
01907   // Mark the length in the first four bytes? For the moment we let
01908   // that be.
01909 
01910   delete [] buffer;
01911 }

template<class T, class T_var>
TAO_Unbounded_Abstract_Sequence< T, T_var > & TAO_Unbounded_Abstract_Sequence< T, T_var >::operator= const TAO_Unbounded_Abstract_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 1815 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_.

01818 {
01819   if (this == &rhs)
01820     {
01821       return *this;
01822     }
01823 
01824   if (this->release_)
01825     {
01826       T **tmp = ACE_reinterpret_cast (T **,
01827                                       this->buffer_);
01828 
01829       for (CORBA::ULong i = 0; i < this->length_; ++i)
01830         {
01831           T_var::tao_release (tmp[i]);
01832           tmp[i] = T_var::tao_nil ();
01833         }
01834 
01835       if (this->maximum_ < rhs.maximum_)
01836         {
01837           TAO_Unbounded_Abstract_Sequence<T, T_var>::freebuf (tmp);
01838           this->buffer_ =
01839             TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (rhs.maximum_);
01840         }
01841     }
01842   else
01843     {
01844       if (rhs.maximum_ == 0)
01845         {
01846           this->buffer_ = 0;
01847         }
01848       else
01849         {
01850           this->buffer_ =
01851             TAO_Unbounded_Abstract_Sequence<T, T_var>::allocbuf (
01852                 rhs.maximum_
01853               );
01854         }
01855     }
01856 
01857   TAO_Unbounded_Base_Sequence::operator= (rhs);
01858 
01859   T **tmp1 = ACE_reinterpret_cast (T **, 
01860                                    this->buffer_);
01861   T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
01862                                           rhs.buffer_);
01863 
01864   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
01865     {
01866       tmp1[i] = T_var::tao_duplicate (tmp2[i]);
01867     }
01868 
01869   return *this;
01870 }

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

read-write accessor.

Definition at line 722 of file Sequence_T.i.

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

00723 {
00724   ACE_ASSERT (slot < this->maximum_);
00725   T ** const tmp = ACE_reinterpret_cast (T ** ACE_CAST_CONST, this->buffer_);
00726   return TAO_Abstract_Manager<T,T_var> (tmp + slot, this->release_);
00727 }


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