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

TAO_Unbounded_Array_Sequence Class Template Reference

Parametric sequence for arrays. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Unbounded_Array_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Unbounded_Array_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Unbounded_Array_Sequence (void)
 default ctor. More...

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

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

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

 ~TAO_Unbounded_Array_Sequence (void)
 dtor releases all the contained elements. More...

TAO_Unbounded_Array_Sequence<
T, T_var > & 
operator= (const TAO_Unbounded_Array_Sequence< T, T_var > &)
T & operator[] (CORBA::ULong)
 operator[]. More...

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

virtual void _allocate_buffer (CORBA::ULong length)
 allocate a buffer of the requested length. The buffer is allocated for the right type. More...

virtual void _deallocate_buffer (void)
 deallocate the buffer. 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)
 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_Array_Sequence< T, T_var >

Parametric sequence for arrays.

The IDL mapping for arrays includes some unique allocation, deallocation, and copying functions, and precludes direct assignment of one array to another. Also, the Any and CDR operators use a special class derived from the array. For these reasons, we use a special class for sequences of arrays, parametrized on the array element type.

Definition at line 1176 of file Sequence_T.h.


Constructor & Destructor Documentation

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

default ctor.

Definition at line 779 of file Sequence_T.i.

00780 {
00781 }

template<class T, class T_var>
ACE_INLINE TAO_Unbounded_Array_Sequence< T, T_var >::TAO_Unbounded_Array_Sequence CORBA::ULong    max
 

Constructor with a "hint" for the maximum capacity.

Definition at line 785 of file Sequence_T.i.

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

Constructor with a given buffer.

Definition at line 793 of file Sequence_T.i.

00797   : TAO_Unbounded_Base_Sequence (maximum, length, value, release)
00798 {
00799 }

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

Copy ctor, deep copies.

Definition at line 2175 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

02178   : TAO_Unbounded_Base_Sequence (rhs)
02179 {
02180   if (rhs.buffer_ != 0)
02181     {
02182       T *tmp1 =
02183         TAO_Unbounded_Array_Sequence<T, T_var>::allocbuf (this->maximum_);
02184 
02185 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02186       const T *tmp2 = (const T *) rhs.buffer_;
02187 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02188       const T *tmp2 = ACE_reinterpret_cast (const T *,
02189                                             rhs.buffer_);
02190 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02191 
02192       for (CORBA::ULong i = 0; i < rhs.length_; ++i)
02193         {
02194           T_var::copy (tmp1[i], tmp2[i]);
02195         }
02196 
02197       this->buffer_ = tmp1;
02198     }
02199   else
02200     {
02201       this->buffer_ = 0;
02202     }
02203 }

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

dtor releases all the contained elements.

Definition at line 2206 of file Sequence_T.cpp.

References _deallocate_buffer.

02207 {
02208   this->_deallocate_buffer ();
02209 }


Member Function Documentation

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

allocate a buffer of the requested length. The buffer is allocated for the right type.

Implements TAO_Base_Sequence.

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

02282 {
02283   T *tmp = TAO_Unbounded_Array_Sequence<T, T_var>::allocbuf (length);
02284 
02285   if (this->buffer_ != 0)
02286     {
02287 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02288       T *old = (T *) this->buffer_;
02289 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02290       T *old = ACE_reinterpret_cast (T *,
02291                                      this->buffer_);
02292 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02293 
02294       for (CORBA::ULong i = 0; i < this->length_; ++i)
02295         {
02296           T_var::copy (tmp[i], old[i]);
02297         }
02298 
02299       if (this->release_)
02300         {
02301           delete [] old;
02302         }
02303     }
02304 
02305   this->buffer_ = tmp;
02306 }

template<class T, class T_var>
void TAO_Unbounded_Array_Sequence< T, T_var >::_deallocate_buffer void    [virtual]
 

deallocate the buffer.

Implements TAO_Base_Sequence.

Definition at line 2309 of file Sequence_T.cpp.

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

Referenced by ~TAO_Unbounded_Array_Sequence.

02310 {
02311   if (this->buffer_ == 0 || this->release_ == 0)
02312     {
02313       return;
02314     }
02315 
02316 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02317   T *tmp = (T *) this->buffer_;
02318 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02319   T *tmp = ACE_reinterpret_cast (T *,
02320                                  this->buffer_);
02321 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02322 
02323   TAO_Unbounded_Array_Sequence<T, T_var>::freebuf (tmp);
02324 
02325   this->buffer_ = 0;
02326 }

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

References ACE_NEW_RETURN.

Referenced by _allocate_buffer, get_buffer, operator=, and TAO_Unbounded_Array_Sequence.

02165 {
02166   T *buf = 0;
02167   ACE_NEW_RETURN (buf,
02168                   T[nelems],
02169                   0);
02170 
02171   return buf;
02172 }

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

Release all the elements.

Definition at line 769 of file Sequence_T.i.

Referenced by _deallocate_buffer, operator=, and replace.

00770 {
00771   if (buffer == 0)
00772     return;
00773 
00774   delete [] buffer;
00775 }

