cresultrecorder.h Source File

API: cresultrecorder.h Source File
API
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
25namespace omnetpp {
26
27class cResultRecorder;
28class 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
70class 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
128class SIM_API cNumericResultRecorder : public cResultRecorder
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
148class SIM_API cResultRecorderType : public cNoncopyableOwnedObject
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
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
int64_t-based, base-10 fixed-point simulation time.
Definition simtime.h:67
Common base for module and channel classes.
Definition ccomponent.h:51
Abstract base class for numeric result recorders.
Definition cresultrecorder.h:129
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition cobject.h:93
Stores a (NED) property with its (possibly compound) value.
Definition cproperty.h:39
Base class for result filters.
Definition cresultfilter.h:73
Common abstract base class for result filters and result recorders.
Definition cresultlistener.h:35
cResultRecorderType(const char *name, const char *className, const char *description=nullptr)
cResultRecorder * create() const
static cResultRecorderType * find(const char *name)
const char * getDescription() const
Definition cresultrecorder.h:168
static cResultRecorderType * get(const char *name)
Abstract base class for result recorders.
Definition cresultrecorder.h:71
virtual const char * getName() const override
Definition cresultrecorder.h:110
virtual std::string getFullPath() const override
Definition cresultrecorder.h:111
Definition opp_pooledstring.h:64
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition opp_string.h:220
Lightweight string class, used internally in some parts of OMNeT++.
Definition opp_string.h:40
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
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
const simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition simtime_t.h:48
Definition cresultrecorder.h:82
const char * statisticName
The base name for the statistic; usually the index of the @statistic [] property (the name in bracket...
Definition cresultrecorder.h:84
cComponent * component
The statistic should be recorded for this module/channel; usually the module on which the @statistic ...
Definition cresultrecorder.h:83
const char * recordingMode
The recording mode; usually an element the the record=... list in the @statistic property.
Definition cresultrecorder.h:85
cProperty * attrsProperty
An optional property from which extra attributes can be taken; usually the @statistic property.
Definition cresultrecorder.h:86