OpenDDS  Snapshot(2023/04/28-20:55)
SendStateDataSampleList.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
10 #include "DataSampleElement.h"
11 #include "Definitions.h"
12 #include "PublicationInstance.h"
13 
15 
16 #if !defined (__ACE_INLINE__)
18 #endif /* __ACE_INLINE__ */
19 
21 
22 namespace OpenDDS {
23 namespace DCPS {
24 
25 
26 const SendStateDataSampleList*
30 {
31  const DataSampleElement* head = element;
32 
33  while (head->previous_send_sample_ != 0) {
34  head = head->previous_send_sample_;
35  }
36 
37  for (SendStateDataSampleList** it = begin; it != end; ++it) {
38  if ((*it)->head_ == head) {
39  return *it;
40  }
41  }
42  return 0;
43 }
44 
45 
46 bool
48 {
49  if (head_ == 0) {
50  return false;
51  }
52 
53  // Same as dequeue from head.
54  if (stale == head_) {
55  DataSampleElement* tmp = head_;
56  return dequeue_head(tmp);
57  }
58 
59  // Search from head_->next_send_sample_.
60  DataSampleElement* toRemove = 0;
62  item != 0 && toRemove == 0;
63  item = item->next_send_sample_) {
64  if (item == stale) {
65  toRemove = item;
66  }
67  }
68 
69  if (toRemove) {
70  --size_;
71  // Remove from the previous element.
73 
74  // Remove from the next element.
75  if (toRemove->next_send_sample_ != 0) {
76  // Remove from the inside of the list.
78 
79  } else {
80  // Remove from the tail of the list.
81  tail_ = toRemove->previous_send_sample_;
82  }
83 
84  toRemove->next_send_sample_ = 0;
85  toRemove->previous_send_sample_ = 0;
86  }
87 
88  return toRemove != 0;
89 }
90 
91 void
93 {
94  if (head_ == 0) {
95  head_ = list.head_;
96  tail_ = list.tail_;
97  size_ = list.size_;
98 
99  } else {
100  tail_->next_send_sample_ = list.head_;
102  tail_ = list.tail_;
103  size_ = size_ + list.size_;
104  }
105 }
106 
107 // -----------------------------------------------
108 
112  DataSampleElement* current)
113  : head_(head)
114  , tail_(tail)
115  , current_(current)
116 {
117 }
118 
121 {
122  if (this->current_) {
123  this->current_ = this->current_->next_send_sample_;
124  }
125 
126  return *this;
127 }
128 
131 {
133  ++(*this);
134  return tmp;
135 }
136 
139 {
140  if (this->current_) {
141  this->current_ = this->current_->previous_send_sample_;
142  } else {
143  this->current_ = this->tail_;
144  }
145 
146  return *this;
147 }
148 
151 {
153  --(*this);
154  return tmp;
155 }
156 
159 {
160  // Hopefully folks will be smart enough to not dereference a
161  // null iterator. Such a case should only exist for an "end"
162  // iterator. Otherwise we may want to throw an exception here.
163  // assert (this->current_ != 0);
164 
165  return *(this->current_);
166 }
167 
170 {
171  return this->current_;
172 }
173 
175  const DataSampleElement* head,
176  const DataSampleElement* tail,
177  const DataSampleElement* current)
178  : head_(head)
179  , tail_(tail)
180  , current_(current)
181 {
182 }
183 
185  const SendStateDataSampleListIterator& iterator)
186  : head_(iterator.head_)
187  , tail_(iterator.tail_)
188  , current_(iterator.current_)
189 {
190 }
191 
194 {
195  if (this->current_) {
196  this->current_ = this->current_->next_send_sample_;
197  }
198 
199  return *this;
200 }
201 
204 {
206  ++(*this);
207  return tmp;
208 }
209 
212 {
213  if (this->current_) {
214  this->current_ = this->current_->previous_send_sample_;
215  } else {
216  this->current_ = this->tail_;
217  }
218 
219  return *this;
220 }
221 
224 {
226  --(*this);
227  return tmp;
228 }
229 
232 {
233  // Hopefully folks will be smart enough to not dereference a
234  // null iterator. Such a case should only exist for an "end"
235  // iterator. Otherwise we may want to throw an exception here.
236  // assert (this->current_ != 0);
237 
238  return *(this->current_);
239 }
240 
243 {
244  return this->current_;
245 }
246 
247 } // namespace DCPS
248 } // namespace OpenDDS
249 
iterator end()
Return iterator to end of list.
SendStateDataSampleListIterator()
Default constructor required by ForwardIterator concept.
static const SendStateDataSampleList * send_list_containing_element(const DataSampleElement *element, SendStateDataSampleList **begin, SendStateDataSampleList **end)
SendStateDataSampleList STL-style const iterator implementation.
SendStateDataSampleListConstIterator & operator++()
SendStateDataSampleListConstIterator & operator--()
void enqueue_tail(const DataSampleElement *element)
bool dequeue_head(DataSampleElement *&stale)
ssize_t size_
Number of elements in the list.
DataSampleElement * next_send_sample_
Thread of data being unsent/sending/sent/released.
bool dequeue(const DataSampleElement *stale)
DataSampleElement * head_
The first element of the list.
DataSampleElement * previous_send_sample_
DataSampleElement * tail_
The last element of the list.
SendStateDataSampleList STL-style iterator implementation.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
SendStateDataSampleListConstIterator()
Default constructor required by ForwardIterator concept.