00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 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 /* __ACE_INLINE__ */ 00014 00015 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00016 00017 namespace OpenDDS { 00018 namespace DCPS { 00019 00020 template<typename DatumType> 00021 DataCollector<DatumType>::~DataCollector() 00022 { 00023 } 00024 00025 template<typename DatumType> 00026 void 00027 DataCollector<DatumType>::collect(const DatumType& datum) 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 } 00049 00050 template<typename DatumType> 00051 unsigned int 00052 DataCollector<DatumType>::size() const 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 } 00060 00061 #ifndef OPENDDS_SAFETY_PROFILE 00062 template<typename DatumType> 00063 std::ostream& 00064 DataCollector<DatumType>::insert(std::ostream& str) const 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 } 00095 #endif //OPENDDS_SAFETY_PROFILE 00096 00097 } // namespace DCPS 00098 } // namespace OpenDDS 00099 00100 OPENDDS_END_VERSIONED_NAMESPACE_DECL