OpenDDS::DCPS::DataCollector< DatumType > Class Template Reference

Collect data in a buffer. More...

#include <DataCollector_T.h>

List of all members.

Public Types

enum  OnFull { KeepOldest, KeepNewest, Unbounded }
 

Selectors for behavior when buffer fills.

More...

Public Member Functions

 DataCollector (unsigned int bound=0, OnFull onFull=KeepOldest)
virtual ~DataCollector ()
 Allow the class to be extended.
void collect (const DatumType &datum)
 Implement data collection.
unsigned int size () const
 Amount of data actually stored.
DataCollector< DatumType > & operator<< (DatumType datum)
std::ostream & insert (std::ostream &str) const
 Implement insertion of collected data onto an ostream.

Private Member Functions

 OPENDDS_VECTOR (DatumType) buffer_
 The collected data goes here.

Private Attributes

unsigned int writeAt_
 Where to write the next datum collected.
unsigned int bound_
 Total or initial capacity of buffer.
bool full_
OnFull onFull_
 Selector for behavior when buffer fills.

Detailed Description

template<typename DatumType>
class OpenDDS::DCPS::DataCollector< DatumType >

Collect data in a buffer.

This class implements a rudimentary data collection mechanism. It is extendable to allow data to be collected as a feature of a more complex class.

Definition at line 37 of file DataCollector_T.h.


Member Enumeration Documentation

template<typename DatumType>
enum OpenDDS::DCPS::DataCollector::OnFull

Selectors for behavior when buffer fills.

Enumerator:
KeepOldest 
KeepNewest 
Unbounded 

Definition at line 40 of file DataCollector_T.h.


Constructor & Destructor Documentation

template<typename DatumType >
ACE_INLINE OpenDDS::DCPS::DataCollector< DatumType >::DataCollector ( unsigned int  bound = 0,
OnFull  onFull = KeepOldest 
) [inline]

Construct with optional buffer size and full behavior.

Parameters:
bound - amount of data to store or reserve as buffer.
onFull - behavior of collector when bound is reached.

OnFull == KeepOldest: The buffer is limited to the amount of data specified by the bound parameter and only the data collected first is retained. OnFull == KeepNewest: The buffer is limited to the amount of data specified by the bound parameter and only the most recently collected data is retained. OnFull == Unbounded: The buffer contains all collected data and the bound parameter is used as an initial reservation amount.

Collection is either bounded or unbounded. In the case of a bounded collection, either the first data collected or the most recent data collected is retained. When an unbounded collection is specified, then the bound parameter is used as a capacity hint and that amount of data is reserved initially.

Definition at line 26 of file DataCollector_T.inl.

References OpenDDS::DCPS::DataCollector< DatumType >::onFull_, and OpenDDS::DCPS::DataCollector< DatumType >::Unbounded.

00027   : buffer_(bound),
00028     writeAt_(0),
00029     bound_(bound),
00030     full_(false),
00031     onFull_(onFull)
00032 {
00033   if (this->onFull_ == Unbounded) {
00034     this->buffer_.clear();
00035   }
00036 }

template<typename DatumType >
OpenDDS::DCPS::DataCollector< DatumType >::~DataCollector (  )  [inline, virtual]

Allow the class to be extended.

Definition at line 21 of file DataCollector_T.cpp.

00022 {
00023 }


Member Function Documentation

template<typename DatumType>
void OpenDDS::DCPS::DataCollector< DatumType >::collect ( const DatumType &  datum  )  [inline]

Implement data collection.

Definition at line 27 of file DataCollector_T.cpp.

References OpenDDS::DCPS::DataCollector< DatumType >::bound_, OpenDDS::DCPS::DataCollector< DatumType >::full_, OpenDDS::DCPS::DataCollector< DatumType >::KeepNewest, OpenDDS::DCPS::DataCollector< DatumType >::onFull_, OpenDDS::DCPS::DataCollector< DatumType >::Unbounded, and OpenDDS::DCPS::DataCollector< DatumType >::writeAt_.

Referenced by OpenDDS::DCPS::DataCollector< DatumType >::operator<<().

