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

TAO_Unbounded_Sequence Class Template Reference

Parametrized implementation of IDL unbounded sequences. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Unbounded_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Unbounded_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Unbounded_Sequence (void)
 Default constructor. More...

 TAO_Unbounded_Sequence (CORBA::ULong max)
 Constructor using a maximum length value. More...

 TAO_Unbounded_Sequence (CORBA::ULong max, CORBA::ULong length, T *data, CORBA::Boolean release=0)
 TAO_Unbounded_Sequence (const TAO_Unbounded_Sequence< T > &)
 Copy constructor. More...

TAO_Unbounded_Sequence< T > & operator= (const TAO_Unbounded_Sequence< T > &)
 Assignment operator. More...

 ~TAO_Unbounded_Sequence (void)
 Dtor. More...

T & operator[] (CORBA::ULong)
 operator[]. More...

const T & operator[] (CORBA::ULong) const
 operator[]. More...

virtual void _allocate_buffer (CORBA::ULong length)
 Implement the TAO_Base_Sequence methods (see Sequence.h). More...

virtual void _deallocate_buffer (void)
 Must deallocate the buffer and then set it to zero. More...

T * get_buffer (CORBA::Boolean orphan=0)
const T * get_buffer (void) const
void replace (CORBA::ULong max, CORBA::ULong length, T *data, CORBA::Boolean release=0)

Static Public Methods

T * allocbuf (CORBA::ULong)
 Allocate storage for the sequence. More...

void freebuf (T *)
 Free the sequence. More...


Detailed Description

template<class T>
class TAO_Unbounded_Sequence< T >

Parametrized implementation of IDL unbounded sequences.

This class completes the implementation for TAO_Base_Sequence for the unbounded case.

Definition at line 34 of file Sequence_T.h.


Constructor & Destructor Documentation

template<class T>
ACE_INLINE TAO_Unbounded_Sequence< T >::TAO_Unbounded_Sequence void   
 

Default constructor.

Definition at line 21 of file Sequence_T.i.

00022 {
00023 }

template<class T>
ACE_INLINE TAO_Unbounded_Sequence< T >::TAO_Unbounded_Sequence CORBA::ULong    max
 

Constructor using a maximum length value.

Definition at line 26 of file Sequence_T.i.

template<class T>
ACE_INLINE TAO_Unbounded_Sequence< T >::TAO_Unbounded_Sequence CORBA::ULong    max,
CORBA::ULong    length,
T *    data,
CORBA::Boolean    release = 0
 

Constructor using the data and memory management flag. Memory *must* be allocated using the allocbuf static method, since in the future this classes may use a global ACE_Allocator.

Definition at line 33 of file Sequence_T.i.

00037   : TAO_Unbounded_Base_Sequence (maximum, length, data, release)
00038 {
00039 }

template<class T>
TAO_Unbounded_Sequence< T >::TAO_Unbounded_Sequence const TAO_Unbounded_Sequence< T > &   
 

Copy constructor.

Definition at line 18 of file Sequence_T.cpp.

References allocbuf, TAO_Base_Sequence::buffer_, and TAO_Base_Sequence::length_.

00021   : TAO_Unbounded_Base_Sequence (rhs)
00022 {
00023   if (rhs.buffer_ != 0)
00024     {
00025       T *tmp1 = TAO_Unbounded_Sequence<T>::allocbuf (this->maximum_);
00026       T * const tmp2 =
00027         ACE_reinterpret_cast (T * ACE_CAST_CONST, rhs.buffer_);
00028 
00029       for (CORBA::ULong i = 0; i < this->length_; ++i)
00030         {
00031           tmp1[i] = tmp2[i];
00032         }
00033 
00034       this->buffer_ = tmp1;
00035     }
00036   else
00037     {
00038       this->buffer_ = 0;
00039     }
00040 }

template<class T>
TAO_Unbounded_Sequence< T >::~TAO_Unbounded_Sequence void   
 

Dtor.

Definition at line 91 of file Sequence_T.cpp.

References _deallocate_buffer.

00092 {
00093   this->_deallocate_buffer ();
00094 }


Member Function Documentation

template<class T>
void TAO_Unbounded_Sequence< T >::_allocate_buffer CORBA::ULong    length [virtual]
 

Implement the TAO_Base_Sequence methods (see Sequence.h).

Implements TAO_Base_Sequence.

Definition at line 97 of file Sequence_T.cpp.

References allocbuf, TAO_Base_Sequence::buffer_, freebuf, TAO_Unbounded_Base_Sequence::length, TAO_Base_Sequence::length_, and TAO_Base_Sequence::release_.

