OpenDDS  Snapshot(2023/04/28-20:55)
DataCollector_T.h
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #ifndef OPENDDS_DCPS_DATACOLLECTOR_T_H
7 #define OPENDDS_DCPS_DATACOLLECTOR_T_H
8 
9 #include <ace/config-macros.h>
10 #ifndef ACE_LACKS_PRAGMA_ONCE
11 # pragma once
12 #endif
13 
14 #include "PoolAllocator.h"
15 #include "SafetyProfileStreams.h"
16 
18 
19 namespace OpenDDS {
20 namespace DCPS {
21 
22 /**
23  * @class DataCollector<DatumType>
24  *
25  * @brief Collect data in a buffer.
26  *
27  * This class implements a rudimentary data collection mechanism. It is
28  * extendable to allow data to be collected as a feature of a more
29  * complex class.
30  */
31 template<typename DatumType>
33 public:
34  /// Selectors for behavior when buffer fills.
36 
37  /**
38  * Construct with optional buffer size and full behavior.
39  *
40  * @param bound - amount of data to store or reserve as buffer.
41  * @param onFull - behavior of collector when bound is reached.
42  *
43  * OnFull == KeepOldest: The buffer is limited to the amount of data
44  * specified by the bound parameter and only
45  * the data collected first is retained.
46  * OnFull == KeepNewest: The buffer is limited to the amount of data
47  * specified by the bound parameter and only
48  * the most recently collected data is
49  * retained.
50  * OnFull == Unbounded: The buffer contains all collected data and
51  * the bound parameter is used as an initial
52  * reservation amount.
53  *
54  * Collection is either bounded or unbounded. In the case of a
55  * bounded collection, either the first data collected or the most
56  * recent data collected is retained. When an unbounded collection
57  * is specified, then the bound parameter is used as a capacity hint
58  * and that amount of data is reserved initially.
59  */
60  DataCollector(unsigned int bound = 0, OnFull onFull = KeepOldest);
61 
62  /// Allow the class to be extended.
63  virtual ~DataCollector();
64 
65  /// Implement data collection.
66  void collect(const DatumType& datum);
67 
68  /// Amount of data actually stored.
69  unsigned int size() const;
70 
71 #ifndef OPENDDS_SAFETY_PROFILE
72  /// Convenience operator for collecting data by inserting it into the
73  /// collector.
74  DataCollector<DatumType>& operator<<(DatumType datum);
75 
76  /// Implement insertion of collected data onto an ostream.
77  std::ostream& insert(std::ostream& str) const;
78 #endif //OPENDDS_SAFETY_PROFILE
79 
80 private:
81  /// The collected data goes here.
82  OPENDDS_VECTOR(DatumType) buffer_;
83 
84  /// Where to write the next datum collected.
85  unsigned int writeAt_;
86 
87  /// Total or initial capacity of buffer.
88  unsigned int bound_;
89 
90  /// Flag indicating that we have collected as much or more data than
91  /// we can store.
92  bool full_;
93 
94  /// Selector for behavior when buffer fills.
96 };
97 
98 #ifndef OPENDDS_SAFETY_PROFILE
99 /// Insert collected data onto an ostream.
100 template<typename DatumType>
101 std::ostream& operator<<(
102  std::ostream& str,
104 #endif //OPENDDS_SAFETY_PROFILE
105 
106 } // namespace DCPS
107 } // namespace OpenDDS
108 
109 
111 
112 #if defined (__ACE_INLINE__)
113 #include "DataCollector_T.inl"
114 #endif /* __ACE_INLINE__ */
115 
116 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
117 #include "DataCollector_T.cpp"
118 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
119 
120 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
121 #pragma implementation ("DataCollector_T.cpp")
122 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
123 
124 #endif /* DATA_COLLECTOR_H */
unsigned int size() const
Amount of data actually stored.
const LogLevel::Value value
Definition: debug.cpp:61
OPENDDS_VECTOR(DatumType) buffer_
The collected data goes here.
DataCollector< DatumType > & operator<<(DatumType datum)
OnFull onFull_
Selector for behavior when buffer fills.
unsigned int writeAt_
Where to write the next datum collected.
void collect(const DatumType &datum)
Implement data collection.
OnFull
Selectors for behavior when buffer fills.
virtual ~DataCollector()
Allow the class to be extended.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
unsigned int bound_
Total or initial capacity of buffer.
Collect data in a buffer.
DataCollector(unsigned int bound=0, OnFull onFull=KeepOldest)
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
std::ostream & insert(std::ostream &str) const
Implement insertion of collected data onto an ostream.