RakeResults_T.h

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 #ifndef RAKERESULTS_H
00009 #define RAKERESULTS_H
00010 
00011 #include /**/ "ace/pre.h"
00012 
00013 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00014 # pragma once
00015 #endif /* ACE_LACKS_PRAGMA_ONCE */
00016 
00017 #include "dds/DdsDcpsSubscriptionC.h"
00018 #include "RakeData.h"
00019 #include "Comparator_T.h"
00020 #include "PoolAllocator.h"
00021 
00022 namespace OpenDDS {
00023 namespace DCPS {
00024 
00025 enum Operation_t { DDS_OPERATION_READ, DDS_OPERATION_TAKE };
00026 
00027 /// Rake is an abbreviation for "read or take".  This class manages the
00028 /// results from a read() or take() operation, which are the received_data
00029 /// and the info_seq sequences passed in by-reference from the user.
00030 template <class SampleSeq>
00031 class RakeResults {
00032 public:
00033   RakeResults(DataReaderImpl* reader,
00034               SampleSeq& received_data,
00035               DDS::SampleInfoSeq& info_seq,
00036               CORBA::Long max_samples,
00037               DDS::PresentationQosPolicy presentation,
00038 #ifndef OPENDDS_NO_QUERY_CONDITION
00039               DDS::QueryCondition_ptr cond,
00040 #endif
00041               Operation_t oper);
00042 
00043   /// Returns false if the sample will definitely not be part of the
00044   /// resulting dataset, however if this returns true it still may be
00045   /// excluded (due to sorting and max_samples).
00046   bool insert_sample(ReceivedDataElement* sample, SubscriptionInstance* i,
00047                      size_t index_in_instance);
00048 
00049   bool copy_to_user();
00050 
00051 private:
00052   template <class FwdIter>
00053   bool copy_into(FwdIter begin, FwdIter end,
00054                  typename SampleSeq::PrivateMemberAccess& received_data_p);
00055 
00056   RakeResults(const RakeResults&); // no copy construction
00057   RakeResults& operator=(const RakeResults&); // no assignment
00058 
00059   DataReaderImpl* reader_;
00060   SampleSeq& received_data_;
00061   DDS::SampleInfoSeq& info_seq_;
00062   CORBA::ULong max_samples_;
00063 #ifndef OPENDDS_NO_QUERY_CONDITION
00064   DDS::QueryCondition_ptr cond_;
00065 #endif
00066   Operation_t oper_;
00067 
00068   class SortedSetCmp {
00069   public:
00070     bool operator()(const RakeData& lhs, const RakeData& rhs) const {
00071       if (!cmp_.in()) {
00072         // The following assumes that if no comparator is set
00073         // then PRESENTATION ordered access applies (TOPIC).
00074         return lhs.rde_->source_timestamp_ < rhs.rde_->source_timestamp_;
00075       }
00076 
00077       return cmp_->compare(lhs.rde_->registered_data_,
00078                            rhs.rde_->registered_data_);
00079     }
00080 
00081     explicit SortedSetCmp(ComparatorBase::Ptr cmp = 0) : cmp_(cmp) {}
00082 
00083   private:
00084     ComparatorBase::Ptr cmp_;
00085   };
00086 
00087   bool do_sort_, do_filter_;
00088   typedef OPENDDS_MULTISET_CMP(RakeData, SortedSetCmp) SortedSet;
00089 
00090   // Contains data for QueryCondition/Ordered access
00091   SortedSet sorted_;
00092 
00093   // Contains data for all other use cases
00094   OPENDDS_VECTOR(RakeData) unsorted_;
00095 
00096   // data structures used by copy_into()
00097   typedef OPENDDS_VECTOR(CORBA::ULong) IndexList;
00098   struct InstanceData {
00099     bool most_recent_generation_;
00100     size_t MRSIC_index_;
00101     IndexList sampleinfo_positions_;
00102     CORBA::Long MRSIC_disposed_gc_, MRSIC_nowriters_gc_,
00103     MRS_disposed_gc_, MRS_nowriters_gc_;
00104     InstanceData() : most_recent_generation_(false), MRSIC_index_(0),
00105       MRSIC_disposed_gc_(0), MRSIC_nowriters_gc_(0), MRS_disposed_gc_(0),
00106       MRS_nowriters_gc_(0) {}
00107   };
00108 };
00109 
00110 } // namespace DCPS
00111 } // namespace OpenDDS
00112 
00113 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00114 #include "dds/DCPS/RakeResults_T.cpp"
00115 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00116 
00117 #include /**/ "ace/post.h"
00118 
00119 #endif /* RAKERESULTS_H  */

Generated on Fri Feb 12 20:05:25 2016 for OpenDDS by  doxygen 1.4.7