Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / node.h @ a3be1d55

History | View | Annotate | Download (4.12 KB)

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

    
21
#include "scavedefs.h"
22
#include "commonutil.h"
23

    
24
NAMESPACE_BEGIN
25

    
26

    
27
class Node;
28
class NodeType;
29
class Channel;
30
class DataflowManager;
31

    
32
/**
33
 * Represents a data element in an output vector file. Processing nodes
34
 * (Node) process elements of this type.
35
 *
36
 * @see Node, Channel, Port
37
 */
38
struct Datum
39
{
40
    // x value stored as a double or a BigDecimal, usually the simulation time t
41
    double x;       // x value as double
42
    BigDecimal xp;  // precise x value, BigDecimal::Nil if not filled in
43
    double y;       // usually the value at t
44
    eventnumber_t eventNumber;
45

    
46
    Datum() : xp(BigDecimal::Nil), eventNumber(-1) {}
47
};
48

    
49

    
50
/**
51
 * Connection point of channels in processing nodes.
52
 *
53
 * @see Datum, Node, Channel
54
 */
55
class SCAVE_API Port
56
{
57
    private:
58
        Node *ownernode;
59
        Channel *chan;
60
    public:
61
        Port(Node *owner) {ownernode = owner; chan = 0;}
62
        Port(const Port& p) {ownernode = p.ownernode; chan = p.chan;}
63
        ~Port() {}
64
        void setChannel(Channel *channel) {Assert(!chan); chan = channel;}
65
        Node *getNode() {return ownernode;}
66
        Channel *getChannel() const  {return chan;}
67
        Channel *operator()() const {Assert(chan); return chan;}
68
};
69

    
70

    
71
/**
72
 * Processing node. Processing nodes can be connected via ports and channels
73
 * to form a data flow network.
74
 *
75
 * @see DataflowManager, Port, Channel, Datum, NodeType
76
 */
77
class SCAVE_API Node
78
{
79
        friend class DataflowManager;
80

    
81
    private:
82
        DataflowManager *mgr;
83
        NodeType *nodetype;
84
        bool alreadyfinished;
85

    
86
    protected:
87
        /**
88
         * Called when the node is added to the dataflow manager.
89
         */
90
        void setDataflowManager(DataflowManager *m) {mgr = m;}
91

    
92
    public:
93
        /**
94
         * Constructor
95
         */
96
        Node() {mgr=NULL; nodetype=NULL; alreadyfinished=false;}
97

    
98
        /**
99
         * Virtual destructor
100
         */
101
        virtual ~Node() {}
102

    
103
        /**
104
         * Returns the dataflow manager in which this node is inserted.
105
         */
106
        DataflowManager *dataflowManager() const {return mgr;}
107

    
108
        /**
109
         * Should be called right after construction by the corresponding
110
         * NodeType class.
111
         */
112
        void setNodeType(const NodeType *t)  {nodetype = const_cast<NodeType *>(t);}
113

    
114
        /**
115
         * Returns the corresponding NodeType class.
116
         */
117
        NodeType *getNodeType() const {return nodetype;}
118

    
119
        /** @name Execution and scheduling */
120
        //@{
121
        /**
122
         * Do some amount of work, then return
123
         */
124
        virtual void process() = 0;
125

    
126
        /**
127
         * Are more invocations of process() necessary()?
128
         */
129
        virtual bool isFinished() const = 0;
130

    
131
        /**
132
         * Provided it has not isFinished() yet, can process() be invoked
133
         * right now? (isFinished() is called first -- isReady() is only
134
         * invoked if isFinished() returns false. So isReady() doesn't need
135
         * to check for eof.)
136
         */
137
        virtual bool isReady() const = 0;
138
        //@}
139

    
140
        /**
141
         * Invoked by the dataflow manager when the node's isFinished() first
142
         * returns true. It sets a status flag so that further invocations
143
         * of isFinished() can be avoided.
144
         */
145
        void setAlreadyFinished() {alreadyfinished = true;}
146

    
147
        /**
148
         * Used by the dataflow manager. Returns true if setAlreadyFinished()
149
         * has already been invoked.
150
         */
151
        bool getAlreadyFinished() {return alreadyfinished;}
152
};
153

    
154
NAMESPACE_END
155

    
156

    
157
#endif
158

    
159