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 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00012 
00013 namespace OpenDDS {
00014 namespace DCPS {
00015 
00016 ACE_INLINE
00017 WriterDataSampleList::WriterDataSampleList()
00018   : head_(0),
00019     tail_(0),
00020     size_(0)
00021 {
00022 }
00023 
00024 ACE_INLINE
00025 void WriterDataSampleList::reset()
00026 {
00027   head_ = tail_ = 0;
00028   size_ = 0;
00029 }
00030 
00031 ACE_INLINE
00032 ssize_t
00033 WriterDataSampleList::size() const
00034 {
00035   return size_;
00036 }
00037 
00038 ACE_INLINE
00039 DataSampleElement*
00040 WriterDataSampleList::head() const
00041 {
00042   return head_;
00043 }
00044 
00045 ACE_INLINE
00046 DataSampleElement*
00047 WriterDataSampleList::tail() const
00048 {
00049   return tail_;
00050 }
00051 
00052 ACE_INLINE
00053 void
00054 WriterDataSampleList::enqueue_tail(const DataSampleElement* sample)
00055 {
00056   // const_cast here so that higher layers don't need to pass around so many
00057   // non-const pointers to DataSampleElement.  Ideally the design would be
00058   // changed to accommodate const-correctness throughout.
00059   DataSampleElement* mSample = const_cast<DataSampleElement*>(sample);
00060 
00061   //sample->previous_writer_sample_ = 0;
00062   //sample->next_writer_sample_ = 0;
00063 
00064   ++size_ ;
00065 
00066   if (head_ == 0) {
00067     // First sample in the list.
00068     head_ = tail_ = mSample ;
00069 
00070   } else {
00071     // Add to existing list.
00072     tail_->next_writer_sample_ = mSample ;
00073     mSample->previous_writer_sample_ = tail_;
00074     tail_ = mSample;
00075   }
00076 }
00077 
00078 ACE_INLINE
00079 bool
00080 WriterDataSampleList::dequeue_head(DataSampleElement*& stale)
00081 {
00082   //
00083   // Remove the oldest sample from the list.
00084   //
00085   stale = head_;
00086 
00087   if (head_ == 0) {
00088     return false;
00089 
00090   } else {
00091     --size_ ;
00092     head_ = head_->next_writer_sample_;
00093 
00094     if (head_ == 0) {
00095       tail_ = 0;
00096 
00097     } else {
00098       head_->previous_writer_sample_ = 0;
00099     }
00100 
00101     stale->next_writer_sample_ = 0;
00102     stale->previous_writer_sample_ = 0;
00103     return true;
00104   }
00105 }
00106 
00107 
00108 } // namespace DCPS
00109 } // namespace OpenDDS
00110 
00111 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1