OpenDDS  Snapshot(2023/04/28-20:55)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
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]

Classes

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

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 ()
 

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 loaner that loaned its samples. More...
 
OpenDDS::DCPS::FirstTimeFastAllocator< OpenDDS::DCPS::ReceivedDataElement *, DEF_MAX > default_allocator_
 the default allocator More...
 
Ptr_Seq_Type ptrs_
 array of pointers if the sequence is supporting zero-copy reads More...
 
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
 

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 53 of file ZeroCopySeq_T.h.

Member Typedef Documentation

◆ Ptr_Seq_Type

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 202 of file ZeroCopySeq_T.h.

◆ value_type

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 56 of file ZeroCopySeq_T.h.

Constructor & Destructor Documentation

◆ ZeroCopyDataSeq() [1/3]

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
maximumMaximum 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_sizeInitial size of the underlying array of pointers.
allocThe 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.

References ACE_INLINE.

48  : loaner_(0)
49  , ptrs_((maximum == 0) ? init_size : 0
50  , alloc ? alloc : &default_allocator_)
52  , sc_length_(0)
55 {
56 }
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
OpenDDS::DCPS::DataReaderImpl * loaner_
The loaner that loaned its samples.
static Sample_T * allocbuf(CORBA::ULong nelems)
CORBA::ULong maximum() const
OpenDDS::DCPS::FirstTimeFastAllocator< OpenDDS::DCPS::ReceivedDataElement *, DEF_MAX > default_allocator_
the default allocator

◆ ZeroCopyDataSeq() [2/3]

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.

References ACE_INLINE.

64  : loaner_(0)
65  , ptrs_(0)
68  , sc_buffer_(buffer)
70 {
71 }
CORBA::ULong length() const
CORBA::Boolean release() const
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
OpenDDS::DCPS::DataReaderImpl * loaner_
The loaner that loaned its samples.
CORBA::ULong maximum() const

◆ ZeroCopyDataSeq() [3/3]

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_, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::sc_length_, and ACE_Vector< T, DEFAULT_SIZE >::size().

32  : loaner_(frm.loaner_)
33  , ptrs_(frm.ptrs_.size(),
34  (frm.ptrs_.allocator_ ==
35  static_cast<const ACE_Allocator*>(&frm.default_allocator_))
37  : const_cast<ACE_Allocator*>(frm.ptrs_.allocator_))
38  //The constructor of ptrs_ requires a non-const ptr to ACE_Alloc.
39  , sc_maximum_(frm.sc_maximum_)
40  , sc_length_(0) //initialized below
41  , sc_buffer_(frm.sc_maximum_ ? allocbuf(frm.sc_maximum_) : 0)
42  , sc_release_(frm.sc_maximum_)
43 {
44  if (frm.is_zero_copy()) {
45  ptrs_ = frm.ptrs_;
46 
47  //ptrs_ doesn't manage the ref count for its elements
48  for (size_t ii = 0; ii < frm.ptrs_.size(); ++ii) {
49  ptrs_[ii]->inc_ref();
50  ++ptrs_[ii]->zero_copy_cnt_;
51  }
52 
53  } else {
54  for (CORBA::ULong i = 0; i < frm.sc_length_; ++i) {
55  sc_buffer_[i] = frm.sc_buffer_[i];
56  ++sc_length_;
57  }
58  }
59 }
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
ACE_CDR::ULong ULong
OpenDDS::DCPS::DataReaderImpl * loaner_
The loaner that loaned its samples.
static Sample_T * allocbuf(CORBA::ULong nelems)
OpenDDS::DCPS::FirstTimeFastAllocator< OpenDDS::DCPS::ReceivedDataElement *, DEF_MAX > default_allocator_
the default allocator

◆ ~ZeroCopyDataSeq()

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

Member Function Documentation

◆ allocbuf()

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 237 of file ZeroCopySeq_T.inl.

References ACE_INLINE.

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

238 {
239  return new Sample_T[nelems];
240 }

◆ assign_ptr()

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 275 of file ZeroCopySeq_T.inl.

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

