00001
00002
00003
00004
00005
00006
00007
00008 #include "DataCollector_T.h"
00009 #include "dds/DCPS/SafetyProfileStreams.h"
00010
00011 #if !defined (__ACE_INLINE__)
00012 #include "DataCollector_T.inl"
00013 #endif
00014
00015
00016 namespace OpenDDS {
00017 namespace DCPS {
00018
00019 template<typename DatumType>
00020 DataCollector<DatumType>::~DataCollector()
00021 {
00022 }
00023
00024 template<typename DatumType>
00025 void
00026 DataCollector<DatumType>::collect(const DatumType& datum)
00027 {
00028 if (this->onFull_ == Unbounded) {
00029 this->buffer_.push_back(datum);
00030
00031 } else {
00032
00033
00034 if (this->writeAt_ != this->bound_) {
00035 this->buffer_[ this->writeAt_++] = datum;
00036
00037
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 }
00048
00049 template<typename DatumType>
00050 unsigned int
00051 DataCollector<DatumType>::size() const
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 }
00059
00060 #ifndef OPENDDS_SAFETY_PROFILE
00061 template<typename DatumType>
00062 std::ostream&
00063 DataCollector<DatumType>::insert(std::ostream& str) const
00064 {
00065 std::ofstream initStrState;
00066 initStrState.copyfmt(str);
00067
00068 str.precision(5);
00069 str << std::scientific;
00070
00071
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
00079 int end = this->writeAt_;
00080
00081 if (end == 0) {
00082
00083 end = static_cast<int>(this->buffer_.size());
00084 }
00085
00086
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 }
00094 #endif //OPENDDS_SAFETY_PROFILE
00095
00096 }
00097 }