OMNeT++ Simulation Library  6.0.3
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 bool hasDelegate(cResultListener *delegate);
108  virtual int getNumDelegates() const;
109  cResultListener *getDelegate(int k) const {return delegates[k];} // unsafe
110  std::vector<cResultListener*> getDelegates() const;
111 
112 };
113 
122 class SIM_API cNumericResultFilter : public cResultFilter
123 {
124  protected:
125  // all receiveSignal() methods either throw error or delegate here;
126  // return value: whether to invoke chained listeners (true) or to swallow the value (false)
127  virtual bool process(simtime_t& t, double& value, cObject *details) = 0;
128  protected:
129  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
130  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override;
131  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override;
132  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
133  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
134  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
135  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override;
136 };
137 
146 class SIM_API cObjectResultFilter : public cResultFilter
147 {
148  protected:
149  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override;
150  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override;
151  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override;
152  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override;
153  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override;
154  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override;
155 };
156 
163 {
164  private:
165  std::string description;
166  std::string className;
167 
168  public:
172  cResultFilterType(const char *name, const char *className, const char *description=nullptr);
173 
177  cResultFilter *create() const;
178 
182  const char *getDescription() const {return description.c_str();}
183 
188  static cResultFilterType *find(const char *name);
189 
193  static cResultFilterType *get(const char *name);
194 };
195 
196 } // namespace omnetpp
197 
198 #endif
199 
200 
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:146
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:122
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:182
omnetpp::cResultListener
Common abstract base class for result filters and result recorders.
Definition: cresultlistener.h:34
omnetpp::cResultFilterType
Registers a cResultFilter.
Definition: cresultfilter.h:162
omnetpp::cProperty
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38