#include <DataCollector_T.h>
Public Types | |
KeepOldest | |
KeepNewest | |
Unbounded | |
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. |
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 36 of file DataCollector_T.h.
enum OpenDDS::DCPS::DataCollector::OnFull |
Selectors for behavior when buffer fills.
Definition at line 39 of file DataCollector_T.h.
00039 { KeepOldest, KeepNewest, Unbounded};
ACE_INLINE OpenDDS::DCPS::DataCollector< DatumType >::DataCollector | ( | unsigned int | bound = 0 , |
|
OnFull | onFull = KeepOldest | |||
) |
Construct with optional buffer size and full behavior.
bound | - amount of data to store or reserve as buffer. | |
onFull | - behavior of collector when bound is reached. |
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 25 of file DataCollector_T.inl.
References OpenDDS::DCPS::DataCollector< DatumType >::Unbounded.
00026 : buffer_(bound), 00027 writeAt_(0), 00028 bound_(bound), 00029 full_(false), 00030 onFull_(onFull) 00031 { 00032 if (this->onFull_ == Unbounded) { 00033 this->buffer_.clear(); 00034 } 00035 }
OpenDDS::DCPS::DataCollector< DatumType >::~DataCollector | ( | ) | [virtual] |
void OpenDDS::DCPS::DataCollector< DatumType >::collect | ( | const DatumType & | datum | ) |
Implement data collection.
Definition at line 26 of file DataCollector_T.cpp.
References OpenDDS::DCPS::DataCollector< DatumType >::full_, OpenDDS::DCPS::DataCollector< DatumType >::KeepNewest, OpenDDS::DCPS::DataCollector< DatumType >::Unbounded, and OpenDDS::DCPS::DataCollector< DatumType >::writeAt_.
Referenced by OpenDDS::DCPS::DataCollector< DatumType >::operator<<().
00027 { 00028 if (this->onFull_ == Unbounded) { 00029 this->buffer_.push_back(datum); 00030 00031 } else { 00032 // writeAt == bound only when we either have no buffer (bound == 0) or 00033 // when we are full with no wrapping (writeAt == bound) 00034 if (this->writeAt_ != this->bound_) { 00035 this->buffer_[ this->writeAt_++] = datum; 00036 00037 // This datum filled the buffer. 00038 if (this->writeAt_ == this->bound_) { 00039 this->full_ = true; 00040 00041 if (this->onFull_ == KeepNewest) { 00042 this->writeAt_ = 0; 00043 } 00044 } 00045 } 00046 } 00047 }
std::ostream & OpenDDS::DCPS::DataCollector< DatumType >::insert | ( | std::ostream & | str | ) | const |
Implement insertion of collected data onto an ostream.
Definition at line 63 of file DataCollector_T.cpp.
References OpenDDS::DCPS::DataCollector< DatumType >::bound_, and OpenDDS::DCPS::DataCollector< DatumType >::writeAt_.
Referenced by OpenDDS::DCPS::operator<<().
00064 { 00065 std::ofstream initStrState; 00066 initStrState.copyfmt(str); 00067 00068 str.precision(5); 00069 str << std::scientific; 00070 00071 // Oldest data first. 00072 if (this->full_) { 00073 for (unsigned int index = this->writeAt_; index < this->bound_; ++index) { 00074 str << this->buffer_[ index] << std::endl; 00075 } 00076 } 00077 00078 // Bounded case. 00079 int end = this->writeAt_; 00080 00081 if (end == 0) { 00082 // Unbounded case. 00083 end = static_cast<int>(this->buffer_.size()); 00084 } 00085 00086 // Newest data last. 00087 for (int index = 0; index < end; ++index) { 00088 str << this->buffer_[ index] << std::endl; 00089 } 00090 00091 str.copyfmt(initStrState); 00092 return str; 00093 }
OpenDDS::DCPS::DataCollector< DatumType >::OPENDDS_VECTOR | ( | DatumType | ) | [private] |
The collected data goes here.
ACE_INLINE DataCollector< DatumType > & OpenDDS::DCPS::DataCollector< DatumType >::operator<< | ( | DatumType | datum | ) |
Convenience operator for collecting data by inserting it into the collector.
Definition at line 41 of file DataCollector_T.inl.
References OpenDDS::DCPS::DataCollector< DatumType >::collect().
00042 { 00043 this->collect(datum); 00044 return *this; 00045 }
unsigned int OpenDDS::DCPS::DataCollector< DatumType >::size | ( | ) | const |
Amount of data actually stored.
Definition at line 51 of file DataCollector_T.cpp.
References OpenDDS::DCPS::DataCollector< DatumType >::bound_, OpenDDS::DCPS::DataCollector< DatumType >::Unbounded, and OpenDDS::DCPS::DataCollector< DatumType >::writeAt_.
Referenced by OpenDDS::DCPS::WriterStats::raw_data().
00052 { 00053 if (this->onFull_ == Unbounded) return static_cast<unsigned int>(this->buffer_.size()); 00054 00055 else if (this->full_) return this->bound_; 00056 00057 else return this->writeAt_; 00058 }
unsigned int OpenDDS::DCPS::DataCollector< DatumType >::bound_ [private] |
Total or initial capacity of buffer.
Definition at line 92 of file DataCollector_T.h.
Referenced by OpenDDS::DCPS::DataCollector< DatumType >::insert(), and OpenDDS::DCPS::DataCollector< DatumType >::size().
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 96 of file DataCollector_T.h.
Referenced by OpenDDS::DCPS::DataCollector< DatumType >::collect().
OnFull OpenDDS::DCPS::DataCollector< DatumType >::onFull_ [private] |
unsigned int OpenDDS::DCPS::DataCollector< DatumType >::writeAt_ [private] |
Where to write the next datum collected.
Definition at line 89 of file DataCollector_T.h.
Referenced by OpenDDS::DCPS::DataCollector< DatumType >::collect(), OpenDDS::DCPS::DataCollector< DatumType >::insert(), and OpenDDS::DCPS::DataCollector< DatumType >::size().