OMNeT++ Simulation Library  5.6.1
cstatistic.h
1 //==========================================================================
2 // CSTATISTIC.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_CSTATISTIC_H
17 #define __OMNETPP_CSTATISTIC_H
18 
19 #include "crandom.h"
20 #include "simtime.h"
21 #include "opp_string.h"
22 
23 namespace omnetpp {
24 
34 class SIM_API cStatistic : public cRandom
35 {
36  private:
37  void copy(const cStatistic& other);
38 
39  protected:
40  // internal: utility function for implementing loadFromFile() functions
41  void freadvarsf (FILE *f, const char *fmt, ...) _OPP_GNU_ATTRIBUTE((format(scanf, 3, 4)));
42  // internal: for collecting the attributes to record into the scalar file
43  virtual void getAttributesToRecord(opp_string_map& attributes) {}
44 
45  public:
48 
52  cStatistic(const cStatistic& r);
53 
57  explicit cStatistic(const char *name=nullptr);
58 
62  virtual ~cStatistic();
63 
68  cStatistic& operator=(const cStatistic& res);
70 
73 
74  /* Note: No dup() because this is an abstract class! */
75 
81  virtual void parsimPack(cCommBuffer *buffer) const override;
82 
88  virtual void parsimUnpack(cCommBuffer *buffer) override;
90 
96  virtual bool isWeighted() const = 0;
97 
101  virtual void collect(double value) = 0;
102 
106  virtual void collect(SimTime value) {collect(value.dbl());}
107 
111  virtual void collectWeighted(double value, double weight);
112 
116  virtual void collectWeighted(SimTime value, double weight) {collectWeighted(value.dbl(), weight);}
117 
121  virtual void collectWeighted(double value, SimTime weight) {collectWeighted(value, weight.dbl());}
122 
126  virtual void collectWeighted(SimTime value, SimTime weight) {collectWeighted(value.dbl(), weight.dbl());}
127 
133  virtual void merge(const cStatistic *other) = 0;
134 
139  virtual void clear() = 0;
141 
144 
148  virtual int64_t getCount() const = 0;
149 
155  virtual double getSum() const = 0;
156 
162  virtual double getSqrSum() const = 0;
163 
167  virtual double getMin() const = 0;
168 
172  virtual double getMax() const = 0;
173 
177  virtual double getMean() const = 0;
178 
182  virtual double getStddev() const = 0;
183 
187  virtual double getVariance() const = 0;
189 
195  virtual double getSumWeights() const = 0;
196 
200  virtual double getWeightedSum() const = 0;
201 
205  virtual double getSqrSumWeights() const = 0;
206 
210  virtual double getWeightedSqrSum() const = 0;
212 
215 
220  virtual void saveToFile(FILE *) const = 0;
221 
226  virtual void loadFromFile(FILE *) = 0;
227 
238  virtual void record() {recordAs(nullptr, nullptr);}
239 
249  virtual void recordWithUnit(const char *unit) {recordAs(nullptr, unit);}
250 
259  virtual void recordAs(const char *name, const char *unit=nullptr);
261 
267  _OPPDEPRECATED virtual double getWeights() const final {return getSumWeights();}
268 
272  _OPPDEPRECATED virtual void collect2(double value, double weight) final {collectWeighted(value, weight);}
273 
277  _OPPDEPRECATED virtual void collect2(SimTime value, double weight) final {collectWeighted(value, weight);}
278 
282  _OPPDEPRECATED virtual void collect2(double value, SimTime weight) final {collectWeighted(value, weight);}
283 
287  _OPPDEPRECATED virtual void collect2(SimTime value, SimTime weight) final {collectWeighted(value, weight);}
288 
292  _OPPDEPRECATED virtual double random() const final {return draw();}
293 
297  _OPPDEPRECATED virtual void clearResult() final {clear();}
299 };
300 
301 } // namespace omnetpp
302 
303 #endif
304 
virtual _OPPDEPRECATED double random() const final
Definition: cstatistic.h:292
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
virtual void collectWeighted(SimTime value, SimTime weight)
Definition: cstatistic.h:126
virtual void collect(SimTime value)
Definition: cstatistic.h:106
virtual _OPPDEPRECATED double getWeights() const final
Definition: cstatistic.h:267
virtual void record()
Definition: cstatistic.h:238
virtual _OPPDEPRECATED void collect2(SimTime value, double weight) final
Definition: cstatistic.h:277
virtual void collectWeighted(double value, SimTime weight)
Definition: cstatistic.h:121
double dbl() const
Definition: simtime.h:301
virtual void collectWeighted(SimTime value, double weight)
Definition: cstatistic.h:116
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
virtual _OPPDEPRECATED void collect2(double value, double weight) final
Definition: cstatistic.h:272
Definition: cabstracthistogram.h:21
Abstract interface for random variate generator classes.
Definition: crandom.h:31
virtual void recordWithUnit(const char *unit)
Definition: cstatistic.h:249
virtual _OPPDEPRECATED void collect2(SimTime value, SimTime weight) final
Definition: cstatistic.h:287
virtual _OPPDEPRECATED void collect2(double value, SimTime weight) final
Definition: cstatistic.h:282
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
virtual _OPPDEPRECATED void clearResult() final
Definition: cstatistic.h:297