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

TAO_Bounded_Array_Sequence Class Template Reference

Bounded version of TAO_Unbounded_Array_Sequence. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Bounded_Array_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Bounded_Array_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Bounded_Array_Sequence (void)
 default ctor. More...

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

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

 ~TAO_Bounded_Array_Sequence (void)
 destructor. More...

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

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

Bounded version of TAO_Unbounded_Array_Sequence.

Please see the documentation for the unbounded case.

Definition at line 1283 of file Sequence_T.h.


Constructor & Destructor Documentation

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

default ctor.

Definition at line 909 of file Sequence_T.i.

00910   : TAO_Bounded_Base_Sequence (MAX, 0, allocbuf (MAX), 1)
00911 {
00912 }

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

Constructor from data.

Definition at line 916 of file Sequence_T.i.

00919   : TAO_Bounded_Base_Sequence (MAX, length, data, release)
00920 {
00921 }

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

Copy constructor.

Definition at line 2344 of file Sequence_T.cpp.

References allocbuf, and TAO_Base_Sequence::buffer_.

02347   : TAO_Bounded_Base_Sequence (rhs)
02348 {
02349   if (rhs.buffer_ != 0)
02350     {
02351       T *tmp1 =
02352         TAO_Bounded_Array_Sequence<T, T_var, MAX>::allocbuf (MAX);
02353 
02354 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02355       const T *tmp2 = (const T *) rhs.buffer_;
02356 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02357       const T *tmp2 = ACE_reinterpret_cast (const T *,
02358                                             rhs.buffer_);
02359 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02360 
02361       for (CORBA::ULong i = 0; i < rhs.length_; i++)
02362         {
02363           T_var::copy (tmp1[i], tmp2[i]);
02364         }
02365 
02366       this->buffer_ = tmp1;
02367     }
02368   else
02369     {
02370       this->buffer_ = 0;
02371     }
02372 }

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

destructor.

Definition at line 2375 of file Sequence_T.cpp.

References _deallocate_buffer.

02376 {
02377   this->_deallocate_buffer ();
02378 }


Member Function Documentation

template<class T, class T_var, size_t MAX>
void TAO_Bounded_Array_Sequence< T, T_var, MAX >::_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 2427 of file Sequence_T.cpp.

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

02428 {
02429   // For this class memory is never reallocated so the implementation
02430   // is *really* simple.
02431   this->buffer_ =
02432     TAO_Bounded_Array_Sequence<T, T_var, MAX>::allocbuf (length);
02433 }

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

deallocate the buffer.

Implements TAO_Base_Sequence.

Definition at line 2436 of file Sequence_T.cpp.

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

Referenced by ~TAO_Bounded_Array_Sequence.

02437 {
02438   if (this->buffer_ == 0 || this->release_ == 0)
02439     {
02440       return;
02441     }
02442 
02443 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02444   T *tmp = (T *) this->buffer_;
02445 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02446   T *tmp = ACE_reinterpret_cast (T *,
02447                                  this->buffer_);
02448 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02449 
02450   TAO_Bounded_Array_Sequence<T, T_var, MAX>::freebuf (tmp);
02451 
02452   this->buffer_ = 0;
02453 }

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

Allocate storage for a sequence..

Definition at line 2333 of file Sequence_T.cpp.

References ACE_NEW_RETURN.

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

02334 {
02335   T *buf = 0;
02336   ACE_NEW_RETURN (buf,
02337                   T[MAX],
02338                   0);
02339 
02340   return buf;
02341 }

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

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

Definition at line 899 of file Sequence_T.i.

Referenced by _deallocate_buffer, and replace.

00900 {
00901   if (buffer == 0)
00902     return;
00903 
00904   delete [] buffer;
00905 }

template<class T, class T_var, size_t MAX>
ACE_INLINE const T * TAO_Bounded_Array_Sequence< T, T_var, MAX >::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 985 of file Sequence_T.i.

00986 {
00987   return ACE_reinterpret_cast (const T * ACE_CAST_CONST, 
00988                                this->buffer_);
00989 }