00098 {
00099   T* tmp = TAO_Unbounded_Sequence<T>::allocbuf (length);
00100 
00101   if (this->buffer_ != 0)
00102     {
00103       T *old = ACE_reinterpret_cast (T *,
00104                                      this->buffer_);
00105 
00106       for (CORBA::ULong i = 0; i < this->length_; ++i)
00107         {
00108           tmp[i] = old[i];
00109         }
00110 
00111       if (this->release_)
00112         {
00113           TAO_Unbounded_Sequence<T>::freebuf (old);
00114         }
00115     }
00116 
00117   this->buffer_ = tmp;
00118 }

template<class T>
void TAO_Unbounded_Sequence< T >::_deallocate_buffer void    [virtual]
 

Must deallocate the buffer and then set it to zero.

Implements TAO_Base_Sequence.

Definition at line 121 of file Sequence_T.cpp.

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

Referenced by ~TAO_Unbounded_Sequence.

00122 {
00123   if (this->release_ == 0)
00124     {
00125       return;
00126     }
00127 
00128   T *tmp = ACE_reinterpret_cast (T *,
00129                                  this->buffer_);
00130 
00131   TAO_Unbounded_Sequence<T>::freebuf (tmp);
00132   this->buffer_ = 0;
00133 }

template<class T>
ACE_INLINE T * TAO_Unbounded_Sequence< T >::allocbuf CORBA::ULong    [static]
 

Allocate storage for the sequence.

Definition at line 9 of file Sequence_T.i.

Referenced by _allocate_buffer, get_buffer, operator=, TAO_Unbounded_Sequence, TAO_Unbounded_Sequence< CORBA::Octet >::_allocate_buffer, TAO_Unbounded_Sequence< CORBA::Octet >::get_buffer, TAO_Unbounded_Sequence< CORBA::Octet >::operator=, and TAO_Unbounded_Sequence< CORBA::Octet >::TAO_Unbounded_Sequence.

00010 {
00011   return new T[size];
00012 }

template<class T>
ACE_INLINE void TAO_Unbounded_Sequence< T >::freebuf T *    [static]
 

Free the sequence.

Definition at line 15 of file Sequence_T.i.

Referenced by _allocate_buffer, _deallocate_buffer, operator=, replace, TAO_Unbounded_Sequence< CORBA::Octet >::_allocate_buffer, TAO_Unbounded_Sequence< CORBA::Octet >::_deallocate_buffer, TAO_Unbounded_Sequence< CORBA::Octet >::operator=, and TAO_Unbounded_Sequence< CORBA::Octet >::replace.

00016 {
00017   delete [] buffer;
00018 }

template<class T>
ACE_INLINE const T * TAO_Unbounded_Sequence< T >::get_buffer void    const
 

This function allows read-only access to the sequence buffer. The sequence returns its buffer, allocating one of one has not yet been allocated. No direct modification of the returned buffer by the caller is permitted.

Definition at line 84 of file Sequence_T.i.

00085 {
00086   return ACE_reinterpret_cast (const T * ACE_CAST_CONST, this->buffer_);
00087 }

template<class T>
ACE_INLINE T * TAO_Unbounded_Sequence< T >::get_buffer CORBA::Boolean    orphan = 0
 

Allows read-write access to the underlying buffer. If <orphan> is FALSE the sequence returns a pointer to its buffer, allocating one if it has not yet done so. The number of elements in the buffer can be determined from the sequence <length> accessor.

If the <orphan> argument to <get_buffer> is FALSE, the sequence maintains ownership of the underlying buffer. Elements in the returned buffer may be directly replaced by the caller. For sequences of strings, wide strings, and object references, the caller must use the sequence <release> accessor to determine whether elements should be freed (using <string_free>, <wstring_free>, or <CORBA::release> for strings, wide straings, and object references, respective) before being directly assigned to.

If the <orphan> argument to <get_buffer> is TRUE, the sequence yields ownership of the buffer to the caller. If <orphan> is TRUE and the sequence does not own its buffer (i.e., its <release> flag is FALSE), the return value is a null pointer. If the buffer is taken from the sequence using this form of <get_buffer>, the sequence reverts to the same state it would have if constructed using its default constructor. The caller becomes responsible for eventually freeing each element of the returned buffer (for strings, wide string, and object references), and then freeing the returned buffer itself using <freebuf>.

Definition at line 42 of file Sequence_T.i.

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

