InstanceDataSampleList.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 #include "DataSampleElement.h"
00008 #include <algorithm>
00009 
00010 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00011 
00012 namespace OpenDDS {
00013 namespace DCPS {
00014 
00015 ACE_INLINE
00016 InstanceDataSampleList::InstanceDataSampleList()
00017   : head_(0),
00018     tail_(0),
00019     size_(0)
00020 {
00021 }
00022 
00023 ACE_INLINE
00024 void InstanceDataSampleList::reset()
00025 {
00026   head_ = tail_ = 0;
00027   size_ = 0;
00028 }
00029 
00030 ACE_INLINE
00031 ssize_t
00032 InstanceDataSampleList::size() const
00033 {
00034   return size_;
00035 }
00036 
00037 ACE_INLINE
00038 DataSampleElement*
00039 InstanceDataSampleList::head() const
00040 {
00041   return head_;
00042 }
00043 
00044 ACE_INLINE
00045 DataSampleElement*
00046 InstanceDataSampleList::tail() const
00047 {
00048   return tail_;
00049 }
00050 
00051 ACE_INLINE
00052 DataSampleElement*
00053 InstanceDataSampleList::next(const DataSampleElement* iter)
00054 {
00055   return iter->next_instance_sample_;
00056 }
00057 
00058 ACE_INLINE
00059 DataSampleElement*
00060 InstanceDataSampleList::prev(const DataSampleElement* iter)
00061 {
00062   return iter->previous_instance_sample_;
00063 }
00064 
00065 ACE_INLINE
00066 void
00067 InstanceDataSampleList::enqueue_tail(const DataSampleElement* sample)
00068 {
00069   // const_cast here so that higher layers don't need to pass around so many
00070   // non-const pointers to DataSampleElement.  Ideally the design would be
00071   // changed to accommodate const-correctness throughout.
00072   DataSampleElement* mSample = const_cast<DataSampleElement*>(sample);
00073 
00074   mSample->next_instance_sample_ = 0;
00075 
00076   ++size_;
00077 
00078   if (head_ == 0) {
00079     // First sample on queue.
00080     head_ = tail_ = mSample;
00081 
00082   } else {
00083     // Another sample on an existing queue.
00084     tail_->next_instance_sample_ = mSample;
00085     mSample->previous_instance_sample_ = tail_;
00086     tail_ = mSample;
00087   }
00088 }
00089 
00090 ACE_INLINE
00091 bool
00092 InstanceDataSampleList::dequeue_head(DataSampleElement*& stale)
00093 {
00094   //
00095   // Remove the oldest sample from the instance list.
00096   //
00097   stale = head_;
00098 
00099   if (head_ == 0) {
00100     // try to dequeue empty instance list.
00101     return false;
00102 
00103   } else {
00104     --size_;
00105     head_ = head_->next_instance_sample_;
00106 
00107     if (head_ == 0) {
00108       tail_ = 0;
00109     } else {
00110       head_->previous_instance_sample_ = 0;
00111     }
00112 
00113     stale->next_instance_sample_ = 0;
00114     return true;
00115   }
00116 }
00117 
00118 } // namespace DCPS
00119 } // namespace OpenDDS
00120 
00121 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