OMNeT++ Simulation Library  5.6.1
cresultrecorder.h
1 //==========================================================================
2 // CRESULTRECORDER.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_CRESULTRECORDER_H
17 #define __OMNETPP_CRESULTRECORDER_H
18 
19 #include "cresultlistener.h"
20 #include "ccomponent.h"
21 #include "onstartup.h"
22 #include "globals.h"
23 
24 namespace omnetpp {
25 
26 class cResultRecorder;
27 class cProperty;
28 
41 #define Register_ResultRecorder(NAME, CLASSNAME) \
42  static omnetpp::cResultRecorder *__FILEUNIQUENAME__() {return new CLASSNAME;} \
43  EXECUTE_ON_STARTUP(omnetpp::resultRecorders.getInstance()->add(new omnetpp::cResultRecorderType(NAME,__FILEUNIQUENAME__));)
44 
57 #define Register_ResultRecorder2(NAME, CLASSNAME, DESCRIPTION) \
58  static omnetpp::cResultRecorder *__FILEUNIQUENAME__() {return new CLASSNAME;} \
59  EXECUTE_ON_STARTUP(omnetpp::resultRecorders.getInstance()->add(new omnetpp::cResultRecorderType(NAME,__FILEUNIQUENAME__,DESCRIPTION));)
60 
61 
69 class SIM_API cResultRecorder : public cResultListener
70 {
71  private:
72  cComponent *component;
73  const char *statisticName;
74  const char *recordingMode;
75  cProperty *attrsProperty; // property to take result attributes from (normally @statistic[statisticName])
76  opp_string_map *manualAttrs; // if non-null, overrides attrsProperty
77  bool finishCalled; // to prevent double-recording of scalar results based on multiple signals
78 
79  protected:
80  virtual opp_string_map getStatisticAttributes(); // order: manualAttrs, then attrsProperty
81  virtual opp_string_map getStatisticAttributesFrom(cProperty *property);
82  virtual void tweakTitle(opp_string& title);
83  virtual void callFinish(cResultFilter *prev) override;
84 
85  public:
93  virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs=nullptr);
94  virtual ~cResultRecorder() {delete manualAttrs;}
95  virtual const char *getName() const override {return getStatisticName();}
96  virtual std::string getFullPath() const override {return getComponent()->getFullPath() + "." + getResultName();}
97  virtual cComponent *getComponent() const {return component;}
98  virtual const char *getStatisticName() const {return statisticName;}
99  virtual const char *getRecordingMode() const {return recordingMode;}
100  virtual std::string getResultName() const {return std::string(getStatisticName())+":"+getRecordingMode();}
101 };
102 
112 {
113  protected:
114  // all receiveSignal() methods either throw error or delegate here.
115  virtual void collect(simtime_t_cref t, double value, cObject *details) = 0;
116  protected:
117  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
118  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override;
119  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override;
120  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
121  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
122  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
123  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
124 };
125 
132 {
133  private:
134  std::string description;
135  cResultRecorder *(*factory)();
136 
137  public:
141  cResultRecorderType(const char *name, cResultRecorder *(*f)(), const char *description=nullptr);
142 
147  cResultRecorder *create() const {return factory();}
148 
152  const char *getDescription() const {return description.c_str();}
153 
158  static cResultRecorderType *find(const char *name);
159 
163  static cResultRecorderType *get(const char *name);
164 };
165 
166 } // namespace omnetpp
167 
168 #endif
169 
virtual std::string getFullPath() const override
Definition: cresultrecorder.h:96
Lightweight string class, used internally in some parts of OMNeT++.
Definition: opp_string.h:39
Common base for module and channel classes.
Definition: ccomponent.h:48
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
Abstract base class for result recorders.
Definition: cresultrecorder.h:69
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Registers a cResultRecorder.
Definition: cresultrecorder.h:131
Abstract base class for numeric result recorders.
Definition: cresultrecorder.h:111
cResultRecorder * create() const
Definition: cresultrecorder.h:147
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
Base class for result filters.
Definition: cresultfilter.h:72
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:200
virtual const char * getName() const override
Definition: cresultrecorder.h:95
Definition: cabstracthistogram.h:21
Common abstract base class for result filters and result recorders.
Definition: cresultlistener.h:34
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication...
Definition: cownedobject.h:248
const char * getDescription() const
Definition: cresultrecorder.h:152