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

TAO_Bounded_Abstract_Sequence Class Template Reference

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

#include <Sequence_T.h>

Inheritance diagram for TAO_Bounded_Abstract_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Bounded_Abstract_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Bounded_Abstract_Sequence (void)
 TAO_Bounded_Abstract_Sequence (CORBA::ULong length, T **value, CORBA::Boolean release=0)
 Constructor from data. More...

 TAO_Bounded_Abstract_Sequence (const TAO_Bounded_Abstract_Sequence< T, T_var, MAX > &)
 Copy constructor. More...

 ~TAO_Bounded_Abstract_Sequence (void)
 destructor. More...

TAO_Bounded_Abstract_Sequence & operator= (const TAO_Bounded_Abstract_Sequence< T, T_var, MAX > &)
 Assignment from another Bounded sequence. More...

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 length)
 Allocate storage for a sequence.. More...

void freebuf (T **buffer)
 Free a buffer allocated by allocbuf() and release each element on it. More...


Detailed Description

template<class T, class T_var, size_t MAX>
class TAO_Bounded_Abstract_Sequence< T, T_var, MAX >

Parametric sequence for types that require managers.

Please see the documentation for the unbounded case.

Definition at line 1116 of file Sequence_T.h.


Constructor & Destructor Documentation

template<class T, class T_var, size_t MAX>
TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::TAO_Bounded_Abstract_Sequence void   
 

Definition at line 1990 of file Sequence_T.cpp.

01993   : TAO_Bounded_Base_Sequence (
01994         MAX,
01995         TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (MAX)
01996       )
01997 {
01998 }

template<class T, class T_var, size_t MAX>
ACE_INLINE TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::TAO_Bounded_Abstract_Sequence CORBA::ULong    length,
T **    value,
CORBA::Boolean    release = 0
 

Constructor from data.

Definition at line 743 of file Sequence_T.i.

00748   : TAO_Bounded_Base_Sequence (MAX, length, value, release)
00749 {
00750 }

template<class T, class T_var, size_t MAX>
TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::TAO_Bounded_Abstract_Sequence const TAO_Bounded_Abstract_Sequence< T, T_var, MAX > &   
 

Copy constructor.

Definition at line 2001 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

02004   : TAO_Bounded_Base_Sequence (rhs)
02005 {
02006   if (rhs.buffer_ != 0)
02007     {
02008       T **tmp1 =
02009         TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (MAX);
02010 
02011       T ** const tmp2 =
02012         ACE_reinterpret_cast (T** ACE_CAST_CONST, rhs.buffer_);
02013 
02014       for (CORBA::ULong i = 0; i < rhs.length_; i++)
02015         {
02016           tmp1[i] = T_var::tao_duplicate (tmp2[i]);
02017         }
02018 
02019       this->buffer_ = tmp1;
02020     }
02021   else
02022     {
02023       this->buffer_ = 0;
02024     }
02025 }

template<class T, class T_var, size_t MAX>
ACE_INLINE TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::~TAO_Bounded_Abstract_Sequence void   
 

destructor.

Definition at line 735 of file Sequence_T.i.

References _deallocate_buffer.

00738 {
00739   this->_deallocate_buffer ();
00740 }


Member Function Documentation

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

No default to workaround egcs problem with templates and namespaces.

Implements TAO_Base_Sequence.

Definition at line 2119 of file Sequence_T.cpp.

References allocbuf, TAO_Base_Sequence::buffer_, and TAO_Bounded_Base_Sequence::length.

02122 {
02123   // For this class memory is never reallocated so the implementation
02124   // is *really* simple.
02125   this->buffer_ =
02126     TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (length);
02127 }

template<class T, class T_var, size_t MAX>
void TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::_deallocate_buffer void    [virtual]
 

Must deallocate the buffer and then set it to zero.

Implements TAO_Base_Sequence.

Definition at line 2131 of file Sequence_T.cpp.

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

Referenced by ~TAO_Bounded_Abstract_Sequence.

02132 {
02133   if (this->release_ == 0)
02134     {
02135       return;
02136     }
02137 
02138   T **tmp = ACE_reinterpret_cast (T **, 
02139                                   this->buffer_);
02140   TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::freebuf (tmp);
02141   this->buffer_ = 0;
02142 }

template<class T, class T_var, size_t MAX>
void TAO_Bounded_Abstract_Sequence< T, T_var, 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 2146 of file Sequence_T.cpp.

02148 {
02149   T **tmp = ACE_reinterpret_cast (T **, 
02150                                   this->buffer_);
02151 
02152   for (CORBA::ULong i = nl; i < ol; ++i)
02153     {
02154       T_var::tao_release (tmp[i]);
02155       tmp[i] = T_var::tao_nil ();
02156     }
02157 }

template<class T, class T_var, size_t MAX>
T ** TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::allocbuf CORBA::ULong    length [static]
 

Allocate storage for a sequence..

Definition at line 2083 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Bounded_Abstract_Sequence.

02084 {
02085   T **buf = 0;
02086   ACE_NEW_RETURN (buf, 
02087                   T*[MAX], 
02088                   0);
02089 
02090   for (CORBA::ULong i = 0; i < MAX; ++i)
02091     {
02092       buf[i] = T_var::tao_nil ();
02093     }
02094 
02095   return buf;
02096 }

template<class T, class T_var, size_t MAX>
void TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::freebuf T **    buffer [static]
 

Free a buffer allocated by allocbuf() and release each element on it.

Definition at line 2100 of file Sequence_T.cpp.

Referenced by _deallocate_buffer.

02101 {
02102   // How much do we deallocate? Easy! allocbuf() always creates MAX
02103   // elements and initialize them to T::_nil().  So we can be
02104   // complaint and call CORBA::release() on each one.
02105   for (CORBA::ULong i = 0; i < MAX; ++i)
02106     {
02107       if (buffer[i] != T_var::tao_nil ())
02108         {
02109           T_var::tao_release (buffer[i]);
02110           buffer[i] = T_var::tao_nil ();
02111         }
02112     }
02113 
02114   delete [] buffer;
02115 }

template<class T, class T_var, size_t MAX>
TAO_Bounded_Abstract_Sequence< T, T_var, MAX > & TAO_Bounded_Abstract_Sequence< T, T_var, MAX >::operator= const TAO_Bounded_Abstract_Sequence< T, T_var, MAX > &   
 

Assignment from another Bounded sequence.

Definition at line 2029 of file Sequence_T.cpp.

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

02032 {
02033   if (this == &rhs)
02034     {
02035       return *this;
02036     }
02037 
02038   if (this->release_)
02039     {
02040       T **tmp = ACE_reinterpret_cast (T **, 
02041                                       this->buffer_);
02042 
02043       for (CORBA::ULong i = 0; i < this->length_; ++i)
02044         {
02045           T_var::tao_release (tmp[i]);
02046           tmp[i] = T_var::tao_nil ();
02047         }
02048       // No need to reallocate the buffer since it is always of size
02049       // MAX
02050     }
02051   else
02052     {
02053       if (rhs.maximum_ == 0)
02054         {
02055           this->buffer_ = 0;
02056         }
02057       else
02058         {
02059           this->buffer_ =
02060             TAO_Bounded_Abstract_Sequence<T, T_var, MAX>::allocbuf (
02061                 rhs.maximum_
02062               );
02063         }
02064     }
02065 
02066   TAO_Bounded_Base_Sequence::operator= (rhs);
02067 
02068   T **tmp1 = ACE_reinterpret_cast (T **, 
02069                                    this->buffer_);
02070   T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
02071                                           rhs.buffer_);
02072 
02073   for (CORBA::ULong i=0; i < rhs.length_; ++i)
02074     {
02075       tmp1[i] = T_var::tao_duplicate (tmp2[i]);
02076     }
02077 
02078   return *this;
02079 }

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

Read-write accessor.

Definition at line 755 of file Sequence_T.i.

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

00758 {
00759   ACE_ASSERT (slot < this->maximum_);
00760   T **const tmp = ACE_reinterpret_cast (T ** ACE_CAST_CONST, this->buffer_);
00761   return TAO_Abstract_Manager<T,T_var> (tmp + slot, this->release_);
00762 }


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