template<class T, class T_var>
ACE_INLINE const T * TAO_Unbounded_Array_Sequence< T, T_var >::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 870 of file Sequence_T.i.

00871 {
00872   return ACE_reinterpret_cast (const T * ACE_CAST_CONST, 
00873                                this->buffer_);
00874 }

template<class T, class T_var>
ACE_INLINE T * TAO_Unbounded_Array_Sequence< T, T_var >::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.

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 826 of file Sequence_T.i.

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

00827 {
00828   T *result = 0;
00829   if (orphan == 0)
00830     {
00831       // We retain ownership.
00832 
00833       if (this->buffer_ == 0)
00834         {
00835           if (this->length_ > 0)
00836             {
00837               result = 
00838                 TAO_Unbounded_Array_Sequence<T, T_var>::allocbuf (
00839                     this->length_
00840                   );
00841               this->buffer_ = result;
00842               this->release_ = 1;
00843             }
00844         }
00845       else
00846         {
00847           result =
00848             ACE_reinterpret_cast (T*, 
00849                                   this->buffer_);
00850         }
00851     }
00852   else // if (orphan == 1)
00853     {
00854       if (this->release_ != 0)
00855         {
00856           // We set the state back to default and relinquish
00857           // ownership.
00858           result = ACE_reinterpret_cast (T*,
00859                                          this->buffer_);
00860           this->maximum_ = 0;
00861           this->length_ = 0;
00862           this->buffer_ = 0;
00863           this->release_ = 0;
00864         }
00865     }
00866   return result;
00867 }

template<class T, class T_var>
TAO_Unbounded_Array_Sequence< T, T_var > & TAO_Unbounded_Array_Sequence< T, T_var >::operator= const TAO_Unbounded_Array_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 2213 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_.

02216 {
02217   if (this == &rhs)
02218     {
02219       return *this;
02220     }
02221 
02222   if (this->release_)
02223     {
02224       if (this->maximum_ < rhs.maximum_)
02225         {
02226           // free the old buffer
02227 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02228           T *tmp = (T *) this->buffer_;
02229 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02230           T *tmp = ACE_reinterpret_cast (T *,
02231                                          this->buffer_);
02232 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02233 
02234           TAO_Unbounded_Array_Sequence<T, T_var>::freebuf (tmp);
02235 
02236           if (rhs.maximum_ == 0)
02237             {
02238               this->buffer_ = 0;
02239             }
02240           else
02241             {
02242               this->buffer_ =
02243                 TAO_Unbounded_Array_Sequence<T, T_var>::allocbuf (
02244                     rhs.maximum_
02245                   );
02246             }
02247         }
02248     }
02249   else
02250     {
02251       if (rhs.maximum_ == 0)
02252         {
02253           this->buffer_ = 0;
02254         }
02255       else
02256         {
02257           this->buffer_ =
02258             TAO_Unbounded_Array_Sequence<T,T_var>::allocbuf (rhs.maximum_);
02259         }
02260     }
02261 
02262   TAO_Unbounded_Base_Sequence::operator= (rhs);
02263 
02264   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
02265     {
02266 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02267       T_var::copy (((T *) this->buffer_)[i],
02268                    ((const T *) rhs.buffer_)[i]);
02269 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02270       T_var::copy (ACE_reinterpret_cast (T *,
02271                                          this->buffer_)[i],
02272                    ACE_reinterpret_cast (const T *,
02273                                          rhs.buffer_)[i]);
02274 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02275     }
02276 
02277   return *this;
02278 }

template<class T, class T_var>
ACE_INLINE const T & TAO_Unbounded_Array_Sequence< T, T_var >::operator[] CORBA::ULong    const
 

operator[].

Definition at line 814 of file Sequence_T.i.

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

00815 {
00816   ACE_ASSERT (i < this->maximum_);
00817 
00818 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
00819   return ((const T* ACE_CAST_CONST) this->buffer_)[i];
00820 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00821   return (ACE_reinterpret_cast (const T* ACE_CAST_CONST, this->buffer_))[i];
00822 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00823 }

template<class T, class T_var>
ACE_INLINE T & TAO_Unbounded_Array_Sequence< T, T_var >::operator[] CORBA::ULong   
 

operator[].

Definition at line 802 of file Sequence_T.i.

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

00803 {
00804   ACE_ASSERT (i < this->maximum_);
00805 
00806 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
00807   return ((T*) this->buffer_)[i];
00808 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00809   return (ACE_reinterpret_cast (T*, this->buffer_))[i];
00810 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00811 }

template<class T, class T_var>
ACE_INLINE void TAO_Unbounded_Array_Sequence< T, T_var >::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 877 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_.

00881 {
00882   this->maximum_ = max;
00883   this->length_ = length;
00884   if (this->buffer_ && this->release_ == 1)
00885     {
00886       T *tmp = ACE_reinterpret_cast (T*,
00887                                      this->buffer_);
00888       TAO_Unbounded_Array_Sequence<T, T_var>::freebuf (tmp);
00889     }
00890   this->buffer_ = data;
00891   this->release_ = release;
00892 }


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