DataCollector_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 DATA_COLLECTOR_H
00009 #define DATA_COLLECTOR_H
00010 
00011 // Needed here to avoid the pragma below when necessary.
00012 #include /**/ "ace/pre.h"
00013 #include /**/ "ace/config-all.h"
00014 
00015 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00016 #pragma once
00017 #endif /* ACE_LACKS_PRAGMA_ONCE */
00018 
00019 #include "dds/DCPS/PoolAllocator.h"
00020 #include "dds/DCPS/SafetyProfileStreams.h"
00021 
00022 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00023 
00024 namespace OpenDDS {
00025 namespace DCPS {
00026 
00027 /**
00028  * @class DataCollector<DatumType>
00029  *
00030  * @brief Collect data in a buffer.
00031  *
00032  * This class implements a rudimentary data collection mechanism.  It is
00033  * extendable to allow data to be collected as a feature of a more
00034  * complex class.
00035  */
00036 template<typename DatumType>
00037 class DataCollector {
00038 public:
00039   /// Selectors for behavior when buffer fills.
00040   enum OnFull { KeepOldest, KeepNewest, Unbounded};
00041 
00042   /**
00043    * Construct with optional buffer size and full behavior.
00044    *
00045    * @param bound  - amount of data to store or reserve as buffer.
00046    * @param onFull - behavior of collector when bound is reached.
00047    *
00048    * OnFull == KeepOldest: The buffer is limited to the amount of data
00049    *                       specified by the bound parameter and only
00050    *                       the data collected first is retained.
00051    * OnFull == KeepNewest: The buffer is limited to the amount of data
00052    *                       specified by the bound parameter and only
00053    *                       the most recently collected data is
00054    *                       retained.
00055    * OnFull == Unbounded:  The buffer contains all collected data and
00056    *                       the bound parameter is used as an initial
00057    *                       reservation amount.
00058    *
00059    * Collection is either bounded or unbounded.  In the case of a
00060    * bounded collection, either the first data collected or the most
00061    * recent data collected is retained.  When an unbounded collection
00062    * is specified, then the bound parameter is used as a capacity hint
00063    * and that amount of data is reserved initially.
00064    */
00065   DataCollector(unsigned int bound = 0, OnFull onFull = KeepOldest);
00066 
00067   /// Allow the class to be extended.
00068   virtual ~DataCollector();
00069 
00070   /// Implement data collection.
00071   void collect(const DatumType& datum);
00072 
00073   /// Amount of data actually stored.
00074   unsigned int size() const;
00075 
00076 #ifndef OPENDDS_SAFETY_PROFILE
00077   /// Convenience operator for collecting data by inserting it into the
00078   /// collector.
00079   DataCollector<DatumType>& operator<<(DatumType datum);
00080 
00081   /// Implement insertion of collected data onto an ostream.
00082   std::ostream& insert(std::ostream& str) const;
00083 #endif //OPENDDS_SAFETY_PROFILE
00084 
00085 private:
00086   /// The collected data goes here.
00087   OPENDDS_VECTOR(DatumType) buffer_;
00088 
00089   /// Where to write the next datum collected.
00090   unsigned int writeAt_;
00091 
00092   /// Total or initial capacity of buffer.
00093   unsigned int bound_;
00094 
00095   /// Flag indicating that we have collected as much or more data than
00096   /// we can store.
00097   bool full_;
00098 
00099   /// Selector for behavior when buffer fills.
00100   OnFull onFull_;
00101 };
00102 
00103 #ifndef OPENDDS_SAFETY_PROFILE
00104 /// Insert collected data onto an ostream.
00105 template<typename DatumType>
00106 std::ostream& operator<<(
00107   std::ostream& str,
00108   const DataCollector<DatumType>& value);
00109 #endif //OPENDDS_SAFETY_PROFILE
00110 
00111 } // namespace DCPS
00112 } // namespace OpenDDS
00113 
00114 
00115 OPENDDS_END_VERSIONED_NAMESPACE_DECL
00116 
00117 #if defined (__ACE_INLINE__)
00118 #include "DataCollector_T.inl"
00119 #endif /* __ACE_INLINE__ */
00120 
00121 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00122 #include "DataCollector_T.cpp"
00123 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00124 
00125 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00126 #pragma implementation ("DataCollector_T.cpp")
00127 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00128 
00129 #include /**/ "ace/post.h"
00130 
00131 #endif /* DATA_COLLECTOR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1