#include <BasicQueue_T.h>
Inheritance diagram for OpenDDS::DCPS::BasicQueue< T >:
Public Member Functions | |
BasicQueue (size_t links_per_pool, size_t initial_pools) | |
~BasicQueue () | |
int | put (T *elem) |
Put a pointer to an element (T*) on to the queue. | |
T * | peek () const |
void | replace_head (T *value) |
T * | get () |
size_t | size () const |
Accessor for the current number of elements in the queue. | |
void | accept_visitor (VisitorType &visitor) const |
void | accept_remove_visitor (VisitorType &visitor) |
void | accept_replace_visitor (VisitorType &visitor) |
Private Types | |
typedef BasicQueueLinkPool< T > | PoolType |
typedef BasicQueueLink< T > | LinkType |
typedef BasicQueueVisitor< T > | VisitorType |
Private Member Functions | |
void | remove_next (LinkType *prev) |
Private Attributes | |
LinkType * | head_ |
The first (oldest) link in the queue. | |
LinkType * | tail_ |
The last (newest) link in the queue. | |
size_t | size_ |
The number of links currently in the queue. | |
PoolType | pool_ |
Definition at line 19 of file BasicQueue_T.h.
typedef BasicQueueLink<T> OpenDDS::DCPS::BasicQueue< T >::LinkType [private] |
Definition at line 23 of file BasicQueue_T.h.
typedef BasicQueueLinkPool<T> OpenDDS::DCPS::BasicQueue< T >::PoolType [private] |
Definition at line 22 of file BasicQueue_T.h.
typedef BasicQueueVisitor<T> OpenDDS::DCPS::BasicQueue< T >::VisitorType [private] |
Definition at line 24 of file BasicQueue_T.h.
OpenDDS::DCPS::BasicQueue< T >::BasicQueue | ( | size_t | links_per_pool, | |
size_t | initial_pools | |||
) | [inline] |
OpenDDS::DCPS::BasicQueue< T >::~BasicQueue | ( | ) | [inline] |
void OpenDDS::DCPS::BasicQueue< T >::accept_remove_visitor | ( | VisitorType & | visitor | ) | [inline] |
Alternate way to supply a visitor to the queue - this will invoke visit_element(T* element, int& remove) on the supplied visitor object once for each element in this BasicQueue<T> object, in order.
The remove argument is a flag that should be set to true (1) in the visitor's visit_element_remove(T* element, int& remove) method if the visitor decides that the element should be removed from the queue. The remove flag is always set to false (0) prior to calling the visitor's visit_element_remove(T* element, int& remove) method.
The visitor can stop visitation early by returning 0 from its visit_element_remove(T* element, int& remove) method.
Definition at line 159 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::TransportSendStrategy::clear(), and OpenDDS::DCPS::TransportSendStrategy::do_remove_sample().
00159 { 00160 LinkType* prev_link = 0; 00161 LinkType* link = this->head_; 00162 00163 while (link != 0) { 00164 // Save off the next_link now, in case we end up removing 00165 // (and releasing) the current link via a call to our 00166 // remove_next() call further on. 00167 LinkType* next_link = link->next(); 00168 00169 T* element = link->elem(); 00170 00171 int remove = 0; 00172 00173 int keep_going = visitor.visit_element_remove(element, remove); 00174 00175 if (remove == 1) { 00176 this->remove_next(prev_link); 00177 00178 // We shouldn't change the prev_link here, because it 00179 // has become the prev_link of the next_link since the 00180 // (middle-man) link was just removed. 00181 00182 } else { 00183 // Set it up for visitation of the next link. 00184 // Adjust the prev_link here because we didn't remove 00185 // the link. 00186 prev_link = link; 00187 } 00188 00189 link = next_link; 00190 00191 if (keep_going == 0) { 00192 // We are done. 00193 return; 00194 } 00195 } 00196 }
void OpenDDS::DCPS::BasicQueue< T >::accept_replace_visitor | ( | VisitorType & | visitor | ) | [inline] |
This kind of visitation may cause the visitor to replace the currently visited element with a new element.
Definition at line 200 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::TransportSendStrategy::do_remove_sample().
00200 { 00201 LinkType* link = this->head_; 00202 00203 while (link != 0) { 00204 // The subtle difference between this visitation method 00205 // and the normal "accept_visitor" visitation method is 00206 // that we supply a reference to a pointer to an element 00207 // here rather than just a pointer to an element. This 00208 // allows the visitor to "replace" the current element 00209 // with a new element. 00210 if (visitor.visit_element_ref(link->elem_ref()) == 0) { 00211 return; 00212 } 00213 00214 link = link->next(); 00215 } 00216 }
void OpenDDS::DCPS::BasicQueue< T >::accept_visitor | ( | VisitorType & | visitor | ) | const [inline] |
Standard way to supply a visitor to the queue - this will invoke visit_element(T* element) on the supplied visitor object once for each element in this BasicQueue<T> object, in order. The visitor can stop visitation early by returning 0 from its visit_element(T* element) method.
Definition at line 133 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::SingleSendBuffer::insert_buffer(), OpenDDS::DCPS::TransportSendStrategy::prepare_packet(), and OpenDDS::DCPS::ThreadPerConnectionSendTask::remove_sample().
00133 { 00134 LinkType* link = this->head_; 00135 00136 while (link != 0) { 00137 if (visitor.visit_element(link->elem()) == 0) { 00138 return; 00139 } 00140 00141 link = link->next(); 00142 } 00143 }
T* OpenDDS::DCPS::BasicQueue< T >::get | ( | ) | [inline] |
Extract the top element from the queue. Returns 0 if there are no elements in the queue.
Definition at line 90 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::TransportSendStrategy::adjust_packet_after_send(), and OpenDDS::DCPS::ThreadPerConnectionSendTask::svc().
00090 { 00091 LinkType* link = this->head_; 00092 00093 if (link == 0) { 00094 // The queue is empty. Return a NULL pointer (0). 00095 return 0; 00096 } 00097 00098 // Adjust the head_ (and possibly the tail_ if there is only 00099 // one link currently in the queue). 00100 this->head_ = link->next(); 00101 00102 if (this->head_ == 0) { 00103 // That was the only link in the queue. Now that the head_ 00104 // indicates that the queue is empty, we need to update the 00105 // tail_ accordingly because we know it was pointing to the 00106 // same link as the head_. 00107 this->tail_ = 0; 00108 } 00109 00110 // Save off the pointer to the link's elem(). 00111 T* elem = link->elem(); 00112 00113 // Release the link object back to the pool. 00114 this->pool_.release(link); 00115 00116 // Decrement our size_ by one. 00117 --this->size_; 00118 00119 // And finally return the elem. 00120 return elem; 00121 }
T* OpenDDS::DCPS::BasicQueue< T >::peek | ( | ) | const [inline] |
Peek at the element at the top of the queue. This is just like the get() operation except that the queue remains intact.
Definition at line 73 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::TransportSendStrategy::adjust_packet_after_send(), OpenDDS::DCPS::TransportSendStrategy::current_packet_first_element(), OpenDDS::DCPS::TransportSendStrategy::get_packet_elems_from_queue(), and OpenDDS::DCPS::RtpsUdpDataLink::MultiSendBuffer::insert().
00073 { 00074 if (this->head_ == 0) { 00075 // The queue is empty. Return a NULL pointer (0). 00076 return 0; 00077 } 00078 00079 return this->head_->elem(); 00080 }
int OpenDDS::DCPS::BasicQueue< T >::put | ( | T * | elem | ) | [inline] |
Put a pointer to an element (T*) on to the queue.
Definition at line 39 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::ThreadPerConnectionSendTask::add_request(), OpenDDS::DCPS::TransportSendStrategy::get_packet_elems_from_queue(), and OpenDDS::DCPS::TransportSendStrategy::send().
00039 { 00040 // Get a "new" link from the pool. 00041 LinkType* link = pool_.obtain(elem); 00042 00043 if (link == 0) { 00044 // Shouldn't happen unless we run out of memory (or encounter 00045 // an internal error condition of some sort, making the 00046 // pool_ unable to provide us with a valid link). 00047 return -1; 00048 } 00049 00050 // Insert the link on the the end of the queue. 00051 if (this->tail_ == 0) { 00052 // The tail_ is NULL only when the queue is empty. 00053 // Set both the head_ and tail_ to point to the "new" link. 00054 this->head_ = this->tail_ = link; 00055 00056 } else { 00057 // There is at least one element in the queue. 00058 // Set the next() of the current tail_ link to point to 00059 // the "new" link. Then set the tail_ to point to the 00060 // "new" link. 00061 this->tail_->next(link); 00062 this->tail_ = link; 00063 } 00064 00065 // Increment our size_ by one. 00066 ++this->size_; 00067 00068 return 0; 00069 }
void OpenDDS::DCPS::BasicQueue< T >::remove_next | ( | LinkType * | prev | ) | [inline, private] |
Used by our accept_remove_visitor() method when an element needs to be removed from this BasicQueue<T> object. The element that is supposed to be removed is the next() link object of the supplied "prev" link object. It's done this way so that the (singlely) linked-list can be stitched back together after the appropriate link has been removed.
Definition at line 226 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::accept_remove_visitor().
00226 { 00227 // We are either removing the head_ or the prev->next(). 00228 // Note that we assume that in this contect, head_ will not 00229 // be NULL (0). And, if prev is not NULL (0), then we assume 00230 // that prev->next() is not NULL (0). 00231 // 00232 // Note that we also assume that the prev link (if not NULL), 00233 // is indeed a member of the queue! 00234 LinkType* link = (prev == 0) ? this->head_ : prev->next(); 00235 00236 // Handle the case where the queue only contains one link 00237 // (we can then assume that this is the link we are removing). 00238 if (this->head_ == this->tail_) { 00239 // We are removing the only link in the queue. 00240 this->head_ = this->tail_ = 0; 00241 00242 } else if (link == this->head_) { 00243 // We are removing the head link, and we know that there 00244 // are other links still in the queue. 00245 this->head_ = this->head_->next(); 00246 00247 } else if (link == this->tail_) { 00248 // We are removing the tail link, and we know that there 00249 // are other links still in the queue. 00250 prev->next(0); 00251 this->tail_ = prev; 00252 00253 } else { 00254 // We are removing a link that is neither the head_ link 00255 // nor the tail_ link. 00256 prev->next(link->next()); 00257 } 00258 00259 // Decrement our size by one 00260 --this->size_; 00261 00262 // And finally, we can release the link back to the pool. 00263 this->pool_.release(link); 00264 }
void OpenDDS::DCPS::BasicQueue< T >::replace_head | ( | T * | value | ) | [inline] |
Definition at line 82 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::TransportSendStrategy::get_packet_elems_from_queue().
size_t OpenDDS::DCPS::BasicQueue< T >::size | ( | ) | const [inline] |
Accessor for the current number of elements in the queue.
Definition at line 124 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::SingleSendBuffer::insert_buffer().
00124 { 00125 return this->size_; 00126 }
LinkType* OpenDDS::DCPS::BasicQueue< T >::head_ [private] |
The first (oldest) link in the queue.
Definition at line 267 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::accept_remove_visitor(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::accept_replace_visitor(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::accept_visitor(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::get(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::peek(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::put(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::remove_next(), and OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::replace_head().
PoolType OpenDDS::DCPS::BasicQueue< T >::pool_ [private] |
The pool of precreated LinkType objects (a "self-growing" allocator is used by the pool).
Definition at line 277 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::get(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::put(), and OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::remove_next().
size_t OpenDDS::DCPS::BasicQueue< T >::size_ [private] |
The number of links currently in the queue.
Definition at line 273 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::get(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::put(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::remove_next(), and OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::size().
LinkType* OpenDDS::DCPS::BasicQueue< T >::tail_ [private] |
The last (newest) link in the queue.
Definition at line 270 of file BasicQueue_T.h.
Referenced by OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::get(), OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::put(), and OpenDDS::DCPS::BasicQueue< OpenDDS::DCPS::TransportQueueElement >::remove_next().