OpenDDS  Snapshot(2023/04/28-20:55)
SendStateDataSampleList.h
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 #ifndef OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H
9 #define OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H
10 
11 #include "PoolAllocator.h"
12 #include "Definitions.h"
14 
16 #include "dds/DdsDcpsInfoUtilsC.h"
17 
18 #include <ace/config-lite.h>
19 
20 #include <iterator>
21 
22 class DDS_TEST;
23 
25 
26 namespace OpenDDS {
27 namespace DCPS {
28 
29 class DataSampleElement;
30 
31 const int MAX_READERS_TO_RESEND = 5;
32 
33 /**
34  * @struct SendStateDataSampleListIterator
35  *
36  * @brief @c SendStateDataSampleList STL-style iterator implementation.
37  *
38  * This class implements a STL-style iterator for the OpenDDS
39  * @c SendStateDataSampleList class. The resulting iterator may be used
40  * @c with the STL generic algorithms. It is meant for iteration
41  * @c over the "send samples" in a @c SendStateDataSampleList.
42  */
44 public:
45  typedef std::bidirectional_iterator_tag iterator_category;
47  typedef std::ptrdiff_t difference_type;
48  typedef value_type* pointer;
49  typedef value_type& reference;
50 
51  /// Default constructor required by ForwardIterator concept
53 
54  /**
55  * This constructor is used when constructing an "end" iterator.
56  */
58  DataSampleElement* tail,
59  DataSampleElement* current);
60 
61  SendStateDataSampleListIterator& operator++();
62  SendStateDataSampleListIterator operator++(int);
63  SendStateDataSampleListIterator& operator--();
64  SendStateDataSampleListIterator operator--(int);
65 
66  reference operator*();
67  pointer operator->();
68 
69  bool
71  return this->head_ == rhs.head_
72  && this->tail_ == rhs.tail_
73  && this->current_ == rhs.current_;
74  }
75 
76  bool
78  return !(*this == rhs);
79  }
80 
81 private:
85 
87 };
88 
89 /**
90  * @struct SendStateDataSampleListConstIterator
91  *
92  * @brief @c SendStateDataSampleList STL-style const iterator implementation.
93  *
94  * This class implements a STL-style const iterator for the OpenDDS
95  * @c SendStateDataSampleList class. The resulting iterator may be used
96  * @c with the STL generic algorithms. It is meant for iteration
97  * @c over the "send samples" in a @c SendStateDataSampleList.
98  */
100 public:
101  typedef std::bidirectional_iterator_tag iterator_category;
103  typedef std::ptrdiff_t difference_type;
104  typedef const DataSampleElement* pointer;
105  typedef const DataSampleElement& reference;
106 
107  /// Default constructor required by ForwardIterator concept
109 
111  const DataSampleElement* tail,
112  const DataSampleElement* current);
113 
115 
117  SendStateDataSampleListConstIterator operator++(int);
119  SendStateDataSampleListConstIterator operator--(int);
120  reference operator*() const;
121  pointer operator->() const;
122 
123  bool
125  return this->head_ == rhs.head_
126  && this->tail_ == rhs.tail_
127  && this->current_ == rhs.current_;
128  }
129 
130  bool
132  return !(*this == rhs);
133  }
134 
135 private:
139 
140 };
141 
142 /**
143 * A list of DataSampleElement pointers to be queued by the order the
144 * samples are to be transmitted over the transport layer.
145 * Cache the number of elements in the list so that list traversal is
146 * not required to find this information.
147 * The Publisher may use this to maintain a list of samples to
148 * be sent with PRESENTATION.access_scope==GROUP by obtaining
149 * data from each DataWriter as it becomes available and
150 * concatenating the data in the order in which it was written.
151 * Manages DataSampleElement's previous_send_sample/next_send_sample pointers
152 */
154 
155  friend class ::DDS_TEST;
156 
157  static const SendStateDataSampleList*
158  send_list_containing_element(const DataSampleElement* element,
159  SendStateDataSampleList** begin,
161 
162 public:
163 
164  /// STL-style bidirectional iterator and const-iterator types.
167 
168  typedef std::reverse_iterator<iterator> reverse_iterator;
169  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
170 
171  /// Default constructor clears the list.
174 
175  /// Returns a pointer to the SendStateDataSampleList containing a
176  /// given DataSampleElement for use in the typical situation where
177  /// the send state of a DataSampleElement is tracked by shifting
178  /// it between distinct SendStateDataSampleLists, one for each state
179  template <size_t N>
180  static const SendStateDataSampleList*
182  SendStateDataSampleList* (&send_lists)[N])
183  {
184  return send_list_containing_element(element,
185  &send_lists[0], &send_lists[N]);
186  }
187 
188  /// Reset to initial state.
189  void reset();
190 
191  ssize_t size() const;
192  DataSampleElement* head() const;
193  DataSampleElement* tail() const;
194 
195  void enqueue_head(const DataSampleElement* element);
196 
197  void enqueue_tail(const DataSampleElement* element);
198  void enqueue_tail(SendStateDataSampleList list);
199 
200  bool dequeue_head(DataSampleElement*& stale);
201 
202  bool dequeue(const DataSampleElement* stale);
203 
204  /// Remove from whichever list "stale" belongs to, without needing
205  /// a reference to the SendStateDataSampleList object itself.
206  /// That SendStateDataSampleList is no longer accurate and can't be used.
207  static void remove(DataSampleElement* stale);
208 
209  /// Return iterator to beginning of list.
210  iterator begin();
211  const_iterator begin() const;
212 
213  /// Return iterator to end of list.
214  iterator end();
215  const_iterator end() const;
216 
217  reverse_iterator rbegin();
218  const_reverse_iterator rbegin() const;
219  reverse_iterator rend();
220  const_reverse_iterator rend() const;
221 
222 protected:
223 
224  /// The first element of the list.
226 
227  /// The last element of the list.
229 
230  /// Number of elements in the list.
232  //TBD size is never negative so should be size_t but this ripples through
233  // the transport code so leave it for now. SHH
234 
235 };
236 
237 } // namespace DCPS
238 } // namespace OpenDDS
239 
241 
242 #if defined(__ACE_INLINE__)
244 #endif /* __ACE_INLINE__ */
245 
246 #endif /* OPENDDS_DCPS_SENDSTATEDATASAMPLELIST_H */
SendStateDataSampleListIterator iterator
STL-style bidirectional iterator and const-iterator types.
bool operator==(const SendStateDataSampleListConstIterator &rhs) const
const int MAX_READERS_TO_RESEND
SendStateDataSampleListIterator()
Default constructor required by ForwardIterator concept.
std::reverse_iterator< iterator > reverse_iterator
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
SendStateDataSampleList STL-style const iterator implementation.
ACE_Message_Block & head_
bool operator!=(const SendStateDataSampleListIterator &rhs) const
int ssize_t
SendStateDataSampleListConstIterator const_iterator
bool operator!=(const SendStateDataSampleListConstIterator &rhs) const
ssize_t size_
Number of elements in the list.
bool operator==(const SendStateDataSampleListIterator &rhs) const
DataSampleElement * head_
The first element of the list.
static const SendStateDataSampleList * send_list_containing_element(const DataSampleElement *element, SendStateDataSampleList *(&send_lists)[N])
DataSampleElement * tail_
The last element of the list.
SendStateDataSampleList STL-style iterator implementation.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
OpenDDS_Dcps_Export TimeDuration operator*(double x, const TimeDuration &y)
std::reverse_iterator< const_iterator > const_reverse_iterator
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
SendStateDataSampleListConstIterator()
Default constructor required by ForwardIterator concept.