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

TAO_Bounded_Sequence Class Template Reference

Parametric bounded sequence. More...

#include <Sequence_T.h>

Inheritance diagram for TAO_Bounded_Sequence:

Inheritance graph
[legend]
Collaboration diagram for TAO_Bounded_Sequence:

Collaboration graph
[legend]
List of all members.

Public Methods

 TAO_Bounded_Sequence (void)
 Default constructor. More...

 TAO_Bounded_Sequence (CORBA::ULong length, T *data, CORBA::Boolean release=0)
 Constructor using the data and memory management flag. More...

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

TAO_Bounded_Sequence< T, MAX > & operator= (const TAO_Bounded_Sequence< T, MAX > &)
 Assignment operator. More...

 ~TAO_Bounded_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)
 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)
 Allocate storage for the sequence. More...

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


Detailed Description

template<class T, size_t MAX>
class TAO_Bounded_Sequence< T, MAX >

Parametric bounded sequence.

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

Definition at line 145 of file Sequence_T.h.


Constructor & Destructor Documentation

template<class T, size_t MAX>
ACE_INLINE TAO_Bounded_Sequence< T, MAX >::TAO_Bounded_Sequence void   
 

Default constructor.

Definition at line 123 of file Sequence_T.i.

References TAO_Base_Sequence::maximum_.

00124 {
00125   this->maximum_ = MAX;
00126 }

template<class T, size_t MAX>
ACE_INLINE TAO_Bounded_Sequence< T, MAX >::TAO_Bounded_Sequence CORBA::ULong    length,
T *    data,
CORBA::Boolean    release = 0
 

Constructor using the data and memory management flag.

Definition at line 129 of file Sequence_T.i.

00132   : TAO_Bounded_Base_Sequence (MAX, length, data, release)
00133 {
00134 }

template<class T, size_t MAX>
TAO_Bounded_Sequence< T, MAX >::TAO_Bounded_Sequence const TAO_Bounded_Sequence< T, MAX > &   
 

Copy constructor.

Definition at line 164 of file Sequence_T.cpp.

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

00167   : TAO_Bounded_Base_Sequence (rhs)
00168 {
00169   if (rhs.buffer_ != 0)
00170     {
00171       T *tmp1 = TAO_Bounded_Sequence<T, MAX>::allocbuf (MAX);
00172 
00173       T * const tmp2 =
00174         ACE_reinterpret_cast (T * ACE_CAST_CONST, 
00175                               rhs.buffer_);
00176 
00177       for (CORBA::ULong i = 0; i < this->length_; ++i)
00178         {
00179           tmp1[i] = tmp2[i];
00180         }
00181 
00182       this->buffer_ = tmp1;
00183     }
00184   else
00185     {
00186       this->buffer_ = 0;
00187     }
00188 }

template<class T, size_t MAX>
TAO_Bounded_Sequence< T, MAX >::~TAO_Bounded_Sequence void   
 

Dtor.

Definition at line 232 of file Sequence_T.cpp.

References _deallocate_buffer.

00233 {
00234   this->_deallocate_buffer ();
00235 }


Member Function Documentation

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

References allocbuf, and TAO_Base_Sequence::buffer_.

00239 {
00240   // For this class memory is never reallocated so the implementation
00241   // is *really* simple.
00242   this->buffer_ = TAO_Bounded_Sequence<T, MAX>::allocbuf (MAX);
00243 }

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

deallocate the buffer.

Implements TAO_Base_Sequence.

Definition at line 246 of file Sequence_T.cpp.

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

Referenced by ~TAO_Bounded_Sequence.

00247 {
00248   if (this->release_ == 0)
00249     {
00250       return;
00251     }
00252 
00253   T *tmp = ACE_reinterpret_cast (T *,
00254                                  this->buffer_);
00255   TAO_Bounded_Sequence<T, MAX>::freebuf (tmp);
00256   this->buffer_ = 0;
00257 }

template<class T, size_t MAX>
ACE_INLINE T * TAO_Bounded_Sequence< T, MAX >::allocbuf CORBA::ULong    [static]
 

