OMNeT++ API 6.1
Discrete Event Simulation Library
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 "opp_pooledstring.h"
23 #include "globals.h"
24 
25 namespace omnetpp {
26 
27 class cResultRecorder;
28 class cProperty;
29 
43 #define Register_ResultRecorder(NAME, CLASSNAME) \
44  __REGISTER_CLASS_X(CLASSNAME, omnetpp::cResultRecorder, "result recorder", omnetpp::internal::resultRecorders.getInstance()->add(new omnetpp::cResultRecorderType(NAME,omnetpp::opp_typename(typeid(CLASSNAME)))) )
45 
59 #define Register_ResultRecorder2(NAME, CLASSNAME, DESCRIPTION) \
60  __REGISTER_CLASS_X(CLASSNAME, omnetpp::cResultRecorder, "result recorder", omnetpp::internal::resultRecorders.getInstance()->add(new omnetpp::cResultRecorderType(NAME,omnetpp::opp_typename(typeid(CLASSNAME)),DESCRIPTION)) )
61 
62 
70 class SIM_API cResultRecorder : public cResultListener
71 {
72  public:
82  struct Context {
84  const char *statisticName;
85  const char *recordingMode;
87  opp_string_map *manualAttrs = nullptr; // If attrsProperty==nullptr, specifies an alternative source of attributes; the ownership is passed into the result recorder object.
88  };
89  private:
90  cComponent *component = nullptr;
91  opp_pooledstring statisticName = nullptr;
92  opp_pooledstring recordingMode = nullptr;
93  opp_pooledstring demuxLabel = nullptr;
94  cProperty *attrsProperty = nullptr; // property to take result attributes from (normally @statistic[statisticName])
95  opp_string_map *manualAttrs = nullptr; // if non-null, overrides attrsProperty
96  bool finishCalled = false; // to prevent double-recording of scalar results based on multiple signals
97 
98  protected:
99  virtual opp_string_map getStatisticAttributes(); // order: manualAttrs, then attrsProperty
100  virtual opp_string_map getStatisticAttributesFrom(cProperty *property);
101  virtual void tweakTitle(opp_string& title);
102  virtual void callFinish(cResultFilter *prev) override;
103 
104  public:
105  cResultRecorder() {}
106  virtual ~cResultRecorder() {delete manualAttrs;}
107  virtual void init(Context *ctx);
108  [[deprecated]] virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs=nullptr) {} // deprecated, left for backward compatibility
109  virtual cResultRecorder *clone() const override;
110  virtual const char *getName() const override {return getStatisticName();}
111  virtual std::string getFullPath() const override {return getComponent()->getFullPath() + "." + getResultName();}
112  virtual cComponent *getComponent() const {return component;}
113  virtual const char *getStatisticName() const {return statisticName.c_str();}
114  virtual const char *getRecordingMode() const {return recordingMode.c_str();}
115  virtual const char *getDemuxLabel() const {return demuxLabel.c_str();}
116  virtual void setDemuxLabel(const char *s) {demuxLabel = s;}
117  virtual std::string getResultName() const;
118 };
119 
129 {
130  protected:
131  // all receiveSignal() methods either throw error or delegate here.
132  virtual void collect(simtime_t_cref t, double value, cObject *details) = 0;
133  protected:
134  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
135  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override;
136  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override;
137  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
138  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
139  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
140  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
141 };
142 
149 {
150  private:
151  std::string description;
152  std::string className;
153 
154  public:
158  cResultRecorderType(const char *name, const char *className, const char *description=nullptr);
159 
163  cResultRecorder *create() const;
164 
168  const char *getDescription() const {return description.c_str();}
169 
174  static cResultRecorderType *find(const char *name);
175 
179  static cResultRecorderType *get(const char *name);
180 };
181 
182 } // namespace omnetpp
183 
184 #endif
185 
omnetpp::simtime_t_cref
const typedef simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:48
omnetpp::cResultRecorder::Context::attrsProperty
cProperty * attrsProperty
An optional property from which extra attributes can be taken; usually the @statistic property.
Definition: cresultrecorder.h:86
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cResultRecorder::getName
virtual const char * getName() const override
Definition: cresultrecorder.h:110
omnetpp::cResultRecorder::Context::component
cComponent * component
The statistic should be recorded for this module/channel; usually the module on which the @statistic ...
Definition: cresultrecorder.h:83
omnetpp::opp_string
Lightweight string class, used internally in some parts of OMNeT++.
Definition: opp_string.h:39
omnetpp::cResultRecorder::Context::statisticName
const char * statisticName
The base name for the statistic; usually the index of the @statistic[] property (the name in brackets...
Definition: cresultrecorder.h:84
omnetpp::cResultRecorder::Context
Definition: cresultrecorder.h:82
omnetpp::cResultRecorderType::getDescription
const char * getDescription() const
Definition: cresultrecorder.h:168
omnetpp::opp_string_map
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:219
omnetpp::cNumericResultRecorder
Abstract base class for numeric result recorders.
Definition: cresultrecorder.h:128
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::uintval_t
uint64_t uintval_t
Unsigned integer type which is guaranteed to be at least 64 bits wide. It is used throughout the libr...
Definition: simkerneldefs.h:109
omnetpp::cResultRecorder
Abstract base class for result recorders.
Definition: cresultrecorder.h:70
omnetpp::cResultRecorder::Context::recordingMode
const char * recordingMode
The recording mode; usually an element the the record=... list in the @statistic property.
Definition: cresultrecorder.h:85
omnetpp::cResultRecorder::getFullPath
virtual std::string getFullPath() const override
Definition: cresultrecorder.h:111
omnetpp::cResultRecorderType
Registers a cResultRecorder.
Definition: cresultrecorder.h:148
omnetpp::intval_t
int64_t intval_t
Signed integer type which is guaranteed to be at least 64 bits wide. It is used throughout the librar...
Definition: simkerneldefs.h:101
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
omnetpp::opp_pooledstring
Definition: opp_pooledstring.h:63
omnetpp::cResultFilter
Base class for result filters.
Definition: cresultfilter.h:72
omnetpp::cNoncopyableOwnedObject
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication.
Definition: cownedobject.h:242
omnetpp::cResultListener
Common abstract base class for result filters and result recorders.
Definition: cresultlistener.h:34
omnetpp::cProperty
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38