Statistics
| Branch: | Revision:

root / src / envir / resultfilter.h @ fbe00e73

History | View | Annotate | Download (4.75 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  RESULTFILTER.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17
18
#ifndef __ENVIR_RESULTFILTER_H
19
#define __ENVIR_RESULTFILTER_H
20
21
#include "envirdefs.h"
22
#include "resultlistener.h"
23
#include "stringpool.h"
24
#include "onstartup.h"
25
#include "cregistrationlist.h"
26
#include "cownedobject.h"
27
28
class ResultFilter;
29
30
#define Register_ResultFilter(NAME, CLASSNAME) \
31
  static ResultFilter *__FILEUNIQUENAME__() {return new CLASSNAME;} \
32
  EXECUTE_ON_STARTUP(resultFilters.getInstance()->add(new ResultFilterDescriptor(NAME,__FILEUNIQUENAME__));)
33
34
extern cGlobalRegistrationList resultFilters;
35
36
/**
37
 * Base class for result filters. Result filters map ONE SIGNAL to ONE SIGNAL
38
 * (i.e. vector-to-vector one-to-one mapping), and accept several listeners
39
 * (delegates). Result filters do not record anything -- that is left to result
40
 * recorders.
41
 */
42
class ENVIR_API ResultFilter : public ResultListener
43
{
44
    private:
45
        ResultListener **delegates; // NULL-terminated array
46
    protected:
47
        // methods for invoking the delegates
48
        void fire(ResultFilter *prev, simtime_t_cref t, long l);
49
        void fire(ResultFilter *prev, simtime_t_cref t, unsigned long l);
50
        void fire(ResultFilter *prev, simtime_t_cref t, double d);
51
        void fire(ResultFilter *prev, simtime_t_cref t, const SimTime& v);
52
        void fire(ResultFilter *prev, simtime_t_cref t, const char *s);
53
        void fire(ResultFilter *prev, simtime_t_cref t, cObject *obj);
54
    public:
55
        ResultFilter();
56
        ~ResultFilter();
57
        virtual void addDelegate(ResultListener *delegate);
58
        virtual int getNumDelegates() const;
59
        std::vector<ResultListener*> getDelegates() const;
60
        virtual void finish(ResultFilter *prev);
61
};
62
63
/**
64
 * Base class for filters that expect to receive an numeric value.
65
 * This class overrides all other receiveSignal() methods to throw an exception,
66
 * and delegates numeric types to a common (actually, two common) methods.
67
 */
68
class ENVIR_API NumericResultFilter : public ResultFilter
69
{
70
    protected:
71
        // all receiveSignal() methods either throw error or delegate here;
72
        // return value: whether to invoke chained listeners (true) or to swallow the value (false)
73
        virtual bool process(simtime_t& t, double& value) = 0;
74
    public:
75
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, long l);
76
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l);
77
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, double d);
78
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v);
79
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s);
80
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *obj);
81
};
82
83
/**
84
 * Base class for filters that expect to receive an object.
85
 * This class overrides all other receiveSignal() methods
86
 * to throw an exception.
87
 */
88
class ENVIR_API ObjectResultFilter : public ResultFilter
89
{
90
    public:
91
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, long l);
92
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l);
93
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, double d);
94
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v);
95
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s);
96
};
97
98
/**
99
 * Registers a ResultFilter.
100
 */
101
class ENVIR_API ResultFilterDescriptor : public cNoncopyableOwnedObject
102
{
103
  private:
104
    ResultFilter *(*creatorfunc)();
105
106
  public:
107
    /**
108
     * Constructor.
109
     */
110
    ResultFilterDescriptor(const char *name, ResultFilter *(*f)());
111
112
    /**
113
     * Creates an instance of a particular class by calling the creator
114
     * function.
115
     */
116
    ResultFilter *create() const  {return creatorfunc();}
117
118
    /**
119
     * Finds the factory object for the given name. The class must have been
120
     * registered previously with the Register_ResultFilter() macro.
121
     */
122
    static ResultFilterDescriptor *find(const char *name);
123
124
    /**
125
     * Like find(), but throws an error if the object was not found.
126
     */
127
    static ResultFilterDescriptor *get(const char *name);
128
};
129
130
#endif
131