IHistogram.hpp
1 #ifndef DM_IHISTROGRAM_HPP_INCLUDED
2 #define DM_IHISTROGRAM_HPP_INCLUDED
3 
4 #ifdef _MSC_VER
5  #pragma once
6 #endif
7 
8 #include "DM/config.hpp"
9 #include "DM/Handle.hpp"
10 #include "DM/ObjectBase.hpp"
11 #include "DM/Iterator.hpp"
12 #include "DM/ColumnTypes.hpp"
13 
14 DM_NAMESPACE_BEGIN
15 
16 /// \brief Class for representing a histogram
17 ///
18 /// Although all DM column types are internally supported, the interface provides access to a reduced list types only (to keep the interface as simple as possible).
19 /// The corresponding conversion are implicitly performed when accessing the values.
20 class DM_API IHistogram : public ObjectBase
21 {
22 public:
23  /// \brief Histogram entry
24  template<typename T>
25  struct IEntry : public ObjectBase {
26  virtual ~IEntry() {};
27 
28  virtual T value() const = 0; ///< value
29  virtual int64_t count() const = 0; ///< absolute frequency
30  };
31 
32  // Iterator typedefs ============================================================================
33  typedef ConstIterator< IEntry<int64_t> > const_iterator_integral; ///< integral histogram iterator
34  typedef ConstIterator< IEntry<double> > const_iterator_real; ///< real histogram iterator
35  typedef ConstIterator< IEntry<bool> > const_iterator_bool; ///< boolean histogram iterator
36  typedef ConstIterator< IEntry<const char*> > const_iterator_string; ///< string histogram iterator
37 
38  virtual ~IHistogram() {}
39 
40  virtual ColumnType::Type type() const = 0; ///< internal type of the histogram
41  virtual bool isIntegral() const = 0; ///< is an integral data type
42  virtual bool isReal() const = 0; ///< is a real (double or float) data type
43  virtual bool isBool() const = 0; ///< is a boolean type
44  virtual bool isString() const = 0; ///< is a string data type
45 
46  virtual int64_t size() const = 0; ///< number of histogram value (number of distinct data values)
47 
48  virtual int64_t sizeData() const = 0; ///< number of data values that were used to build the histogram
49  virtual int64_t sizeNull() const = 0; ///< number of null values occurred in the corresponding data set
50 
51  virtual bool complete() const = 0; ///< flag if histogram covers the full data set
52 
53  // Iterator function ============================================================================
54  virtual const_iterator_integral beginIntegral() const = 0; ///< only allowed if isIntegral() == true
55  virtual const_iterator_integral endIntegral() const = 0;
56 
57  virtual const_iterator_real beginReal() const = 0;
58  virtual const_iterator_real endReal() const = 0;
59 
60  virtual const_iterator_bool beginBool() const = 0;
61  virtual const_iterator_bool endBool() const = 0;
62 
63  virtual const_iterator_string beginString() const = 0;
64  virtual const_iterator_string endString() const = 0;
65 };
66 
67 typedef Handle< IHistogram > HistogramHandle;
68 
69 
70 DM_NAMESPACE_END
71 
72 #endif //DM_IHISTROGRAM_HPP_INCLUDED