OMNeT++ Simulation Library  5.6.1
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 
41 #define Register_ResultFilter(NAME, CLASSNAME) \
42  static omnetpp::cResultFilter *__FILEUNIQUENAME__() {return new CLASSNAME;} \
43  EXECUTE_ON_STARTUP(omnetpp::resultFilters.getInstance()->add(new omnetpp::cResultFilterType(NAME,__FILEUNIQUENAME__));)
44 
45 
57 #define Register_ResultFilter2(NAME, CLASSNAME, DESCRIPTION) \
58  static omnetpp::cResultFilter *__FILEUNIQUENAME__() {return new CLASSNAME;} \
59  EXECUTE_ON_STARTUP(omnetpp::resultFilters.getInstance()->add(new omnetpp::cResultFilterType(NAME,__FILEUNIQUENAME__,DESCRIPTION));)
60 
72 class SIM_API cResultFilter : public cResultListener
73 {
74  private:
75  cResultListener **delegates; // nullptr-terminated array
76  protected:
77  // methods for invoking the delegates
78  void fire(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details);
79  void fire(cResultFilter *prev, simtime_t_cref t, long l, cObject *details);
80  void fire(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details);
81  void fire(cResultFilter *prev, simtime_t_cref t, double d, cObject *details);
82  void fire(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details);
83  void fire(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details);
84  void fire(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details);
85  virtual void callFinish(cResultFilter *prev) override;
86  virtual void forEachChild(cVisitor *v) override;
87  public:
88  cResultFilter();
89  ~cResultFilter();
90  virtual void init(cComponent *component, cProperty *attrsProperty) {}
91  virtual double getInitialDoubleValue() const {return NAN;}
92  virtual void addDelegate(cResultListener *delegate);
93  virtual int getNumDelegates() const;
94  cResultListener *getDelegate(int k) const {return delegates[k];} // unsafe
95  std::vector<cResultListener*> getDelegates() const;
96 
97 };
98 
107 class SIM_API cNumericResultFilter : public cResultFilter
108 {
109  protected:
110  // all receiveSignal() methods either throw error or delegate here;
111  // return value: whether to invoke chained listeners (true) or to swallow the value (false)
112  virtual bool process(simtime_t& t, double& value, cObject *details) = 0;
113  protected:
114  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
115  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override;
116  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override;
117  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
118  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
119  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
120  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
121 };
122 
131 class SIM_API cObjectResultFilter : public cResultFilter
132 {
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, long l, cObject *details) override;
136  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long 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 };
141 
148 {
149  private:
150  std::string description;
151  cResultFilter *(*factory)();
152 
153  public:
157  cResultFilterType(const char *name, cResultFilter *(*f)(), const char *description=nullptr);
158 
163  cResultFilter *create() const {return factory();}
164 
168  const char *getDescription() const {return description.c_str();}
169 
174  static cResultFilterType *find(const char *name);
175 
179  static cResultFilterType *get(const char *name);
180 };
181 
182 } // namespace omnetpp
183 
184 #endif
185 
186 
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
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Base class for filters that expect to receive an numeric value.
Definition: cresultfilter.h:107
Registers a cResultFilter.
Definition: cresultfilter.h:147
const char * getDescription() const
Definition: cresultfilter.h:168
cResultFilter * create() const
Definition: cresultfilter.h:163
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
Base class for result filters.
Definition: cresultfilter.h:72
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
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
Base class for filters that expect to receive an object.
Definition: cresultfilter.h:131