Line data Source code
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 : 12 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 13 : 14 : namespace OpenDDS { 15 : namespace DCPS { 16 : 17 : ACE_INLINE 18 0 : SendStateDataSampleList::SendStateDataSampleList() 19 0 : : head_(0), 20 0 : tail_(0), 21 0 : size_(0) 22 : { 23 0 : } 24 : 25 : ACE_INLINE 26 0 : void SendStateDataSampleList::reset() 27 : { 28 0 : head_ = tail_ = 0; 29 0 : size_ = 0; 30 0 : } 31 : 32 : ACE_INLINE 33 : ssize_t 34 0 : SendStateDataSampleList::size() const 35 : { 36 0 : return size_; 37 : } 38 : 39 : ACE_INLINE 40 : DataSampleElement* 41 0 : SendStateDataSampleList::head() const 42 : { 43 0 : return head_; 44 : } 45 : 46 : ACE_INLINE 47 : DataSampleElement* 48 0 : SendStateDataSampleList::tail() const 49 : { 50 0 : return tail_; 51 : } 52 : 53 : ACE_INLINE 54 : void 55 0 : SendStateDataSampleList::enqueue_head(const DataSampleElement* sample) 56 : { 57 0 : ++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 0 : DataSampleElement* mSample = const_cast<DataSampleElement*>(sample); 63 : 64 0 : if (head_ == 0) { 65 0 : head_ = tail_ = mSample; 66 0 : sample->next_send_sample_ = sample->previous_send_sample_ = 0; 67 : 68 : } else { 69 0 : sample->next_send_sample_ = head_; 70 0 : sample->previous_send_sample_ = 0; 71 0 : head_->previous_send_sample_ = mSample; 72 0 : head_ = mSample; 73 : } 74 0 : } 75 : 76 : ACE_INLINE 77 : void 78 0 : SendStateDataSampleList::enqueue_tail(const DataSampleElement* sample) 79 : { 80 0 : ++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 0 : DataSampleElement* mSample = const_cast<DataSampleElement*>(sample); 86 : 87 0 : if (head_ == 0) { 88 0 : head_ = tail_ = mSample; 89 0 : sample->next_send_sample_ = sample->previous_send_sample_ = 0; 90 : 91 : } else { 92 0 : sample->previous_send_sample_ = tail_; 93 0 : sample->next_send_sample_ = 0; 94 0 : tail_->next_send_sample_ = mSample; 95 0 : tail_ = mSample; 96 : } 97 0 : } 98 : 99 : ACE_INLINE 100 : bool 101 0 : SendStateDataSampleList::dequeue_head(DataSampleElement*& stale) 102 : { 103 : // 104 : // Remove the oldest sample from the instance list. 105 : // 106 0 : stale = head_; 107 : 108 0 : if (head_ == 0) { 109 0 : return false; 110 : 111 : } else { 112 0 : --size_; 113 : 114 0 : head_ = head_->next_send_sample_; 115 : 116 0 : if (head_ == 0) { 117 0 : tail_ = 0; 118 : 119 : } else { 120 0 : head_->previous_send_sample_ = 0; 121 : } 122 : 123 0 : stale->next_send_sample_ = 0; 124 0 : stale->previous_send_sample_ = 0; 125 : 126 0 : return true; 127 : } 128 : } 129 : 130 : ACE_INLINE 131 : void 132 0 : SendStateDataSampleList::remove(DataSampleElement* stale) 133 : { 134 0 : if (stale->previous_send_sample_) { 135 0 : stale->previous_send_sample_->next_send_sample_ = stale->next_send_sample_; 136 : } 137 0 : if (stale->next_send_sample_) { 138 0 : stale->next_send_sample_->previous_send_sample_ = stale->previous_send_sample_; 139 : } 140 0 : } 141 : 142 : ACE_INLINE 143 : SendStateDataSampleList::iterator 144 0 : SendStateDataSampleList::begin() 145 : { 146 0 : return iterator(this->head_, this->tail_, this->head_); 147 : } 148 : 149 : ACE_INLINE 150 : SendStateDataSampleList::iterator 151 0 : SendStateDataSampleList::end() 152 : { 153 0 : return iterator(this->head_, this->tail_, 0); 154 : } 155 : 156 : ACE_INLINE 157 : SendStateDataSampleList::const_iterator 158 0 : SendStateDataSampleList::begin() const 159 : { 160 0 : return const_iterator(this->head_, this->tail_, this->head_); 161 : } 162 : 163 : ACE_INLINE 164 : SendStateDataSampleList::const_iterator 165 0 : SendStateDataSampleList::end() const 166 : { 167 0 : return const_iterator(this->head_, this->tail_, 0); 168 : } 169 : 170 : ACE_INLINE 171 : SendStateDataSampleList::reverse_iterator 172 : SendStateDataSampleList::rbegin() 173 : { 174 : return reverse_iterator(end()); 175 : } 176 : 177 : ACE_INLINE 178 : SendStateDataSampleList::reverse_iterator 179 : SendStateDataSampleList::rend() 180 : { 181 : return reverse_iterator(begin()); 182 : } 183 : 184 : ACE_INLINE 185 : SendStateDataSampleList::const_reverse_iterator 186 0 : SendStateDataSampleList::rbegin() const 187 : { 188 0 : return const_reverse_iterator(end()); 189 : } 190 : 191 : ACE_INLINE 192 : SendStateDataSampleList::const_reverse_iterator 193 0 : SendStateDataSampleList::rend() const 194 : { 195 0 : return const_reverse_iterator(begin()); 196 : } 197 : 198 : } // namespace DCPS 199 : } // namespace OpenDDS 200 : 201 : OPENDDS_END_VERSIONED_NAMESPACE_DECL