OMNeT++ API 6.1
Discrete Event Simulation Library
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 
25 namespace omnetpp {
26 
27 class cResultFilter;
28 class 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 
72 class SIM_API cResultFilter : public cResultListener
73 {
74  public:
78  struct Context {
81  };
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 
123 class 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 
147 class 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 
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 
178  cResultFilter *create() const;
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 
omnetpp::simtime_t_cref
const typedef simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:48
omnetpp::cObjectResultFilter
Base class for filters that expect to receive an object.
Definition: cresultfilter.h:147
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cResultFilter::Context::component
cComponent * component
The module/channel for which the statistic is being recorded; usually the module on which the @statis...
Definition: cresultfilter.h:79
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
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::cResultFilter::Context::attrsProperty
cProperty * attrsProperty
An optional property from which extra attributes can be taken; usually the @statistic property.
Definition: cresultfilter.h:80
omnetpp::cNumericResultFilter
Base class for filters that expect to receive an numeric value.
Definition: cresultfilter.h:123
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::cResultFilter::Context
Definition: cresultfilter.h:78
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
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::cResultFilterType::getDescription
const char * getDescription() const
Definition: cresultfilter.h:183
omnetpp::cResultListener
Common abstract base class for result filters and result recorders.
Definition: cresultlistener.h:34
omnetpp::cResultFilterType
Registers a cResultFilter.
Definition: cresultfilter.h:163
omnetpp::cProperty
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38