Statistics
| Branch: | Revision:

root / src / envir / resultrecorder.h @ 68da4f12

History | View | Annotate | Download (3.75 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  RESULTRECORDER.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_RESULTRECORDER_H
19
#define __ENVIR_RESULTRECORDER_H
20
21
#include "envirdefs.h"
22
#include "resultlistener.h"
23
#include "ccomponent.h"
24
#include "commonutil.h"
25
#include "stringpool.h"
26
#include "onstartup.h"
27
#include "cregistrationlist.h"
28
29
class ResultRecorder;
30
31
#define Register_ResultRecorder(NAME, CLASSNAME) \
32
  static ResultRecorder *__FILEUNIQUENAME__() {return new CLASSNAME;} \
33
  EXECUTE_ON_STARTUP(resultRecorders.getInstance()->add(new ResultRecorderDescriptor(NAME,__FILEUNIQUENAME__));)
34
35
extern cGlobalRegistrationList resultRecorders;
36
37
38
/**
39
 * Abstract base class for result recorders.
40
 */
41
class ENVIR_API ResultRecorder : public ResultListener
42
{
43
    private:
44
        static CommonStringPool namesPool;
45
        cComponent *component;
46
        const char *statisticName;
47
        const char *recordingMode;
48
    protected:
49
        virtual opp_string_map getStatisticAttributes();
50
        virtual void tweakTitle(opp_string& title);
51
    public:
52
        virtual void init(cComponent *component, const char *statisticName, const char *recordingMode);
53
        virtual cComponent *getComponent() const {return component;}
54
        virtual const char *getStatisticName() const {return statisticName;}
55
        virtual const char *getRecordingMode() const {return recordingMode;}
56
        virtual std::string getResultName() const {return std::string(getStatisticName())+":"+getRecordingMode();}
57
};
58
59
/**
60
 * Abstract base class for numeric result recorders. Numeric result recorders
61
 * convert all numeric data types to double, and throw an error for non-numeric
62
 * types (const char *, cObject *).
63
 */
64
class ENVIR_API NumericResultRecorder : public ResultRecorder
65
{
66
    protected:
67
        // all receiveSignal() methods either throw error or delegate here.
68
        virtual void collect(simtime_t_cref t, double value) = 0;
69
    public:
70
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, long l);
71
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l);
72
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, double d);
73
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v);
74
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s);
75
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *obj);
76
};
77
78
/**
79
 * Registers a ResultRecorder.
80
 */
81
class ENVIR_API ResultRecorderDescriptor : public cNoncopyableOwnedObject
82
{
83
  private:
84
    ResultRecorder *(*creatorfunc)();
85
86
  public:
87
    /**
88
     * Constructor.
89
     */
90
    ResultRecorderDescriptor(const char *name, ResultRecorder *(*f)());
91
92
    /**
93
     * Creates an instance of a particular class by calling the creator
94
     * function.
95
     */
96
    ResultRecorder *create() const  {return creatorfunc();}
97
98
    /**
99
     * Finds the factory object for the given name. The class must have been
100
     * registered previously with the Register_ResultRecorder() macro.
101
     */
102
    static ResultRecorderDescriptor *find(const char *name);
103
104
    /**
105
     * Like find(), but throws an error if the object was not found.
106
     */
107
    static ResultRecorderDescriptor *get(const char *name);
108
};
109
110
#endif