ReceivedDataElementList.cpp

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 "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00008 #include "ReceivedDataElementList.h"
00009 
00010 #if !defined (__ACE_INLINE__)
00011 # include "ReceivedDataElementList.inl"
00012 #endif /* !__ACE_INLINE__ */
00013 
00014 namespace {
00015 
00016 class IdentityFilter
00017   : public OpenDDS::DCPS::ReceivedDataFilter {
00018 public:
00019   explicit IdentityFilter(OpenDDS::DCPS::ReceivedDataElement* data_sample)
00020     : data_sample_(data_sample)
00021   {}
00022 
00023   bool
00024   operator()(OpenDDS::DCPS::ReceivedDataElement* data_sample) {
00025     return this->data_sample_ == data_sample;
00026   }
00027 
00028 private:
00029   OpenDDS::DCPS::ReceivedDataElement* data_sample_;
00030 };
00031 
00032 } // namespace
00033 
00034 
00035 void* OpenDDS::DCPS::ReceivedDataElement::operator new(size_t , ACE_New_Allocator& pool)
00036 {
00037   OpenDDS::DCPS::ReceivedDataElementMemoryBlock* block =  static_cast<OpenDDS::DCPS::ReceivedDataElementMemoryBlock*>(pool.malloc(sizeof(OpenDDS::DCPS::ReceivedDataElementMemoryBlock)));
00038   block->allocator_ = &pool;
00039   return block;
00040 }
00041 
00042 void OpenDDS::DCPS::ReceivedDataElement::operator delete(void* memory)
00043 {
00044   if (memory) {
00045     OpenDDS::DCPS::ReceivedDataElementMemoryBlock* block = static_cast<OpenDDS::DCPS::ReceivedDataElementMemoryBlock*>(memory);
00046     block->allocator_->free(block);
00047   }
00048 }
00049 
00050 void OpenDDS::DCPS::ReceivedDataElement::operator delete(void* memory, ACE_New_Allocator&)
00051 {
00052   operator delete(memory);
00053 }
00054 
00055 OpenDDS::DCPS::ReceivedDataElementList::ReceivedDataElementList(InstanceState *instance_state)
00056   : head_(0), tail_(0), size_(0), instance_state_(instance_state)
00057 {
00058 }
00059 
00060 OpenDDS::DCPS::ReceivedDataElementList::~ReceivedDataElementList()
00061 {
00062   // The memory pointed to by instance_state_ is owned by
00063   // another object.
00064 }
00065 
00066 void
00067 OpenDDS::DCPS::ReceivedDataElementList::apply_all(
00068   ReceivedDataFilter& match,
00069   ReceivedDataOperation& op)
00070 {
00071   for (ReceivedDataElement* it = head_;
00072        it != 0 ; it = it->next_data_sample_) {
00073     if (match(it)) {
00074       op(it);
00075     }
00076   }
00077 }
00078 
00079 bool
00080 OpenDDS::DCPS::ReceivedDataElementList::remove(
00081   ReceivedDataFilter& match,
00082   bool eval_all)
00083 {
00084   if (!head_) {
00085     return false;
00086   }
00087 
00088   bool released = false;
00089 
00090   for (ReceivedDataElement* item = head_ ; item != 0 ;
00091        item = item->next_data_sample_) {
00092     if (match(item)) {
00093       size_-- ;
00094 
00095       if (item == head_) {
00096         if (head_ == tail_) {
00097           head_ = tail_ = 0;
00098 
00099         } else {
00100           head_ = item->next_data_sample_ ;
00101 
00102           if (head_) {
00103             head_->previous_data_sample_ = 0 ;
00104           }
00105         }
00106 
00107       } else if (item == tail_) {
00108         tail_ = item->previous_data_sample_ ;
00109 
00110         if (tail_) {
00111           tail_->next_data_sample_ = 0 ;
00112         }
00113 
00114       } else {
00115         item->previous_data_sample_->next_data_sample_ =
00116           item->next_data_sample_ ;
00117         item->next_data_sample_->previous_data_sample_ =
00118           item->previous_data_sample_ ;
00119       }
00120 
00121       if (instance_state_ && size_ == 0) {
00122         // let the instance know it is empty
00123         released = released || instance_state_->empty(true);
00124       }
00125 
00126       if (!eval_all) break;
00127     }
00128   }
00129 
00130   return released;
00131 }
00132 
00133 bool
00134 OpenDDS::DCPS::ReceivedDataElementList::remove(ReceivedDataElement *data_sample)
00135 {
00136   IdentityFilter match(data_sample);
00137   return remove(match, false); // short-circuit evaluation
00138 }
00139 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1