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