278 {
280  if (ptrs_[ii]) {
281  --ptrs_[ii]->zero_copy_cnt_;
282  ptrs_[ii]->dec_ref();
283  }
284 
285  item->inc_ref();
286  ++item->zero_copy_cnt_;
287  ptrs_[ii] = item;
288 }
#define OPENDDS_ASSERT(C)
Definition: Definitions.h:72
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads

◆ assign_sample()

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

◆ freebuf()

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 245 of file ZeroCopySeq_T.inl.

References ACE_INLINE.

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

246 {
247  delete[] buffer;
248 }

◆ get_buffer() [1/2]

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 127 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().

129 {
130  //Case 1: I can't give away what's not mine
131  // (includes zero-copy since sc_release_ is always false for zero-copy
132  if (orphan && !sc_release_) return 0;
133 
134  // (preparation for cases 2-3)
136 
137  if (!sc_buffer_) {
139 
140  if (!orphan) sc_release_ = true;
141  }
142 
143  //Case 2: Keeping the buffer but letting client use it too
144  if (!orphan) return sc_buffer_;
145 
146  //Case 3: Orphaning the buffer to the client, leaves "this" in the
147  // default-constructed state (which in our case is ZC-enabled)
148  ZeroCopyDataSeq<Sample_T, DEF_MAX> yours;
149  swap(yours);
150  yours.sc_release_ = false; //don't freebuf in dtor
151  return yours.sc_buffer_;
152 }
CORBA::ULong max_slots() const
void swap(ZeroCopyDataSeq &frm)
void make_single_copy(CORBA::ULong maximum)
static Sample_T * allocbuf(CORBA::ULong nelems)

◆ get_buffer() [2/2]

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 218 of file ZeroCopySeq_T.inl.

References ACE_INLINE, 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_.

219 {
220  //If we're currently zero-copy we must become single copy in order to return
221  //a contiguous buffer. The only way to do this and meet the CORBA/C++ spec
222  //interface is to cast-away the constness.
223  if (is_zero_copy())
224  const_cast<ZeroCopyDataSeq*>(this)->make_single_copy(max_slots());
225 
226  if (!sc_buffer_) {
228  sc_release_ = true;
229  }
230 
231  return sc_buffer_;
232 }
CORBA::ULong max_slots() const
void make_single_copy(CORBA::ULong maximum)
static Sample_T * allocbuf(CORBA::ULong nelems)
ZeroCopyDataSeq(CORBA::ULong maximum=0, CORBA::ULong init_size=DEF_MAX, ACE_Allocator *alloc=0)

◆ get_ptr()

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 292 of file ZeroCopySeq_T.inl.

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

293 {
295  return ptrs_[ii];
296 }
#define OPENDDS_ASSERT(C)
Definition: Definitions.h:72
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads

◆ increment_references()

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

Definition at line 159 of file ZeroCopySeq_T.cpp.

References TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, ACE_Vector< T, DEFAULT_SIZE >::size(), and TAO_END_VERSIONED_NAMESPACE_DECL.

160 {
161  if (is_zero_copy()) {
162  for (size_t ii = 0; ii < ptrs_.size(); ++ii) {
163  ptrs_[ii]->inc_ref();
164  }
165  }
166 }
size_t size(void) const
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads

◆ internal_set_length()

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 252 of file ZeroCopySeq_T.inl.

References ACE_INLINE, 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 >::ptrs_, ACE_Vector< T, DEFAULT_SIZE >::resize(), and ACE_Vector< T, DEFAULT_SIZE >::size().

253 {
254  if (!is_zero_copy() || len < ptrs_.size()) {
255  length(len);
256 
257  } else if (len > ptrs_.size()) {
258  //We need the vector to grow efficiently (not reallocate on each call)...
259  ptrs_.resize((std::max)(len, CORBA::ULong(ptrs_.size()) * 2), 0);
260  //...but maintain the invariant that the size of ptrs_ is our length
261  ptrs_.resize(len, 0);
262  }
263 }
size_t size(void) const
CORBA::ULong length() const
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
ACE_CDR::ULong ULong
void resize(const size_t new_size, const T &t)

◆ is_zero_copy()

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

