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

TAO_Bounded_Pseudo_Sequence Class Template Reference

Bounded version of TAO_Unbounded_Pseudo_Sequence. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Bounded_Pseudo_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Bounded_Pseudo_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Bounded_Pseudo_Sequence (void)
 default ctor. More...

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

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

 ~TAO_Bounded_Pseudo_Sequence (void)
 destructor. More...

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

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 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_Pseudo_Sequence< T, T_var, MAX >

Bounded version of TAO_Unbounded_Pseudo_Sequence.

Please see the documentation for the unbounded case.

Definition at line 884 of file Sequence_T.h.


Constructor & Destructor Documentation

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

default ctor.

Definition at line 1201 of file Sequence_T.cpp.

01202   : TAO_Bounded_Base_Sequence (
01203         MAX,
01204         TAO_Bounded_Pseudo_Sequence<T, T_var,MAX>::allocbuf (MAX)
01205       )
01206 {
01207 }

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

Constructor from data.

Definition at line 604 of file Sequence_T.i.

00607   : TAO_Bounded_Base_Sequence (MAX, length, value, release)
00608 {
00609 }

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

Copy constructor.

Definition at line 1210 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

01213   : TAO_Bounded_Base_Sequence (rhs)
01214 {
01215   if (rhs.buffer_ != 0)
01216     {
01217       T **tmp1 =
01218         TAO_Bounded_Pseudo_Sequence<T, T_var,MAX>::allocbuf (MAX);
01219 
01220       T ** const tmp2 =
01221        ACE_reinterpret_cast (T** ACE_CAST_CONST, rhs.buffer_);
01222 
01223       for (CORBA::ULong i = 0; i < rhs.length_; i++)
01224         {
01225           tmp1[i] = T::_duplicate (tmp2[i]);
01226         }
01227 
01228       this->buffer_ = tmp1;
01229     }
01230   else
01231     {
01232       this->buffer_ = 0;
01233     }
01234 }

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

destructor.

Definition at line 597 of file Sequence_T.i.

References _deallocate_buffer.

00598 {
00599   this->_deallocate_buffer ();
00600 }


Member Function Documentation

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

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

01323 {
01324   // For this class memory is never reallocated so the implementation
01325   // is *really* simple.
01326   this->buffer_ =
01327     TAO_Bounded_Pseudo_Sequence<T, T_var,MAX>::allocbuf (length);
01328 }

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

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

Referenced by ~TAO_Bounded_Pseudo_Sequence.

01332 {
01333   if (this->release_ == 0)
01334     {
01335       return;
01336     }
01337 
01338   T **tmp = ACE_reinterpret_cast (T **, 
01339                                   this->buffer_);
01340   TAO_Bounded_Pseudo_Sequence<T, T_var, MAX>::freebuf (tmp);
01341   this->buffer_ = 0;
01342 }

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

References CORBA::release.

01347 {
01348   T **tmp = ACE_reinterpret_cast (T **, 
01349                                   this->buffer_);
01350 
01351   for (CORBA::ULong i = nl; i < ol; ++i)
01352     {
01353       CORBA::release (tmp[i]);
01354       tmp[i] = T::_nil ();
01355     }
01356 }

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

Allocate storage for a sequence..

Definition at line 1288 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Bounded_Pseudo_Sequence.

01289 {
01290   T **buf = 0;
01291   ACE_NEW_RETURN (buf, 
01292                   T*[MAX], 
01293                   0);
01294 
01295   for (CORBA::ULong i = 0; i < MAX; ++i)
01296     {
01297       buf[i] = T::_nil ();
01298     }
01299 
01300   return buf;
01301 }

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

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

Definition at line 1304 of file Sequence_T.cpp.

References CORBA::release.

Referenced by _deallocate_buffer.

01305 {
01306   // How much do we deallocate? Easy! allocbuf() always creates MAX
01307   // elements and initialize them to T::_nil().  So we can be
01308   // complaint and call CORBA::release() on each one.
01309   for (CORBA::ULong i = 0; i < MAX; ++i)
01310     {
01311       if (buffer[i] != T::_nil ())
01312         {
01313           CORBA::release (buffer[i]);
01314           buffer[i] = T::_nil ();
01315         }
01316     }
01317 
01318   delete [] buffer;
01319 }

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

Assignment from another Bounded sequence.

Definition at line 1237 of file Sequence_T.cpp.

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

01240 {
01241   if (this == &rhs)
01242     {
01243       return *this;
01244     }
01245 
01246   if (this->release_)
01247     {
01248       T **tmp = ACE_reinterpret_cast (T **, 
01249                                       this->buffer_);
01250 
01251       for (CORBA::ULong i = 0; i < this->length_; ++i)
01252         {
01253           CORBA::release (tmp[i]);
01254           tmp[i] = T::_nil ();
01255         }
01256       // No need to reallocate the buffer since it is always of size
01257       // MAX
01258     }
01259   else
01260     {
01261       if (rhs.maximum_ == 0)
01262         {
01263           this->buffer_ = 0;
01264         }
01265       else
01266         {
01267           this->buffer_ =
01268             TAO_Bounded_Pseudo_Sequence<T,T_var,MAX>::allocbuf (rhs.maximum_);
01269         }
01270     }
01271 
01272   TAO_Bounded_Base_Sequence::operator= (rhs);
01273 
01274   T **tmp1 = ACE_reinterpret_cast (T **, 
01275                                    this->buffer_);
01276   T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
01277                                           rhs.buffer_);
01278 
01279   for (CORBA::ULong i=0; i < rhs.length_; ++i)
01280     {
01281       tmp1[i] = T::_duplicate (tmp2[i]);
01282     }
01283 
01284   return *this;
01285 }

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

Read-write accessor.

Definition at line 612 of file Sequence_T.i.

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

00613 {
00614   ACE_ASSERT (slot < this->maximum_);
00615   T **const tmp = ACE_reinterpret_cast (T ** ACE_CAST_CONST,
00616                                         this->buffer_);
00617   return TAO_Pseudo_Object_Manager<T,T_var> (tmp + slot,
00618                                              this->release_);
00619 }


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