00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/ 00009 #include "ReceivedDataElementList.h" 00010 00011 #if !defined (__ACE_INLINE__) 00012 # include "ReceivedDataElementList.inl" 00013 #endif /* !__ACE_INLINE__ */ 00014 00015 namespace { 00016 00017 class IdentityFilter 00018 : public OpenDDS::DCPS::ReceivedDataFilter { 00019 public: 00020 explicit IdentityFilter(OpenDDS::DCPS::ReceivedDataElement* data_sample) 00021 : data_sample_(data_sample) 00022 {} 00023 00024 bool 00025 operator()(OpenDDS::DCPS::ReceivedDataElement* data_sample) { 00026 return this->data_sample_ == data_sample; 00027 } 00028 00029 private: 00030 OpenDDS::DCPS::ReceivedDataElement* data_sample_; 00031 }; 00032 00033 } // namespace 00034 00035 OpenDDS::DCPS::ReceivedDataElementList::ReceivedDataElementList(InstanceState *instance_state) 00036 : head_(0), tail_(0), size_(0), instance_state_(instance_state) 00037 { 00038 } 00039 00040 OpenDDS::DCPS::ReceivedDataElementList::~ReceivedDataElementList() 00041 { 00042 // The memory pointed to by instance_state_ is owned by 00043 // another object. 00044 } 00045 00046 void 00047 OpenDDS::DCPS::ReceivedDataElementList::apply_all( 00048 ReceivedDataFilter& match, 00049 ReceivedDataOperation& op) 00050 { 00051 for (ReceivedDataElement* it = head_; 00052 it != 0 ; it = it->next_data_sample_) { 00053 if (match(it)) { 00054 op(it); 00055 } 00056 } 00057 } 00058 00059 bool 00060 OpenDDS::DCPS::ReceivedDataElementList::remove( 00061 ReceivedDataFilter& match, 00062 bool eval_all) 00063 { 00064 if (!head_) { 00065 return false; 00066 } 00067 00068 bool released = false; 00069 00070 for (ReceivedDataElement* item = head_ ; item != 0 ; 00071 item = item->next_data_sample_) { 00072 if (match(item)) { 00073 size_-- ; 00074 00075 if (item == head_) { 00076 if (head_ == tail_) { 00077 head_ = tail_ = 0; 00078 00079 } else { 00080 head_ = item->next_data_sample_ ; 00081 00082 if (head_) { 00083 head_->previous_data_sample_ = 0 ; 00084 } 00085 } 00086 00087 } else if (item == tail_) { 00088 tail_ = item->previous_data_sample_ ; 00089 00090 if (tail_) { 00091 tail_->next_data_sample_ = 0 ; 00092 } 00093 00094 } else { 00095 item->previous_data_sample_->next_data_sample_ = 00096 item->next_data_sample_ ; 00097 item->next_data_sample_->previous_data_sample_ = 00098 item->previous_data_sample_ ; 00099 } 00100 00101 if (instance_state_ && size_ == 0) { 00102 // let the instance know it is empty 00103 released = released || instance_state_->empty(true); 00104 } 00105 00106 if (!eval_all) break; 00107 } 00108 } 00109 00110 return released; 00111 } 00112 00113 bool 00114 OpenDDS::DCPS::ReceivedDataElementList::remove(ReceivedDataElement *data_sample) 00115 { 00116 IdentityFilter match(data_sample); 00117 return remove(match, false); // short-circuit evaluation 00118 }