Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / mergernodes.h @ a3be1d55

History | View | Annotate | Download (3.16 KB)

1
//=========================================================================
2
//  MERGERNODES.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 _MERGERNODES_H_
19
#define _MERGERNODES_H_
20

    
21
#include "commonnodes.h"
22

    
23
#include <vector>
24
#include "node.h"
25
#include "nodetype.h"
26

    
27
NAMESPACE_BEGIN
28

    
29

    
30
/**
31
 * Processing node which merges several input streams into one.
32
 */
33
class SCAVE_API MergerNode : public Node
34
{
35
    public:
36
        typedef std::vector<Port> PortVector;
37
        Port out;
38
        PortVector ports;
39
    public:
40
        MergerNode() : out(this) {}
41
        virtual ~MergerNode() {}
42

    
43
        Port *addPort();
44

    
45
        virtual bool isReady() const;
46
        virtual void process();
47
        virtual bool isFinished() const;
48
};
49

    
50
class SCAVE_API MergerNodeType : public NodeType
51
{
52
    public:
53
        virtual const char *getName() const {return "merger";}
54
        virtual const char *getCategory() const {return "merger";}
55
        virtual const char *getDescription() const;
56
        virtual bool isHidden() const {return true;}
57
        virtual void getAttributes(StringMap& attrs) const;
58
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
59
        virtual Port *getPort(Node *node, const char *portname) const;
60
};
61

    
62
/**
63
 * Processing node which aggregates several input streams into one.
64
 *
65
 * It can compute the average/count/minimum/maximum of its inputs.
66
 *
67
 * TODO: compute all statistics at once.
68
 */
69
class SCAVE_API AggregatorNode : public Node
70
{
71
    private:
72
        enum Function
73
        {
74
            Sum, Average, Count, Minimum, Maximum
75
        };
76

    
77
        Function fn;
78
        double acc;
79
        int count;
80

    
81
        void init();
82
        void collect(double value);
83
        double result();
84
    public:
85
        typedef std::vector<Port> PortVector;
86
        Port out;
87
        PortVector ports;
88
    public:
89
        AggregatorNode(const std::string &function);
90
        virtual ~AggregatorNode() {}
91

    
92
        Port *addPort();
93

    
94
        virtual bool isReady() const;
95
        virtual void process();
96
        virtual bool isFinished() const;
97
};
98

    
99
class SCAVE_API AggregatorNodeType : public NodeType
100
{
101
    public:
102
        virtual const char *getName() const {return "aggregator";}
103
        virtual const char *getCategory() const {return "merger";}
104
        virtual const char *getDescription() const;
105
        virtual bool isHidden() const {return true;}
106
        virtual void getAttributes(StringMap& attrs) const;
107
        virtual void getAttrDefaults(StringMap& attrs) const;
108
        virtual void validateAttrValues(const StringMap& attrs) const;
109
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
110
        virtual Port *getPort(Node *node, const char *portname) const;
111
};
112

    
113
NAMESPACE_END
114

    
115

    
116
#endif
117

    
118

    
119