00028 {
00029   if (this->onFull_ == Unbounded) {
00030     this->buffer_.push_back(datum);
00031 
00032   } else {
00033     // writeAt == bound only when we either have no buffer (bound == 0) or
00034     // when we are full with no wrapping (writeAt == bound)
00035     if (this->writeAt_ != this->bound_) {
00036       this->buffer_[ this->writeAt_++] = datum;
00037 
00038       // This datum filled the buffer.
00039       if (this->writeAt_ == this->bound_) {
00040         this->full_  = true;
00041 
00042         if (this->onFull_ == KeepNewest) {
00043           this->writeAt_ = 0;
00044         }
00045       }
00046     }
00047   }
00048 }

Here is the caller graph for this function:

template<typename DatumType >
std::ostream & OpenDDS::DCPS::DataCollector< DatumType >::insert ( std::ostream &  str  )  const [inline]

Implement insertion of collected data onto an ostream.

Definition at line 64 of file DataCollector_T.cpp.

References OpenDDS::DCPS::DataCollector< DatumType >::bound_, OpenDDS::DCPS::DataCollector< DatumType >::full_, and OpenDDS::DCPS::DataCollector< DatumType >::writeAt_.

Referenced by OpenDDS::DCPS::operator<<().

00065 {
00066   std::ofstream initStrState;
00067   initStrState.copyfmt(str);
00068 
00069   str.precision(5);
00070   str << std::scientific;
00071 
00072   // Oldest data first.
00073   if (this->full_) {
00074     for (unsigned int index = this->writeAt_; index < this->bound_; ++index) {
00075       str << this->buffer_[ index] << std::endl;
00076     }
00077   }
00078 
00079   // Bounded case.
00080   int end = this->writeAt_;
00081 
00082   if (end == 0) {
00083     // Unbounded case.
00084     end = static_cast<int>(this->buffer_.size());
00085   }
00086 
00087   // Newest data last.
00088   for (int index = 0; index < end; ++index) {
00089     str << this->buffer_[ index] << std::endl;
00090   }
00091 
00092   str.copyfmt(initStrState);
00093   return str;
00094 }

Here is the caller graph for this function:

template<typename DatumType>
OpenDDS::DCPS::DataCollector< DatumType >::OPENDDS_VECTOR ( DatumType   )  [private]

The collected data goes here.

template<typename DatumType>
ACE_INLINE DataCollector< DatumType > & OpenDDS::DCPS::DataCollector< DatumType >::operator<< ( DatumType  datum  )  [inline]

Convenience operator for collecting data by inserting it into the collector.

Definition at line 42 of file DataCollector_T.inl.

References OpenDDS::DCPS::DataCollector< DatumType >::collect().

00043 {
00044   this->collect(datum);
00045   return *this;
00046 }

Here is the call graph for this function:

template<typename DatumType >
unsigned int OpenDDS::DCPS::DataCollector< DatumType >::size ( void   )  const [inline]

Amount of data actually stored.

Definition at line 52 of file DataCollector_T.cpp.

References OpenDDS::DCPS::DataCollector< DatumType >::bound_, OpenDDS::DCPS::DataCollector< DatumType >::full_, OpenDDS::DCPS::DataCollector< DatumType >::onFull_, OpenDDS::DCPS::DataCollector< DatumType >::Unbounded, and OpenDDS::DCPS::DataCollector< DatumType >::writeAt_.

Referenced by OpenDDS::DCPS::WriterStats::raw_data().

00053 {
00054   if (this->onFull_ == Unbounded) return static_cast<unsigned int>(this->buffer_.size());
00055 
00056   else if (this->full_)           return this->bound_;
00057 
00058   else                            return this->writeAt_;
00059 }

Here is the caller graph for this function:


Member Data Documentation

template<typename DatumType>
unsigned int OpenDDS::DCPS::DataCollector< DatumType >::bound_ [private]
template<typename DatumType>
bool OpenDDS::DCPS::DataCollector< DatumType >::full_ [private]

Flag indicating that we have collected as much or more data than we can store.

Definition at line 97 of file DataCollector_T.h.

Referenced by OpenDDS::DCPS::DataCollector< DatumType >::collect(), OpenDDS::DCPS::DataCollector< DatumType >::insert(), and OpenDDS::DCPS::DataCollector< DatumType >::size().

template<typename DatumType>
OnFull OpenDDS::DCPS::DataCollector< DatumType >::onFull_ [private]
template<typename DatumType>
unsigned int OpenDDS::DCPS::DataCollector< DatumType >::writeAt_ [private]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1