OMNeT++ Simulation Library  5.6.1
clegacyhistogram.h
1 //==========================================================================
2 // CLEGACYHISTOGRAM.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CLEGACYHISTOGRAM_H
17 #define __OMNETPP_CLEGACYHISTOGRAM_H
18 
19 #include <cmath>
20 #include "cprecolldensityest.h"
21 
22 #if defined(__clang__) || defined(__GNUC__)
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
25 #endif
26 
27 namespace omnetpp {
28 
37 class _OPPDEPRECATED SIM_API cLegacyHistogramBase : public cPrecollectionBasedDensityEst
38 {
39  protected:
40  int numCells; // number of histogram cells or bins
41  double *cellv; // counts, type double because of weighted statistics
42 
43  private:
44  void copy(const cLegacyHistogramBase& other);
45 
46  protected:
47  // abstract method in cPrecollectionBasedDensityEst
48  virtual void doMergeBinValues(const cPrecollectionBasedDensityEst *other) override;
49 
50  public:
53 
58 
62  cLegacyHistogramBase(const char *name, int numcells, bool weighted=false);
63 
67  virtual ~cLegacyHistogramBase();
68 
72  cLegacyHistogramBase& operator=(const cLegacyHistogramBase& res);
74 
77 
78  /* No dup() because this is an abstract class. */
79 
85  virtual void parsimPack(cCommBuffer *buffer) const override;
86 
92  virtual void parsimUnpack(cCommBuffer *buffer) override;
94 
97 
101  virtual void clear() override;
102 
107  virtual void setUpBins() override;
108 
112  virtual int getNumBins() const override;
113 
117  virtual void saveToFile(FILE *) const override;
118 
122  virtual void loadFromFile(FILE *) override;
124 
131  virtual void setNumCells(int numcells);
133 };
134 
135 
194 class _OPPDEPRECATED SIM_API cLegacyHistogram : public cLegacyHistogramBase
195 {
196  public:
197  enum Mode {MODE_AUTO, MODE_INTEGERS, MODE_DOUBLES};
198  typedef Mode HistogramMode;
199 
200  protected:
201  Mode mode;
202  double cellSize; // cell (bin) size; <=0 if unset
203 
204  private:
205  void copy(const cLegacyHistogram& other);
206 
207  protected:
208  virtual void setupRangeInteger();
209  virtual void setupRangeDouble();
210  virtual void getAttributesToRecord(opp_string_map& attributes) override;
211 
212  public:
215 
220 
224  explicit cLegacyHistogram(const char *name=nullptr, int numcells=-1, Mode mode=MODE_AUTO, bool weighted=false);
225 
229  cLegacyHistogram& operator=(const cLegacyHistogram& res);
231 
234 
235  /* No dup() because this is an abstract class. */
236 
242  virtual void parsimPack(cCommBuffer *buffer) const override;
243 
249  virtual void parsimUnpack(cCommBuffer *buffer) override;
251 
252  protected:
257  virtual void collectIntoHistogram(double value) override;
258 
263  virtual void collectWeightedIntoHistogram(double value, double weight) override;
264 
269  virtual void setupRange() override;
270 
271  public:
274 
278  virtual double getBinEdge(int k) const override;
279 
283  virtual double getBinValue(int k) const override;
284 
288  virtual double getPDF(double x) const override;
289 
293  virtual double getCDF(double x) const override;
294 
302  virtual double draw() const override;
303 
307  virtual void saveToFile(FILE *) const override;
308 
312  virtual void loadFromFile(FILE *) override;
314 
321  virtual void setMode(Mode mode);
322 
327  virtual Mode getMode() const {return mode;}
328 
333  virtual void setCellSize(double d);
334 
339  virtual double getCellSize() const {return cellSize;}
341 
342 };
343 
344 
355 class _OPPDEPRECATED SIM_API cLongHistogram : public cLegacyHistogram
356 {
357  private:
358  void copy(const cLongHistogram& other) {}
359 
360  public:
367 
371  explicit cLongHistogram(const char *name=nullptr, int numcells=-1, bool weighted=false) :
372  cLegacyHistogram(name, numcells, MODE_INTEGERS, weighted) {}
373 
377  virtual ~cLongHistogram() {}
378 
382  cLongHistogram& operator=(const cLongHistogram& other);
384 
387 
392  virtual cLongHistogram *dup() const override {return new cLongHistogram(*this);}
394 
395  public:
398 
403  virtual void collect(double value) override {cLegacyHistogram::collect(std::floor(value));}
404 
408  virtual void collect(SimTime value) override {collect(value.dbl());}
409 };
410 
411 
422 class _OPPDEPRECATED SIM_API cDoubleHistogram : public cLegacyHistogram
423 {
424  private:
425  void copy(const cDoubleHistogram& other) {}
426 
427  public:
430 
435 
439  explicit cDoubleHistogram(const char *name=nullptr, int numcells=-1, bool weighted=false) :
440  cLegacyHistogram(name, numcells, MODE_DOUBLES, weighted) {}
441 
445  virtual ~cDoubleHistogram() {}
446 
450  cDoubleHistogram& operator=(const cDoubleHistogram& other);
452 
455 
460  virtual cDoubleHistogram *dup() const override {return new cDoubleHistogram(*this);}
462 };
463 
464 } // namespace omnetpp
465 
466 #if defined(__clang__) || defined(__GNUC__)
467 #pragma GCC diagnostic pop
468 #endif
469 
470 #endif
471 
virtual void collect(SimTime value) override
Definition: clegacyhistogram.h:408
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
virtual void collect(double value) override
Definition: clegacyhistogram.h:403
Implements an equidistant histogram.
Definition: clegacyhistogram.h:194
Base class for histogram classes. It adds a vector of counters to cPrecollectionBasedDensityEst.
Definition: clegacyhistogram.h:37
virtual void collect(double value) override
virtual double getCellSize() const
Definition: clegacyhistogram.h:339
Equidistant histogram for integers.
Definition: clegacyhistogram.h:355
Equidistant histogram for doubles.
Definition: clegacyhistogram.h:422
double dbl() const
Definition: simtime.h:301
virtual Mode getMode() const
Definition: clegacyhistogram.h:327
cLegacyHistogramBase(const cLegacyHistogramBase &r)
Definition: clegacyhistogram.h:57
cDoubleHistogram(const cDoubleHistogram &r)
Definition: clegacyhistogram.h:434
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:200
cDoubleHistogram(const char *name=nullptr, int numcells=-1, bool weighted=false)
Definition: clegacyhistogram.h:439
cLongHistogram(const char *name=nullptr, int numcells=-1, bool weighted=false)
Definition: clegacyhistogram.h:371
virtual ~cLongHistogram()
Definition: clegacyhistogram.h:377
cLongHistogram(const cLongHistogram &r)
Definition: clegacyhistogram.h:366
Definition: cabstracthistogram.h:21
virtual cDoubleHistogram * dup() const override
Definition: clegacyhistogram.h:460
virtual ~cDoubleHistogram()
Definition: clegacyhistogram.h:445
Base class for histogram-like density estimation classes.
Definition: cprecolldensityest.h:55
cLegacyHistogram(const cLegacyHistogram &r)
Definition: clegacyhistogram.h:219
virtual cLongHistogram * dup() const override
Definition: clegacyhistogram.h:392