TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX > Class Template Reference

#include <ZeroCopySeq_T.h>

Collaboration diagram for TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef Sample_T value_type

Public Member Functions

 ZeroCopyDataSeq (CORBA::ULong maximum=0, CORBA::ULong init_size=DEF_MAX, ACE_Allocator *alloc=0)
 ZeroCopyDataSeq (CORBA::ULong maximum, CORBA::ULong length, Sample_T *buffer, CORBA::Boolean release=false)
 ZeroCopyDataSeq (const ZeroCopyDataSeq &frm)
ZeroCopyDataSeqoperator= (const ZeroCopyDataSeq &frm)
void swap (ZeroCopyDataSeq &frm)
 ~ZeroCopyDataSeq ()
CORBA::ULong maximum () const
void length (CORBA::ULong length)
CORBA::ULong length () const
const Sample_T & operator[] (CORBA::ULong i) const
Sample_T & operator[] (CORBA::ULong i)
CORBA::Boolean release () const
void replace (CORBA::ULong max, CORBA::ULong length, Sample_T *buffer, CORBA::Boolean release=false)
Sample_T * get_buffer (CORBA::Boolean orphan=false)
const Sample_T * get_buffer () const
void increment_references (void)

Static Public Member Functions

static Sample_T * allocbuf (CORBA::ULong nelems)
static void freebuf (Sample_T *buffer)

Private Types

typedef ZeroCopyVector Ptr_Seq_Type

Private Member Functions

CORBA::ULong max_slots () const
void internal_set_length (CORBA::ULong len)
void set_loaner (OpenDDS::DCPS::DataReaderImpl *loaner)
void assign_ptr (CORBA::ULong ii, OpenDDS::DCPS::ReceivedDataElement *item)
OpenDDS::DCPS::ReceivedDataElementget_ptr (CORBA::ULong ii) const
void assign_sample (CORBA::ULong ii, const Sample_T &sample)
bool is_zero_copy () const
void make_single_copy (CORBA::ULong maximum)

Private Attributes

OpenDDS::DCPS::DataReaderImplloaner_
 The datareader that loaned its samples.
OpenDDS::DCPS::FirstTimeFastAllocator<
OpenDDS::DCPS::ReceivedDataElement *,
DEF_MAX > 
default_allocator_
 the default allocator
Ptr_Seq_Type ptrs_
 array of pointers if the sequence is supporting zero-copy reads
CORBA::ULong sc_maximum_
CORBA::ULong sc_length_
Sample_T * sc_buffer_
CORBA::Boolean sc_release_

Static Private Attributes

static Sample_T default_

Friends

class PrivateMemberAccess

Classes

class  PrivateMemberAccess
 Only used by the FooDataReaderImpl and tests. More...
class  ZeroCopyVector

Detailed Description

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
class TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >

Provides [] operators returning sample references but it is implemented as an "array" of pointers to the samples so they can be "loaned" to the application code.

Design Goals:

Definition at line 50 of file ZeroCopySeq_T.h.


Member Typedef Documentation

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
typedef ZeroCopyVector TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::Ptr_Seq_Type [private]

Definition at line 193 of file ZeroCopySeq_T.h.

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
typedef Sample_T TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::value_type

Definition at line 53 of file ZeroCopySeq_T.h.


Constructor & Destructor Documentation

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyDataSeq ( CORBA::ULong  maximum = 0,
CORBA::ULong  init_size = DEF_MAX,
ACE_Allocator alloc = 0 
) [explicit]

Construct a sequence of sample data values that supports zero-copy reads.

Parameters:
maximum Maximum number of samples to insert into the sequence. If == 0 then use zero-copy reading. Defaults to zero hence supporting zero-copy reads/takes.
init_size Initial size of the underlying array of pointers.
alloc The allocator used to allocate the array of pointers to samples. If zero then use the default allocator.
This constructor also serves as the "maximum" ctor and default ctor in the CORBA spec.

Definition at line 44 of file ZeroCopySeq_T.inl.