template<class T, class T_var, size_t MAX>
ACE_INLINE T * TAO_Bounded_Array_Sequence< T, T_var, MAX >::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 948 of file Sequence_T.i.

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

00949 {
00950   T *result = 0;
00951   if (orphan == 0)
00952     {
00953       // We retain ownership.
00954 
00955       if (this->buffer_ == 0)
00956         {
00957           result = 
00958             TAO_Bounded_Array_Sequence<T, T_var, MAX>::allocbuf (this->maximum_);
00959           this->buffer_ = result;
00960           this->release_ = 1;
00961         }
00962       else
00963         {
00964           result =
00965             ACE_reinterpret_cast (T*, this->buffer_);
00966         }
00967     }
00968   else // if (orphan == 1)
00969     {
00970       if (this->release_ != 0)
00971         {
00972           // We set the state back to default and relinquish
00973           // ownership.
00974           result = ACE_reinterpret_cast(T*,this->buffer_);
00975           this->maximum_ = 0;
00976           this->length_ = 0;
00977           this->buffer_ = 0;
00978           this->release_ = 0;
00979         }
00980     }
00981   return result;
00982 }

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

Assignment from another Bounded sequence.

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

02384 {
02385   if (this == &rhs)
02386     {
02387       return *this;
02388     }
02389 
02390   if (this->release_)
02391     {
02392       // We never need to reallocate the buffer because they are
02393       // always of size MAX.
02394     }
02395   else
02396     {
02397       if (rhs.maximum_ == 0)
02398         {
02399           this->buffer_ = 0;
02400         }
02401       else
02402         {
02403           this->buffer_ =
02404             TAO_Bounded_Array_Sequence<T,T_var,MAX>::allocbuf (rhs.maximum_);
02405         }
02406     }
02407 
02408   TAO_Bounded_Base_Sequence::operator= (rhs);
02409 
02410   for (CORBA::ULong i = 0; i < rhs.length_; ++i)
02411     {
02412 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
02413       T_var::copy (((T *) this->buffer_)[i],
02414                    ((const T *) rhs.buffer_)[i]);
02415 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02416       T_var::copy (ACE_reinterpret_cast (T *,
02417                                          this->buffer_)[i],
02418                    ACE_reinterpret_cast (const T *,
02419                                          rhs.buffer_)[i]);
02420 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
02421     }
02422 
02423   return *this;
02424 }

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

operator[].

Definition at line 936 of file Sequence_T.i.

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

00937 {
00938   ACE_ASSERT (i < this->maximum_);
00939 
00940 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
00941   return ((const T* ACE_CAST_CONST) this->buffer_)[i];
00942 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00943   return (ACE_reinterpret_cast (const T* ACE_CAST_CONST, this->buffer_))[i];
00944 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00945 }

template<class T, class T_var, size_t MAX>
ACE_INLINE T & TAO_Bounded_Array_Sequence< T, T_var, MAX >::operator[] CORBA::ULong   
 

operator[].

Definition at line 924 of file Sequence_T.i.

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

00925 {
00926   ACE_ASSERT (i < this->maximum_);
00927 
00928 #if defined (__SUNPRO_CC) && (__SUNPRO_CC < 0x500)
00929   return ((T*) this->buffer_)[i];
00930 #else /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00931   return (ACE_reinterpret_cast (T*, this->buffer_))[i];
00932 #endif /* (__SUNPRO_CC) && (__SUNPRO_CC < 0x500) */
00933 }

template<class T, class T_var, size_t MAX>
ACE_INLINE void TAO_Bounded_Array_Sequence< T, T_var, MAX >::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 992 of file Sequence_T.i.

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

00996 {
00997   this->maximum_ = max;
00998   this->length_ = length;
00999   if (this->buffer_ && this->release_ == 1)
01000     {
01001       T* tmp = ACE_reinterpret_cast (T*, 
01002                                      this->buffer_);
01003       TAO_Bounded_Array_Sequence<T, T_var, MAX>::freebuf (tmp);
01004     }
01005   this->buffer_ = data;
01006   this->release_ = release;
01007 }


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