OpenDDS  Snapshot(2023/04/28-20:55)
SendStateDataSampleList.inl
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 "DataSampleElement.h"
9 
10 #include <algorithm>
11 
13 
14 namespace OpenDDS {
15 namespace DCPS {
16 
19  : head_(0),
20  tail_(0),
21  size_(0)
22 {
23 }
24 
27 {
28  head_ = tail_ = 0;
29  size_ = 0;
30 }
31 
33 ssize_t
35 {
36  return size_;
37 }
38 
42 {
43  return head_;
44 }
45 
49 {
50  return tail_;
51 }
52 
54 void
56 {
57  ++size_;
58 
59  // const_cast here so that higher layers don't need to pass around so many
60  // non-const pointers to DataSampleElement. Ideally the design would be
61  // changed to accommodate const-correctness throughout.
62  DataSampleElement* mSample = const_cast<DataSampleElement*>(sample);
63 
64  if (head_ == 0) {
65  head_ = tail_ = mSample;
66  sample->next_send_sample_ = sample->previous_send_sample_ = 0;
67 
68  } else {
69  sample->next_send_sample_ = head_;
70  sample->previous_send_sample_ = 0;
71  head_->previous_send_sample_ = mSample;
72  head_ = mSample;
73  }
74 }
75 
77 void
79 {
80  ++size_;
81 
82  // const_cast here so that higher layers don't need to pass around so many
83  // non-const pointers to DataSampleElement. Ideally the design would be
84  // changed to accommodate const-correctness throughout.
85  DataSampleElement* mSample = const_cast<DataSampleElement*>(sample);
86 
87  if (head_ == 0) {
88  head_ = tail_ = mSample;
89  sample->next_send_sample_ = sample->previous_send_sample_ = 0;
90 
91  } else {
92  sample->previous_send_sample_ = tail_;
93  sample->next_send_sample_ = 0;
94  tail_->next_send_sample_ = mSample;
95  tail_ = mSample;
96  }
97 }
98 
100 bool
102 {
103  //
104  // Remove the oldest sample from the instance list.
105  //
106  stale = head_;
107 
108  if (head_ == 0) {
109  return false;
110 
111  } else {
112  --size_;
113 
115 
116  if (head_ == 0) {
117  tail_ = 0;
118 
119  } else {
121  }
122 
123  stale->next_send_sample_ = 0;
124  stale->previous_send_sample_ = 0;
125 
126  return true;
127  }
128 }
129 
131 void
133 {
134  if (stale->previous_send_sample_) {
136  }
137  if (stale->next_send_sample_) {
139  }
140 }
141 
145 {
146  return iterator(this->head_, this->tail_, this->head_);
147 }
148 
152 {
153  return iterator(this->head_, this->tail_, 0);
154 }
155 
159 {
160  return const_iterator(this->head_, this->tail_, this->head_);
161 }
162 
166 {
167  return const_iterator(this->head_, this->tail_, 0);
168 }
169 
173 {
174  return reverse_iterator(end());
175 }
176 
180 {
181  return reverse_iterator(begin());
182 }
183 
187 {
188  return const_reverse_iterator(end());
189 }
190 
194 {
195  return const_reverse_iterator(begin());
196 }
197 
198 } // namespace DCPS
199 } // namespace OpenDDS
200 
SendStateDataSampleList()
Default constructor clears the list.
SendStateDataSampleListIterator iterator
STL-style bidirectional iterator and const-iterator types.
iterator end()
Return iterator to end of list.
std::reverse_iterator< iterator > reverse_iterator
SendStateDataSampleList STL-style const iterator implementation.
ACE_Message_Block & head_
int ssize_t
SendStateDataSampleListConstIterator const_iterator
void enqueue_tail(const DataSampleElement *element)
bool dequeue_head(DataSampleElement *&stale)
ssize_t size_
Number of elements in the list.
iterator begin()
Return iterator to beginning of list.
DataSampleElement * next_send_sample_
Thread of data being unsent/sending/sent/released.
size_t size_
DataSampleElement * head_
The first element of the list.
static void remove(DataSampleElement *stale)
DataSampleElement * previous_send_sample_
void enqueue_head(const DataSampleElement *element)
DataSampleElement * tail_
The last element of the list.
SendStateDataSampleList STL-style iterator implementation.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
#define ACE_INLINE
std::reverse_iterator< const_iterator > const_reverse_iterator
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28