00048   : loaner_(0)
00049   , ptrs_((maximum == 0) ? init_size : 0
00050             , alloc ? alloc : &default_allocator_)
00051   , sc_maximum_(maximum)
00052   , sc_length_(0)
00053   , sc_buffer_(sc_maximum_ ? allocbuf(sc_maximum_) : 0)
00054   , sc_release_(sc_maximum_)
00055 {
00056 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyDataSeq ( CORBA::ULong  maximum,
CORBA::ULong  length,
Sample_T *  buffer,
CORBA::Boolean  release = false 
)

Definition at line 59 of file ZeroCopySeq_T.inl.

00064   : loaner_(0)
00065   , ptrs_(0)
00066   , sc_maximum_(maximum)
00067   , sc_length_(length)
00068   , sc_buffer_(buffer)
00069   , sc_release_(release)
00070 {
00071 }

template<class Sample_T, size_t DEF_MAX>
TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyDataSeq ( const ZeroCopyDataSeq< Sample_T, DEF_MAX > &  frm  ) 

Definition at line 30 of file ZeroCopySeq_T.cpp.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_length_.

00032   : loaner_(frm.loaner_)
00033   , ptrs_(frm.ptrs_.size(),
00034             (frm.ptrs_.allocator_ ==
00035              static_cast<const ACE_Allocator*>(&frm.default_allocator_))
00036             ? &default_allocator_
00037             : const_cast<ACE_Allocator*>(frm.ptrs_.allocator_))
00038     //The constructor of ptrs_ requires a non-const ptr to ACE_Alloc.
00039   , sc_maximum_(frm.sc_maximum_)
00040   , sc_length_(0) //initialized below
00041   , sc_buffer_(frm.sc_maximum_ ? allocbuf(frm.sc_maximum_) : 0)
00042   , sc_release_(frm.sc_maximum_)
00043 {
00044   if (frm.is_zero_copy()) {
00045     ptrs_ = frm.ptrs_;
00046 
00047     //ptrs_ doesn't manage the ref count for its elements
00048     for (size_t ii = 0; ii < frm.ptrs_.size(); ++ii) {
00049       ptrs_[ii]->inc_ref();
00050       ++ptrs_[ii]->zero_copy_cnt_;
00051     }
00052 
00053   } else {
00054     for (CORBA::ULong i = 0; i < frm.sc_length_; ++i) {
00055       sc_buffer_[i] = frm.sc_buffer_[i];
00056       ++sc_length_;
00057     }
00058   }
00059 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::~ZeroCopyDataSeq (  ) 

Definition at line 113 of file ZeroCopySeq_T.inl.

References OpenDDS::DCPS::DataReaderImpl::auto_return_loan(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::freebuf(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::loaner_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_release_.

00114 {
00115   if (loaner_) loaner_->auto_return_loan(this);
00116 
00117   if (sc_release_ && sc_buffer_) freebuf(sc_buffer_);
00118 }


Member Function Documentation

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE Sample_T * TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::allocbuf ( CORBA::ULong  nelems  )  [static]

Definition at line 234 of file ZeroCopySeq_T.inl.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer().

00235 {
00236   return new Sample_T[nelems];
00237 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::assign_ptr ( CORBA::ULong  ii,
OpenDDS::DCPS::ReceivedDataElement item 
) [private]

Definition at line 272 of file ZeroCopySeq_T.inl.

References OpenDDS::DCPS::ReceivedDataElement::inc_ref(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, and OpenDDS::DCPS::ReceivedDataElement::zero_copy_cnt_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::PrivateMemberAccess::assign_ptr().

00275 {
00276   ACE_ASSERT(is_zero_copy());
00277   item->inc_ref();
00278   ++item->zero_copy_cnt_;
00279   ptrs_[ii] = item;
00280 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::assign_sample ( CORBA::ULong  ii,
const Sample_T &  sample 
) [private]

Definition at line 292 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::PrivateMemberAccess::assign_sample().

00294 {
00295   ACE_ASSERT(!is_zero_copy());
00296   sc_buffer_[ii] = sample;
00297 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::freebuf ( Sample_T *  buffer  )  [static]

Definition at line 242 of file ZeroCopySeq_T.inl.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::~ZeroCopyDataSeq().

00243 {
00244   delete[] buffer;
00245 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE const Sample_T * TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer (  )  const

Definition at line 215 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::allocbuf(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::make_single_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::max_slots(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_release_.

00216 {
00217   //If we're currently zero-copy we must become single copy in order to return
00218   //a contiguous buffer.  The only way to do this and meet the CORBA/C++ spec
00219   //interface is to cast-away the constness.
00220   if (is_zero_copy())
00221     const_cast<ZeroCopyDataSeq*>(this)->make_single_copy(max_slots());
00222 
00223   if (!sc_buffer_) {
00224     sc_buffer_ = allocbuf(sc_maximum_);
00225     sc_release_ = true;
00226   }
00227 
00228   return sc_buffer_;
00229 }

template<class Sample_T, size_t DEF_MAX>
Sample_T * TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer ( CORBA::Boolean  orphan = false  ) 

Definition at line 126 of file ZeroCopySeq_T.cpp.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::allocbuf(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::make_single_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::max_slots(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_release_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

00128 {
00129   //Case 1: I can't give away what's not mine
00130   //  (includes zero-copy since sc_release_ is always false for zero-copy
00131   if (orphan && !sc_release_) return 0;
00132 
00133   // (preparation for cases 2-3)
00134   if (is_zero_copy()) make_single_copy(max_slots());
00135 
00136   if (!sc_buffer_) {
00137     sc_buffer_ = allocbuf(sc_maximum_);
00138 
00139     if (!orphan) sc_release_ = true;
00140   }
00141 
00142   //Case 2: Keeping the buffer but letting client use it too
00143   if (!orphan) return sc_buffer_;
00144 
00145   //Case 3: Orphaning the buffer to the client, leaves "this" in the
00146   //  default-constructed state (which in our case is ZC-enabled)
00147   ZeroCopyDataSeq<Sample_T, DEF_MAX> yours;
00148   swap(yours);
00149   yours.sc_release_ = false; //don't freebuf in dtor
00150   return yours.sc_buffer_;
00151 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE OpenDDS::DCPS::ReceivedDataElement * TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_ptr ( CORBA::ULong  ii  )  const [private]

Definition at line 284 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::PrivateMemberAccess::get_ptr().

00285 {
00286   ACE_ASSERT(is_zero_copy());
00287   return ptrs_[ii];
00288 }

template<class Sample_T, size_t DEF_MAX>
void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::increment_references ( void   ) 

Definition at line 159 of file ZeroCopySeq_T.cpp.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_.

00159                                                             {
00160   if (is_zero_copy()) {
00161     for (size_t ii = 0; ii < ptrs_.size(); ++ii) {
00162       ptrs_[ii]->inc_ref();
00163     }
00164   }
00165 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::internal_set_length ( CORBA::ULong  len  )  [private]

Definition at line 249 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::PrivateMemberAccess::internal_set_length().

00250 {
00251   if (!is_zero_copy() || len < ptrs_.size()) {
00252     length(len);
00253 
00254   } else if (len > ptrs_.size()) {
00255     //We need the vector to grow efficiently (not reallocate on each call)...
00256     ptrs_.resize((std::max)(len, CORBA::ULong(ptrs_.size()) * 2), 0);
00257     //...but maintain the invariant that the size of ptrs_ is our length
00258     ptrs_.resize(len, 0);
00259   }
00260 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE bool TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy (  )  const [private]

Definition at line 122 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::assign_ptr(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::assign_sample(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_ptr(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::increment_references(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::internal_set_length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::max_slots(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator[](), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyDataSeq().

00123 {
00124   return sc_maximum_ == 0;
00125 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE CORBA::ULong TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length (  )  const

Definition at line 144 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_length_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::internal_set_length(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length().

00145 {
00146   return is_zero_copy() ? static_cast<CORBA::ULong>(ptrs_.size()) : sc_length_;
00147 }

template<class Sample_T, size_t DEF_MAX>
void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length ( CORBA::ULong  length  ) 

Performance note: increasing the length of a zero-copy sequence past its current length may cause a copy (the sequence will no longer be zero-copy enabled).

Definition at line 66 of file ZeroCopySeq_T.cpp.

References OpenDDS::DCPS::DataReaderImpl::dec_ref_data_element(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::loaner_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::make_single_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_length_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::set_loaner(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::make_single_copy().

00067 {
00068   using std::fill;
00069   using std::max;
00070   using std::copy;
00071 
00072   if (length == this->length()) {
00073     return;
00074   }
00075 
00076   if (is_zero_copy()) {
00077     if (length < ptrs_.size()) {
00078       if (!loaner_) {
00079         make_single_copy(length);
00080         this->length(length);
00081         return;
00082       }
00083 
00084       for (size_t i(length); i < ptrs_.size(); ++i) {
00085         --ptrs_[i]->zero_copy_cnt_;
00086         loaner_->dec_ref_data_element(ptrs_[i]);
00087       }
00088 
00089       ptrs_.resize(length, 0);
00090       // At this point, there is no longer a loan
00091       this->set_loaner(0);
00092 
00093     } else {
00094       //There's no way we can expand the size (logical) of the zero-copy
00095       //array and have the user do any meaningful operations on the new
00096       //elements.  The fact that they're pointers to ReceivedDataElement
00097       //is hidden from the user.  Thus we need to make the sequence
00098       //single-copy at this point.
00099       make_single_copy(length);
00100       sc_length_ = length;
00101     }
00102 
00103   } else {
00104     if (length < sc_length_) { //shrink
00105       sc_length_ = length;
00106 
00107     } else if (length <= sc_maximum_) { //grow within buffer
00108       fill(&sc_buffer_[sc_length_], &sc_buffer_[length], Sample_T());
00109       sc_length_ = length;
00110 
00111     } else { //grow to larger buffer
00112       ZeroCopyDataSeq<Sample_T, DEF_MAX> grow(max(length, sc_maximum_*2));
00113       copy(sc_buffer_, &sc_buffer_[sc_length_], grow.sc_buffer_);
00114       fill(&grow.sc_buffer_[sc_length_], &grow.sc_buffer_[length],
00115            Sample_T());
00116       swap(grow);
00117     }
00118   }
00119 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::make_single_copy ( CORBA::ULong  maximum  )  [private]

Definition at line 200 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length().

00201 {
00202   CORBA::ULong currentSize(static_cast<CORBA::ULong>(ptrs_.size()));
00203   ZeroCopyDataSeq<Sample_T, DEF_MAX> sc((std::max)(maximum, currentSize));
00204   sc.length(currentSize);
00205 
00206   for (CORBA::ULong i(0); i < ptrs_.size(); ++i) {
00207     sc[i] = (*this)[i];
00208   }
00209 
00210   swap(sc);
00211 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE CORBA::ULong TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::max_slots (  )  const [private]

Current allocated number of sample slots.

Note:
The DDS specification's use of maximum=0 to designate zero-copy read request requires some way of knowing the internally allocated slots for sample pointers that is not "maximum".

Definition at line 136 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::PrivateMemberAccess::max_slots().

00137 {
00138   return is_zero_copy() ? static_cast<CORBA::ULong>(ptrs_.max_size())
00139     : sc_maximum_;
00140 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE CORBA::ULong TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::maximum (  )  const

Definition at line 129 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_.

00130 {
00131   return sc_maximum_;
00132 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE ZeroCopyDataSeq< Sample_T, DEF_MAX > & TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator= ( const ZeroCopyDataSeq< Sample_T, DEF_MAX > &  frm  ) 

Definition at line 75 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

00077 {
00078   if (this != &frm) {
00079     ZeroCopyDataSeq<Sample_T, DEF_MAX> temp(frm);
00080     swap(temp);
00081   }
00082 
00083   return *this;
00084 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE Sample_T & TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator[] ( CORBA::ULong  i  ) 

Definition at line 166 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::default_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_.

00167 {
00168   if (is_zero_copy()) {
00169     if (ptrs_[i]->registered_data_) {
00170       return *static_cast<Sample_T*>(ptrs_[i]->registered_data_);
00171     }
00172     return default_;
00173 
00174   } else {
00175     return sc_buffer_[i];
00176   }
00177 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE const Sample_T & TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator[] ( CORBA::ULong  i  )  const

Definition at line 151 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::default_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_.

00152 {
00153   if (is_zero_copy()) {
00154     if (ptrs_[i]->registered_data_) {
00155       return *static_cast<const Sample_T*>(ptrs_[i]->registered_data_);
00156     }
00157     return default_;
00158 
00159   } else {
00160     return sc_buffer_[i];
00161   }
00162 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE CORBA::Boolean TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::release (  )  const

Definition at line 181 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_release_.

00182 {
00183   return sc_release_; //will always be false in zero-copy mode
00184 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::replace ( CORBA::ULong  max,
CORBA::ULong  length,
Sample_T *  buffer,
CORBA::Boolean  release = false 
)

Definition at line 188 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

00193 {
00194   ZeroCopyDataSeq<Sample_T, DEF_MAX> newOne(maximum, length, buffer, release);
00195   swap(newOne);
00196 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::set_loaner ( OpenDDS::DCPS::DataReaderImpl loaner  )  [private]

Definition at line 264 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::loaner_.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::PrivateMemberAccess::set_loaner().

00266 {
00267   loaner_ = loaner;
00268 }

template<class Sample_T, size_t DEF_MAX>
ACE_INLINE void TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap ( ZeroCopyDataSeq< Sample_T, DEF_MAX > &  frm  ) 

Definition at line 88 of file ZeroCopySeq_T.inl.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::default_allocator_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::loaner_, OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::pool(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_length_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_release_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyVector::swap(), and OpenDDS::DCPS::swap().

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::make_single_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator=(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::replace().

00089 {
00090   bool thisUsedDefAlloc = ptrs_.allocator_ == &default_allocator_;
00091   bool thisUsedLocalBuffer = ptrs_.array_ == default_allocator_.pool();
00092   bool frmUsedDefAlloc = frm.ptrs_.allocator_ == &frm.default_allocator_;
00093   bool frmUsedLocalBuffer = frm.ptrs_.array_ == frm.default_allocator_.pool();
00094 
00095   std::swap(loaner_, frm.loaner_);
00096   std::swap(default_allocator_, frm.default_allocator_);
00097   ptrs_.swap(frm.ptrs_);
00098   std::swap(sc_maximum_, frm.sc_maximum_);
00099   std::swap(sc_length_, frm.sc_length_);
00100   std::swap(sc_buffer_, frm.sc_buffer_);
00101   std::swap(sc_release_, frm.sc_release_);
00102 
00103   if (thisUsedDefAlloc) frm.ptrs_.allocator_ = &frm.default_allocator_;
00104 
00105   if (thisUsedLocalBuffer) frm.ptrs_.array_ = frm.default_allocator_.pool();
00106 
00107   if (frmUsedDefAlloc) ptrs_.allocator_ = &default_allocator_;
00108 
00109   if (frmUsedLocalBuffer) ptrs_.array_ = default_allocator_.pool();
00110 }


Friends And Related Function Documentation

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
friend class PrivateMemberAccess [friend]

Definition at line 143 of file ZeroCopySeq_T.h.


Member Data Documentation

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
Sample_T TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::default_ [static, private]

Definition at line 197 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator[]().

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
OpenDDS::DCPS::FirstTimeFastAllocator<OpenDDS::DCPS::ReceivedDataElement*, DEF_MAX> TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::default_allocator_ [private]

the default allocator

Definition at line 191 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
OpenDDS::DCPS::DataReaderImpl* TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::loaner_ [private]

The datareader that loaned its samples.

Definition at line 187 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::set_loaner(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::~ZeroCopyDataSeq().

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
Ptr_Seq_Type TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_ [private]

array of pointers if the sequence is supporting zero-copy reads

Definition at line 196 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::assign_ptr(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_ptr(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::increment_references(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::internal_set_length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::make_single_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::max_slots(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator[](), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyDataSeq().

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
Sample_T* TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_buffer_ [mutable, private]

Definition at line 202 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::assign_sample(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::operator[](), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyDataSeq(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::~ZeroCopyDataSeq().

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
CORBA::ULong TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_length_ [private]

Definition at line 201 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyDataSeq().

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
CORBA::ULong TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_maximum_ [private]

Definition at line 200 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::max_slots(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::maximum(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

template<class Sample_T, size_t DEF_MAX = DCPS_ZERO_COPY_SEQ_DEFAULT_SIZE>
CORBA::Boolean TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_release_ [mutable, private]

Definition at line 203 of file ZeroCopySeq_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::get_buffer(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::release(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::~ZeroCopyDataSeq().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:51 2016 for OpenDDS by  doxygen 1.4.7