◆ length() [1/2]

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::XTypes::copy(), OpenDDS::DCPS::grow(), 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_, ACE_Vector< T, DEFAULT_SIZE >::resize(), 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(), ACE_Vector< T, DEFAULT_SIZE >::size(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

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

67 {
68  using std::fill;
69  using std::max;
70  using std::copy;
71 
72  if (length == this->length()) {
73  return;
74  }
75 
76  if (is_zero_copy()) {
77  if (length < ptrs_.size()) {
78  if (!loaner_) {
80  this->length(length);
81  return;
82  }
83 
84  for (size_t i(length); i < ptrs_.size(); ++i) {
85  --ptrs_[i]->zero_copy_cnt_;
86  ptrs_[i]->dec_ref();
87  }
88 
89  ptrs_.resize(length, 0);
90  // At this point, there is no longer a loan
91  this->set_loaner(0);
92 
93  } else {
94  //There's no way we can expand the size (logical) of the zero-copy
95  //array and have the user do any meaningful operations on the new
96  //elements. The fact that they're pointers to ReceivedDataElement
97  //is hidden from the user. Thus we need to make the sequence
98  //single-copy at this point.
100  sc_length_ = length;
101  }
102 
103  } else {
104  if (length < sc_length_) { //shrink
105  sc_length_ = length;
106 
107  } else if (length <= sc_maximum_) { //grow within buffer
108  fill(&sc_buffer_[sc_length_], &sc_buffer_[length], Sample_T());
109  sc_length_ = length;
110 
111  } else { //grow to larger buffer
112  ZeroCopyDataSeq<Sample_T, DEF_MAX> grow(max(length, sc_maximum_*2));
113  grow.sc_length_ = length;
114  copy(sc_buffer_, &sc_buffer_[sc_length_], grow.sc_buffer_);
115  fill(&grow.sc_buffer_[sc_length_], &grow.sc_buffer_[length],
116  Sample_T());
117  swap(grow);
118  }
119  }
120 }
size_t size(void) const
CORBA::ULong length() const
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
void swap(ZeroCopyDataSeq &frm)
OpenDDS::DCPS::DataReaderImpl * loaner_
The loaner that loaned its samples.
void make_single_copy(CORBA::ULong maximum)
Seq::size_type grow(Seq &seq)
Definition: Util.h:151
DDS::ReturnCode_t copy(DDS::DynamicData_ptr dest, DDS::DynamicData_ptr src)
void resize(const size_t new_size, const T &t)
void set_loaner(OpenDDS::DCPS::DataReaderImpl *loaner)

◆ length() [2/2]

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

◆ make_single_copy()

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 203 of file ZeroCopySeq_T.inl.

References ACE_INLINE, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::length(), TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ptrs_, ACE_Vector< T, DEFAULT_SIZE >::size(), 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().

204 {
205  CORBA::ULong currentSize(static_cast<CORBA::ULong>(ptrs_.size()));
206  ZeroCopyDataSeq<Sample_T, DEF_MAX> sc((std::max)(maximum, currentSize));
207  sc.length(currentSize);
208 
209  for (CORBA::ULong i(0); i < ptrs_.size(); ++i) {
210  sc[i] = (*this)[i];
211  }
212 
213  swap(sc);
214 }
size_t size(void) const
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
ACE_CDR::ULong ULong
void swap(ZeroCopyDataSeq &frm)
CORBA::ULong maximum() const

◆ max_slots()

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 139 of file ZeroCopySeq_T.inl.

References ACE_INLINE, TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::is_zero_copy(), ACE_Array_Base< T >::max_size(), 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().

140 {
141  return is_zero_copy() ? static_cast<CORBA::ULong>(ptrs_.max_size())
142  : sc_maximum_;
143 }
size_type max_size(void) const
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
ACE_CDR::ULong ULong

◆ maximum()

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

Definition at line 132 of file ZeroCopySeq_T.inl.

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

133 {
134  return sc_maximum_;
135 }

◆ operator=()

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 ACE_INLINE, and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

77 {
78  if (this != &frm) {
79  ZeroCopyDataSeq<Sample_T, DEF_MAX> temp(frm);
80  swap(temp);
81  }
82 
83  return *this;
84 }
void swap(ZeroCopyDataSeq &frm)

◆ operator[]() [1/2]

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 154 of file ZeroCopySeq_T.inl.

References ACE_INLINE, 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_.

155 {
156  if (is_zero_copy()) {
157  if (ptrs_[i]->registered_data_) {
158  return *static_cast<const Sample_T*>(ptrs_[i]->registered_data_);
159  }
160  return default_;
161 
162  } else {
163  return sc_buffer_[i];
164  }
165 }
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads

◆ operator[]() [2/2]

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 169 of file ZeroCopySeq_T.inl.

References ACE_INLINE, 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_.

170 {
171  if (is_zero_copy()) {
172  if (ptrs_[i]->registered_data_) {
173  return *static_cast<Sample_T*>(ptrs_[i]->registered_data_);
174  }
175  return default_;
176 
177  } else {
178  return sc_buffer_[i];
179  }
180 }
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads

◆ release()

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

Definition at line 184 of file ZeroCopySeq_T.inl.

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

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

185 {
186  return sc_release_; //will always be false in zero-copy mode
187 }

◆ replace()

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 191 of file ZeroCopySeq_T.inl.

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

196 {
197  ZeroCopyDataSeq<Sample_T, DEF_MAX> newOne(maximum, length, buffer, release);
198  swap(newOne);
199 }
CORBA::ULong length() const
CORBA::Boolean release() const
void swap(ZeroCopyDataSeq &frm)
CORBA::ULong maximum() const

◆ set_loaner()

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 267 of file ZeroCopySeq_T.inl.

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

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

269 {
270  loaner_ = loaner;
271 }
OpenDDS::DCPS::DataReaderImpl * loaner_
The loaner that loaned its samples.

◆ swap()

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 ACE_INLINE, ACE_Array_Base< T >::allocator_, ACE_Array_Base< T >::array_, 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_, OpenDDS::DCPS::swap(), and TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::ZeroCopyVector::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().

89 {
90  bool thisUsedDefAlloc = ptrs_.allocator_ == &default_allocator_;
91  bool thisUsedLocalBuffer = ptrs_.array_ == default_allocator_.pool();
92  bool frmUsedDefAlloc = frm.ptrs_.allocator_ == &frm.default_allocator_;
93  bool frmUsedLocalBuffer = frm.ptrs_.array_ == frm.default_allocator_.pool();
94 
95  std::swap(loaner_, frm.loaner_);
96  std::swap(default_allocator_, frm.default_allocator_);
97  ptrs_.swap(frm.ptrs_);
98  std::swap(sc_maximum_, frm.sc_maximum_);
99  std::swap(sc_length_, frm.sc_length_);
100  std::swap(sc_buffer_, frm.sc_buffer_);
101  std::swap(sc_release_, frm.sc_release_);
102 
103  if (thisUsedDefAlloc) frm.ptrs_.allocator_ = &frm.default_allocator_;
104 
105  if (thisUsedLocalBuffer) frm.ptrs_.array_ = frm.default_allocator_.pool();
106 
107  if (frmUsedDefAlloc) ptrs_.allocator_ = &default_allocator_;
108 
109  if (frmUsedLocalBuffer) ptrs_.array_ = default_allocator_.pool();
110 }
void swap(MessageBlock &lhs, MessageBlock &rhs)
Ptr_Seq_Type ptrs_
array of pointers if the sequence is supporting zero-copy reads
OpenDDS::DCPS::DataReaderImpl * loaner_
The loaner that loaned its samples.
ACE_Allocator * allocator_
value_type * array_
OpenDDS::DCPS::FirstTimeFastAllocator< OpenDDS::DCPS::ReceivedDataElement *, DEF_MAX > default_allocator_
the default allocator

Friends And Related Function Documentation

◆ PrivateMemberAccess

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

Definition at line 148 of file ZeroCopySeq_T.h.

Member Data Documentation

◆ default_

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

◆ default_allocator_

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 200 of file ZeroCopySeq_T.h.

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

◆ loaner_

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

◆ ptrs_

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

◆ sc_buffer_

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_
mutableprivate

◆ sc_length_

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

◆ sc_maximum_

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

◆ sc_release_

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_
mutableprivate

The documentation for this class was generated from the following files: