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

TAO_Unbounded_Valuetype_Sequence Class Template Reference

Parametric sequence for valuetypes. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Unbounded_Valuetype_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Unbounded_Valuetype_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

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

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

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

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

TAO_Unbounded_Valuetype_Sequence<
T, T_var > & 
operator= (const TAO_Unbounded_Valuetype_Sequence< T, T_var > &)
TAO_Valuetype_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_Valuetype_Sequence< T, T_var >

Parametric sequence for valuetypes.

See also:
TAO_Unbounded_Object_Sequence

Definition at line 933 of file Sequence_T.h.


Constructor & Destructor Documentation

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

Definition at line 628 of file Sequence_T.i.

00631 {
00632 }

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

Constructor with a "hint" for the maximum capacity.

Definition at line 1364 of file Sequence_T.cpp.

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

Constructor with a given buffer.

Definition at line 636 of file Sequence_T.i.

00642   : TAO_Unbounded_Base_Sequence (maximum, length, value, release)
00643 {
00644 }

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

Copy ctor, deep copies.

Definition at line 1375 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

01378   : TAO_Unbounded_Base_Sequence (rhs)
01379 {
01380   if (rhs.buffer_ != 0)
01381     {
01382       T **tmp1 =
01383         TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (this->maximum_);
01384       T ** const tmp2 =
01385         ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
01386                               rhs.buffer_);
01387 
01388       for (CORBA::ULong i = 0; i < rhs.length_; ++i)
01389         {
01390           T_var::tao_add_ref (tmp2[i]);
01391           tmp1[i] = tmp2[i];
01392         }
01393 
01394       this->buffer_ = tmp1;
01395     }
01396   else
01397     {
01398       this->buffer_ = 0;
01399     }
01400 }

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

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

Definition at line 1403 of file Sequence_T.cpp.

References _deallocate_buffer.

01406 {
01407   this->_deallocate_buffer ();
01408 }


Member Function Documentation

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

01517 {
01518   T **tmp = TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (length);
01519 
01520   if (this->buffer_ != 0)
01521     {
01522       T **old = ACE_reinterpret_cast (T**, 
01523                                       this->buffer_);
01524 
01525       for (CORBA::ULong i = 0; i < this->length_; ++i)
01526         // Only call duplicate when we did not own the previous
01527         // buffer, since after this method we own it we must also own
01528         // the objects.  If we already own the objects there is no
01529         // need to copy them, if we did we would also have to remove
01530         // the old instances.
01531         if (!this->release_)
01532           {
01533             T_var::tao_add_ref (tmp[i]);
01534             tmp[i] = old[i];
01535           }
01536         else
01537           {
01538             tmp[i] = old[i];
01539           }
01540 
01541       if (this->release_)
01542         {
01543           delete [] old;
01544         }
01545     }
01546 
01547   this->buffer_ = tmp;
01548 }

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

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

Referenced by ~TAO_Unbounded_Valuetype_Sequence.

01552 {
01553   if (this->buffer_ == 0 || this->release_ == 0)
01554     {
01555       return;
01556     }
01557 
01558   T **tmp = ACE_reinterpret_cast (T**, 
01559                                   this->buffer_);
01560 
01561   for (CORBA::ULong i = 0; i < this->length_; ++i)
01562     {
01563       T_var::tao_remove_ref (tmp[i]);
01564       tmp[i] = 0;
01565     }
01566 
01567   TAO_Unbounded_Valuetype_Sequence<T, T_var>::freebuf (tmp);
01568   this->buffer_ = 0;
01569 }

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

01574 {
01575   T **tmp = ACE_static_cast (T**, 
01576                              this->buffer_);
01577 
01578   for (CORBA::ULong i = nl; i < ol; ++i)
01579     {
01580       T_var::tao_remove_ref (tmp[i]);
01581       tmp[i] = 0;
01582     }
01583 }

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

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, operator=, and TAO_Unbounded_Valuetype_Sequence.

01474 {
01475   T **buf = 0;
01476   ACE_NEW_RETURN (buf, 
01477                   T*[nelems], 
01478                   0);
01479 
01480   for (CORBA::ULong i = 0; i < nelems; i++)
01481     {
01482       buf[i] = 0;
01483     }
01484 
01485   return buf;
01486 }

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

Release all the elements.

Definition at line 1490 of file Sequence_T.cpp.

Referenced by _deallocate_buffer, and operator=.

01491 {
01492   if (buffer == 0)
01493     {
01494       return;
01495     }
01496 
01497   // {orbos/97-05-15:16.11} The freebuf function ensures that the
01498   // destructor for each element is called before the buffer is
01499   // destroyed, except for string elements, which are freed using
01500   // string_free(), and object reference elements, which are freed
01501   // using release(). The freebuf function will ignore null pointers
01502   // passed to it.
01503 
01504   // @@ How are we supposed to implement that! We don't know the
01505   // length of the buffer here.
01506   // Mark the length in the first four bytes? For the moment we let
01507   // that be.
01508 
01509   delete [] buffer;
01510 }

template<class T, class T_var>
TAO_Unbounded_Valuetype_Sequence< T, T_var > & TAO_Unbounded_Valuetype_Sequence< T, T_var >::operator= const TAO_Unbounded_Valuetype_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 1413 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_.

01416 {
01417   if (this == &rhs)
01418     {
01419       return *this;
01420     }
01421 
01422   if (this->release_)
01423     {
01424       T **tmp = ACE_reinterpret_cast (T **,
01425                                       this->buffer_);
01426 
01427       for (CORBA::ULong i = 0; i < this->length_; ++i)
01428         {
01429           T_var::tao_remove_ref (tmp[i]);
01430           tmp[i] = 0;
01431         }
01432 
01433       if (this->maximum_ < rhs.maximum_)
01434         {
01435           TAO_Unbounded_Valuetype_Sequence<T, T_var>::freebuf (tmp);
01436           this->buffer_ =
01437             TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (rhs.maximum_);
01438         }
01439     }
01440   else
01441     {
01442       if (rhs.maximum_ == 0)
01443         {
01444           this->buffer_ = 0;
01445         }
01446       else
01447         {
01448           this->buffer_ =
01449             TAO_Unbounded_Valuetype_Sequence<T, T_var>::allocbuf (
01450                 rhs.maximum_
01451               );
01452         }
01453     }
01454 
01455   TAO_Unbounded_Base_Sequence::operator= (rhs);
01456 
01457   T **tmp1 = ACE_reinterpret_cast (T **, 
01458                                    this->buffer_);
01459   T ** const tmp2 = ACE_reinterpret_cast (T ** ACE_CAST_CONST, 
01460                                           rhs.buffer_);
01461 
01462   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
01463     {
01464       T_var::tao_add_ref (tmp2[i]);
01465       tmp1[i] = tmp2[i];
01466     }
01467 
01468   return *this;
01469 }

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

read-write accessor.

Definition at line 649 of file Sequence_T.i.

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

00652 {
00653   ACE_ASSERT (slot < this->maximum_);
00654   T ** const tmp = ACE_reinterpret_cast (T ** ACE_CAST_CONST, this->buffer_);
00655   return TAO_Valuetype_Manager<T,T_var> (tmp + slot, this->release_);
00656 }


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