OMNeT++ Simulation Library  5.4.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 
45 
53 class SIM_API cResultRecorder : public cResultListener
54 {
55  private:
56  cComponent *component;
57  const char *statisticName;
58  const char *recordingMode;
59  cProperty *attrsProperty; // property to take result attributes from (normally @statistic[statisticName])
60  opp_string_map *manualAttrs; // if non-null, overrides attrsProperty
61  bool finishCalled; // to prevent double-recording of scalar results based on multiple signals
62 
63  protected:
64  virtual opp_string_map getStatisticAttributes(); // order: manualAttrs, then attrsProperty
65  virtual opp_string_map getStatisticAttributesFrom(cProperty *property);
66  virtual void tweakTitle(opp_string& title);
67  virtual void callFinish(cResultFilter *prev) override;
68 
69  public:
77  virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs=nullptr);
78  virtual ~cResultRecorder() {delete manualAttrs;}
79  virtual const char *getName() const override {return getStatisticName();}
80  virtual std::string getFullPath() const override {return getComponent()->getFullPath() + "." + getResultName();}
81  virtual cComponent *getComponent() const {return component;}
82  virtual const char *getStatisticName() const {return statisticName;}
83  virtual const char *getRecordingMode() const {return recordingMode;}
84  virtual std::string getResultName() const {return std::string(getStatisticName())+":"+getRecordingMode();}
85 };
86 
96 {
97  protected:
98  // all receiveSignal() methods either throw error or delegate here.
99  virtual void collect(simtime_t_cref t, double value, cObject *details) = 0;
100  protected:
101  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
102  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override;
103  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override;
104  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
105  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
106  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
107  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
108 };
109 
116 {
117  private:
118  cResultRecorder *(*creatorfunc)();
119 
120  public:
124  cResultRecorderType(const char *name, cResultRecorder *(*f)());
125 
130  cResultRecorder *create() const {return creatorfunc();}
131 
136  static cResultRecorderType *find(const char *name);
137 
141  static cResultRecorderType *get(const char *name);
142 };
143 
144 } // namespace omnetpp
145 
146 #endif
147 
virtual std::string getFullPath() const override
Definition: cresultrecorder.h:80
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:53
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Registers a cResultRecorder.
Definition: cresultrecorder.h:115
Abstract base class for numeric result recorders.
Definition: cresultrecorder.h:95
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
Base class for result filters.
Definition: cresultfilter.h:57
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:200
cResultRecorder * create() const
Definition: cresultrecorder.h:130
virtual const char * getName() const override
Definition: cresultrecorder.h:79
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