LCOV - code coverage report
Current view: top level - DCPS - DataCollector_T.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 32 0.0 %
Date: 2023-04-30 01:32:43 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *
       4             :  * Distributed under the OpenDDS License.
       5             :  * See: http://www.opendds.org/license.html
       6             :  */
       7             : 
       8             : #include "DataCollector_T.h"
       9             : #include "SafetyProfileStreams.h"
      10             : 
      11             : #if !defined (__ACE_INLINE__)
      12             : #include "DataCollector_T.inl"
      13             : #endif /* __ACE_INLINE__ */
      14             : 
      15             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      16             : 
      17             : namespace OpenDDS {
      18             : namespace DCPS {
      19             : 
      20             : template<typename DatumType>
      21           0 : DataCollector<DatumType>::~DataCollector()
      22             : {
      23           0 : }
      24             : 
      25             : template<typename DatumType>
      26             : void
      27           0 : DataCollector<DatumType>::collect(const DatumType& datum)
      28             : {
      29           0 :   if (this->onFull_ == Unbounded) {
      30           0 :     this->buffer_.push_back(datum);
      31             : 
      32             :   } else {
      33             :     // writeAt == bound only when we either have no buffer (bound == 0) or
      34             :     // when we are full with no wrapping (writeAt == bound)
      35           0 :     if (this->writeAt_ != this->bound_) {
      36           0 :       this->buffer_[ this->writeAt_++] = datum;
      37             : 
      38             :       // This datum filled the buffer.
      39           0 :       if (this->writeAt_ == this->bound_) {
      40           0 :         this->full_  = true;
      41             : 
      42           0 :         if (this->onFull_ == KeepNewest) {
      43           0 :           this->writeAt_ = 0;
      44             :         }
      45             :       }
      46             :     }
      47             :   }
      48           0 : }
      49             : 
      50             : template<typename DatumType>
      51             : unsigned int
      52           0 : DataCollector<DatumType>::size() const
      53             : {
      54           0 :   if (this->onFull_ == Unbounded) return static_cast<unsigned int>(this->buffer_.size());
      55             : 
      56           0 :   else if (this->full_)           return this->bound_;
      57             : 
      58           0 :   else                            return this->writeAt_;
      59             : }
      60             : 
      61             : #ifndef OPENDDS_SAFETY_PROFILE
      62             : template<typename DatumType>
      63             : std::ostream&
      64           0 : DataCollector<DatumType>::insert(std::ostream& str) const
      65             : {
      66           0 :   std::ofstream initStrState;
      67           0 :   initStrState.copyfmt(str);
      68             : 
      69           0 :   str.precision(5);
      70           0 :   str << std::scientific;
      71             : 
      72             :   // Oldest data first.
      73           0 :   if (this->full_) {
      74           0 :     for (unsigned int index = this->writeAt_; index < this->bound_; ++index) {
      75           0 :       str << this->buffer_[ index] << std::endl;
      76             :     }
      77             :   }
      78             : 
      79             :   // Bounded case.
      80           0 :   int end = this->writeAt_;
      81             : 
      82           0 :   if (end == 0) {
      83             :     // Unbounded case.
      84           0 :     end = static_cast<int>(this->buffer_.size());
      85             :   }
      86             : 
      87             :   // Newest data last.
      88           0 :   for (int index = 0; index < end; ++index) {
      89           0 :     str << this->buffer_[ index] << std::endl;
      90             :   }
      91             : 
      92           0 :   str.copyfmt(initStrState);
      93           0 :   return str;
      94           0 : }
      95             : #endif //OPENDDS_SAFETY_PROFILE
      96             : 
      97             : } // namespace DCPS
      98             : } // namespace OpenDDS
      99             : 
     100             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16