WriterDataSampleList.inl

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DataSampleElement.h"
00009 #include <algorithm>
00010 
00011 namespace OpenDDS {
00012 namespace DCPS {
00013 
00014 
00015 ACE_INLINE
00016 WriterDataSampleList::WriterDataSampleList()
00017   : head_(0),
00018     tail_(0),
00019     size_(0)
00020 {
00021 }
00022 
00023 ACE_INLINE
00024 void WriterDataSampleList::reset()
00025 {
00026   head_ = tail_ = 0;
00027   size_ = 0;
00028 }
00029 
00030 ACE_INLINE
00031 ssize_t
00032 WriterDataSampleList::size() const
00033 {
00034   return size_;
00035 }
00036 
00037 ACE_INLINE
00038 DataSampleElement*
00039 WriterDataSampleList::head() const
00040 {
00041   return head_;
00042 }
00043 
00044 ACE_INLINE
00045 DataSampleElement*
00046 WriterDataSampleList::tail() const
00047 {
00048   return tail_;
00049 }
00050 
00051 ACE_INLINE
00052 void
00053 WriterDataSampleList::enqueue_tail(const DataSampleElement* sample)
00054 {
00055   // const_cast here so that higher layers don't need to pass around so many
00056   // non-const pointers to DataSampleElement.  Ideally the design would be
00057   // changed to accommodate const-correctness throughout.
00058   DataSampleElement* mSample = const_cast<DataSampleElement*>(sample);
00059 
00060   //sample->previous_writer_sample_ = 0;
00061   //sample->next_writer_sample_ = 0;
00062 
00063   ++size_ ;
00064 
00065   if (head_ == 0) {
00066     // First sample in the list.
00067     head_ = tail_ = mSample ;
00068 
00069   } else {
00070     // Add to existing list.
00071     tail_->next_writer_sample_ = mSample ;
00072     mSample->previous_writer_sample_ = tail_;
00073     tail_ = mSample;
00074   }
00075 }
00076 
00077 ACE_INLINE
00078 bool
00079 WriterDataSampleList::dequeue_head(DataSampleElement*& stale)
00080 {
00081   //
00082   // Remove the oldest sample from the list.
00083   //
00084   stale = head_;
00085 
00086   if (head_ == 0) {
00087     return false;
00088 
00089   } else {
00090     --size_ ;
00091     head_ = head_->next_writer_sample_;
00092 
00093     if (head_ == 0) {
00094       tail_ = 0;
00095 
00096     } else {
00097       head_->previous_writer_sample_ = 0;
00098     }
00099 
00100     stale->next_writer_sample_ = 0;
00101     stale->previous_writer_sample_ = 0;
00102     return true;
00103   }
00104 }
00105 
00106 
00107 } // namespace DCPS
00108 } // namespace OpenDDS

Generated on Fri Feb 12 20:05:29 2016 for OpenDDS by  doxygen 1.4.7