00043 {
00044   T *result = 0;
00045   if (orphan == 0)
00046     {
00047       // We retain ownership.
00048       if (this->buffer_ == 0)
00049         {
00050           if (this->length_ > 0)
00051             {
00052               result = TAO_Unbounded_Sequence<T>::allocbuf (this->length_);
00053               this->buffer_ = result;
00054               this->release_ = 1;
00055             }
00056         }
00057       else
00058         {
00059           result =
00060             ACE_reinterpret_cast (T*, 
00061                                   this->buffer_);
00062         }
00063     }
00064   else // if (orphan == 1)
00065     {
00066       result = ACE_reinterpret_cast (T*,
00067                                      this->buffer_);
00068 
00069       if (this->release_ != 0)
00070         {
00071           // We set the state back to default and relinquish
00072           // ownership.
00073           this->maximum_ = 0;
00074           this->length_ = 0;
00075           this->buffer_ = 0;
00076           this->release_ = 0;
00077         }
00078     }
00079 
00080   return result;
00081 }

template<class T>
TAO_Unbounded_Sequence< T > & TAO_Unbounded_Sequence< T >::operator= const TAO_Unbounded_Sequence< T > &   
 

Assignment operator.

Definition at line 43 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_.

Referenced by TAO_ObjectKey::operator=.

00044 {
00045   if (this == &rhs)
00046     {
00047       return *this;
00048     }
00049 
00050   if (this->release_)
00051     {
00052       if (this->maximum_ < rhs.maximum_)
00053         {
00054           // Free the old buffer.
00055           T *tmp = ACE_reinterpret_cast (T *,
00056                                          this->buffer_);
00057           TAO_Unbounded_Sequence<T>::freebuf (tmp);
00058           this->buffer_ =
00059             TAO_Unbounded_Sequence<T>::allocbuf (rhs.maximum_);
00060         }
00061     }
00062   else
00063     {
00064       if (rhs.maximum_ == 0)
00065         {
00066           this->buffer_ = 0;
00067         }
00068       else
00069         {
00070           this->buffer_ =
00071             TAO_Unbounded_Sequence<T>::allocbuf (rhs.maximum_);
00072         }
00073     }
00074 
00075   TAO_Unbounded_Base_Sequence::operator= (rhs);
00076 
00077   T *tmp1 = ACE_reinterpret_cast (T *, 
00078                                   this->buffer_);
00079   T * const tmp2 = ACE_reinterpret_cast (T * ACE_CAST_CONST, 
00080                                          rhs.buffer_);
00081 
00082   for (CORBA::ULong i = 0; i < this->length_; ++i)
00083     {
00084       tmp1[i] = tmp2[i];
00085     }
00086 
00087   return *this;
00088 }

template<class T>
const T & TAO_Unbounded_Sequence< T >::operator[] CORBA::ULong    const
 

operator[].

Definition at line 150 of file Sequence_T.cpp.

References ACE_ASSERT, and TAO_Base_Sequence::maximum_.

00151 {
00152   ACE_ASSERT (i < this->maximum_);
00153   T * const tmp = ACE_reinterpret_cast (T* ACE_CAST_CONST, 
00154                                         this->buffer_);
00155   ACE_ASSERT (tmp != 0);
00156   return tmp[i];
00157 }

template<class T>
T & TAO_Unbounded_Sequence< T >::operator[] CORBA::ULong   
 

operator[].

Definition at line 138 of file Sequence_T.cpp.

References ACE_ASSERT, and TAO_Base_Sequence::maximum_.

00139 {
00140   ACE_ASSERT (i < this->maximum_);
00141   T* tmp = ACE_reinterpret_cast (T *,
00142                                  this->buffer_);
00143   ACE_ASSERT (tmp != 0);
00144   return tmp[i];
00145 }

template<class T>
ACE_INLINE void TAO_Unbounded_Sequence< T >::replace CORBA::ULong    max,
CORBA::ULong    length,
T *    data,
CORBA::Boolean    release = 0
 

Allows the buffer underlying a sequence to be replaced. The parameters to <replace> are identical in type, order, and purpose to those for the <T *data> constructor for the sequence.

Definition at line 90 of file Sequence_T.i.

References TAO_Base_Sequence::buffer_, freebuf, TAO_Unbounded_Base_Sequence::length, TAO_Base_Sequence::length_, TAO_Base_Sequence::maximum_, TAO_Base_Sequence::release, and TAO_Base_Sequence::release_.

Referenced by operator>>.

00094 {
00095   this->maximum_ = max;
00096   this->length_ = length;
00097   if (this->buffer_ && this->release_ == 1)
00098     {
00099       T *tmp = ACE_reinterpret_cast(T*,this->buffer_);
00100       TAO_Unbounded_Sequence<T>::freebuf (tmp);
00101     }
00102   this->buffer_ = data;
00103   this->release_ = release;
00104 }


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