OMNeT++ API 6.1
Discrete Event Simulation Library
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  _OPP_GNU_ATTRIBUTE(format(scanf, 3, 4))
42  void freadvarsf (FILE *f, const char *fmt, ...);
43  // internal: for collecting the attributes to record into the scalar file
44  virtual void getAttributesToRecord(opp_string_map& attributes) {}
45 
46  public:
49 
53  cStatistic(const cStatistic& r);
54 
58  explicit cStatistic(const char *name=nullptr);
59 
63  virtual ~cStatistic() {}
64 
69  cStatistic& operator=(const cStatistic& res);
71 
74 
75  /* Note: No dup() because this is an abstract class! */
76 
82  virtual void parsimPack(cCommBuffer *buffer) const override;
83 
89  virtual void parsimUnpack(cCommBuffer *buffer) override;
91 
97  virtual bool isWeighted() const = 0;
98 
102  virtual void collect(double value) = 0;
103 
107  virtual void collect(SimTime value) {collect(value.dbl());}
108 
112  virtual void collectWeighted(double value, double weight);
113 
117  virtual void collectWeighted(SimTime value, double weight) {collectWeighted(value.dbl(), weight);}
118 
122  virtual void collectWeighted(double value, SimTime weight) {collectWeighted(value, weight.dbl());}
123 
127  virtual void collectWeighted(SimTime value, SimTime weight) {collectWeighted(value.dbl(), weight.dbl());}
128 
134  virtual void merge(const cStatistic *other) = 0;
135 
140  virtual void clear() = 0;
142 
145 
149  virtual int64_t getCount() const = 0;
150 
156  virtual double getSum() const = 0;
157 
163  virtual double getSqrSum() const = 0;
164 
168  virtual double getMin() const = 0;
169 
173  virtual double getMax() const = 0;
174 
178  virtual double getMean() const = 0;
179 
183  virtual double getStddev() const = 0;
184 
188  virtual double getVariance() const = 0;
190 
196  virtual double getSumWeights() const = 0;
197 
201  virtual double getWeightedSum() const = 0;
202 
206  virtual double getSqrSumWeights() const = 0;
207 
211  virtual double getWeightedSqrSum() const = 0;
213 
216 
221  virtual void saveToFile(FILE *) const = 0;
222 
227  virtual void loadFromFile(FILE *) = 0;
228 
239  virtual void record() {recordAs(nullptr, nullptr);}
240 
250  virtual void recordWithUnit(const char *unit) {recordAs(nullptr, unit);}
251 
260  virtual void recordAs(const char *name, const char *unit=nullptr);
262 };
263 
264 } // namespace omnetpp
265 
266 #endif
267 
omnetpp::cStatistic::~cStatistic
virtual ~cStatistic()
Definition: cstatistic.h:63
omnetpp::cStatistic::recordWithUnit
virtual void recordWithUnit(const char *unit)
Definition: cstatistic.h:250
omnetpp::opp_string_map
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:219
omnetpp::cRandom
Abstract interface for random variate generator classes.
Definition: crandom.h:31
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::cStatistic::collectWeighted
virtual void collectWeighted(double value, SimTime weight)
Definition: cstatistic.h:122
omnetpp::SimTime::dbl
double dbl() const
Definition: simtime.h:346
omnetpp::cStatistic
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
omnetpp::cStatistic::record
virtual void record()
Definition: cstatistic.h:239
omnetpp::cStatistic::collectWeighted
virtual void collectWeighted(SimTime value, SimTime weight)
Definition: cstatistic.h:127
omnetpp::cStatistic::collect
virtual void collect(SimTime value)
Definition: cstatistic.h:107
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
omnetpp::cStatistic::collectWeighted
virtual void collectWeighted(SimTime value, double weight)
Definition: cstatistic.h:117