cresultfilter.h Source File

API: cresultfilter.h Source File
API
cresultfilter.h
1//==========================================================================
2// CRESULTFILTER.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_CRESULTFILTER_H
17#define __OMNETPP_CRESULTFILTER_H
18
19#include "simkerneldefs.h"
20#include "cresultlistener.h"
21#include "onstartup.h"
22#include "globals.h"
23#include "cownedobject.h"
24
25namespace omnetpp {
26
27class cResultFilter;
28class cProperty;
29
42#define Register_ResultFilter(NAME, CLASSNAME) \
43 __REGISTER_CLASS_X(CLASSNAME, omnetpp::cResultFilter, "result filter", omnetpp::internal::resultFilters.getInstance()->add(new omnetpp::cResultFilterType(NAME,omnetpp::opp_typename(typeid(CLASSNAME)))) )
44
45
58#define Register_ResultFilter2(NAME, CLASSNAME, DESCRIPTION) \
59 __REGISTER_CLASS_X(CLASSNAME, omnetpp::cResultFilter, "result filter", omnetpp::internal::resultFilters.getInstance()->add(new omnetpp::cResultFilterType(NAME,omnetpp::opp_typename(typeid(CLASSNAME)),DESCRIPTION)) )
60
72class SIM_API cResultFilter : public cResultListener
73{
74 public:
82 private:
83 cComponent *component = nullptr;
84 cProperty *attrsProperty = nullptr;
85 cResultListener **delegates; // nullptr-terminated array
86 protected:
87 // methods for invoking the delegates
88 void fire(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details);
89 void fire(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details);
90 void fire(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details);
91 void fire(cResultFilter *prev, simtime_t_cref t, double d, cObject *details);
92 void fire(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details);
93 void fire(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details);
94 void fire(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details);
95 virtual void callFinish(cResultFilter *prev) override;
96 virtual void callEmitInitialValue() override;
97 virtual void forEachChild(cVisitor *v) override;
98 virtual void emitInitialValue() override;
99 public:
100 cResultFilter();
101 ~cResultFilter();
102 virtual void init(Context *ctx);
103 [[deprecated]] virtual void init(cComponent *component, cProperty *attrsProperty) {} // deprecated, left for backward compatibility
104 virtual cResultFilter *clone() const override;
105 virtual double getInitialDoubleValue() const {return NAN;}
106 virtual void addDelegate(cResultListener *delegate);
107 virtual void removeDelegate(cResultListener *delegate);
108 virtual bool hasDelegate(cResultListener *delegate);
109 virtual int getNumDelegates() const;
110 cResultListener *getDelegate(int k) const {return delegates[k];} // unsafe
111 std::vector<cResultListener*> getDelegates() const;
112
113};
114
123class SIM_API cNumericResultFilter : public cResultFilter
124{
125 protected:
126 // all receiveSignal() methods either throw error or delegate here;
127 // return value: whether to invoke chained listeners (true) or to swallow the value (false)
128 virtual bool process(simtime_t& t, double& value, cObject *details) = 0;
129 protected:
130 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
131 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override;
132 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override;
133 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
134 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
135 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
136 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
137};
138
147class SIM_API cObjectResultFilter : public cResultFilter
148{
149 protected:
150 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
151 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override;
152 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override;
153 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
154 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
155 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
156};
157
163class SIM_API cResultFilterType : public cNoncopyableOwnedObject
164{
165 private:
166 std::string description;
167 std::string className;
168
169 public:
173 cResultFilterType(const char *name, const char *className, const char *description=nullptr);
174
179
183 const char *getDescription() const {return description.c_str();}
184
189 static cResultFilterType *find(const char *name);
190
194 static cResultFilterType *get(const char *name);
195};
196
197} // namespace omnetpp
198
199#endif
200
201
int64_t-based, base-10 fixed-point simulation time.
Definition simtime.h:67
Common base for module and channel classes.
Definition ccomponent.h:51
Base class for filters that expect to receive an numeric value.
Definition cresultfilter.h:124
Base class for filters that expect to receive an object.
Definition cresultfilter.h:148
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
cResultFilter * create() const
const char * getDescription() const
Definition cresultfilter.h:183
cResultFilterType(const char *name, const char *className, const char *description=nullptr)
static cResultFilterType * get(const char *name)
static cResultFilterType * find(const char *name)
Base class for result filters.
Definition cresultfilter.h:73
virtual void forEachChild(cVisitor *v) override
Common abstract base class for result filters and result recorders.
Definition cresultlistener.h:35
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition cvisitor.h:57
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
SimTime simtime_t
Represents simulation time.
Definition simtime_t.h:40
const simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition simtime_t.h:48
Definition cresultfilter.h:78
cComponent * component
The module/channel for which the statistic is being recorded; usually the module on which the @statis...
Definition cresultfilter.h:79
cProperty * attrsProperty
An optional property from which extra attributes can be taken; usually the @statistic property.
Definition cresultfilter.h:80