Allocate storage for the sequence.

Definition at line 111 of file Sequence_T.i.

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

00112 {
00113   return new T[MAX];
00114 }

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

Free the sequence.

Definition at line 117 of file Sequence_T.i.

Referenced by _deallocate_buffer, and replace.

00118 {
00119   delete [] buffer;
00120 }

template<class T, size_t MAX>
ACE_INLINE const T * TAO_Bounded_Sequence< T, 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 173 of file Sequence_T.i.

00174 {
00175   return ACE_reinterpret_cast(const T * ACE_CAST_CONST, this->buffer_);
00176 }

template<class T, size_t MAX>
ACE_INLINE T * TAO_Bounded_Sequence< T, 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 size of the returned buffer is equal to the sequence bound, which can be determined with the <maximum> accessor. 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 137 of file Sequence_T.i.

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

00138 {
00139   T *result = 0;
00140   if (orphan == 0)
00141     {
00142       // We retain ownership.
00143 
00144       if (this->buffer_ == 0)
00145         {
00146           result = TAO_Bounded_Sequence<T,MAX>::allocbuf (this->maximum_);
00147           this->buffer_ = result;
00148           this->release_ = 1;
00149         }
00150       else
00151         {
00152           result =
00153             ACE_reinterpret_cast (T*, this->buffer_);
00154         }
00155     }
00156   else // if (orphan == 1)
00157     {
00158       if (this->release_ != 0)
00159         {
00160           // We set the state back to default and relinquish
00161           // ownership.
00162           result = ACE_reinterpret_cast(T*,this->buffer_);
00163           this->maximum_ = 0;
00164           this->length_ = 0;
00165           this->buffer_ = 0;
00166           this->release_ = 0;
00167         }
00168     }
00169   return result;
00170 }

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

Assignment operator.

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

00194 {
00195   if (this == &rhs)
00196     {
00197       return *this;
00198     }
00199 
00200   if (this->release_)
00201     {
00202       // We never need to reallocate the buffer because they are
00203       // always of size MAX.
00204     }
00205   else
00206     {
00207       if (rhs.maximum_ == 0)
00208         {
00209           this->buffer_ = 0;
00210         }
00211       else
00212         {
00213           this->buffer_ =
00214             TAO_Bounded_Sequence<T, MAX>::allocbuf (rhs.maximum_);
00215         }
00216     }
00217 
00218   TAO_Bounded_Base_Sequence::operator= (rhs);
00219 
00220   T* tmp1 = ACE_reinterpret_cast (T *, this->buffer_);
00221   T* const tmp2 = ACE_reinterpret_cast (T * ACE_CAST_CONST, rhs.buffer_);
00222 
00223   for (CORBA::ULong i = 0; i < this->length_; ++i)
00224     {
00225       tmp1[i] = tmp2[i];
00226     }
00227 
00228   return *this;
00229 }

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

operator[].

Definition at line 204 of file Sequence_T.i.

References ACE_ASSERT, and TAO_Base_Sequence::maximum_.

00205 {
00206   ACE_ASSERT (i < this->maximum_);
00207   const T* tmp = ACE_reinterpret_cast (const T* ACE_CAST_CONST,this->buffer_);
00208   return tmp[i];
00209 }

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

operator[].

Definition at line 196 of file Sequence_T.i.

References ACE_ASSERT, and TAO_Base_Sequence::maximum_.

00197 {
00198   ACE_ASSERT (i < this->maximum_);
00199   T *tmp = ACE_reinterpret_cast (T*,this->buffer_);
00200   return tmp[i];
00201 }

template<class T, size_t MAX>
ACE_INLINE void TAO_Bounded_Sequence< T, 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 179 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_.

00183 {
00184   this->maximum_ = max;
00185   this->length_ = length;
00186   if (this->buffer_ && this->release_ == 1)
00187     {
00188       T* tmp = ACE_reinterpret_cast(T*, this->buffer_);
00189       TAO_Bounded_Sequence<T, MAX>::freebuf (tmp);
00190     }
00191   this->buffer_ = data;
00192   this->release_ = release;
00193 }


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