Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / teenode.cc @ a3be1d55

History | View | Annotate | Download (1.85 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  TEENODE.CC - 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
#include <string.h>
19
#include "channel.h"
20
#include "teenode.h"
21
22
USING_NAMESPACE
23
24
Port *TeeNode::addPort()
25
{
26
    outs.push_back(Port(this));
27
    return &(outs.back());
28
}
29
30
bool TeeNode::isReady() const
31
{
32
    return in()->length()>0;
33
}
34
35
void TeeNode::process()
36
{
37
    Datum d;
38
39
    int n = in()->length();
40
    for (int i=0; i<n; i++)
41
    {
42
        in()->read(&d,1);
43
        for (PortVector::iterator it=outs.begin(); it!=outs.end(); it++)
44
            (*it)()->write(&d,1);
45
    }
46
47
}
48
49
bool TeeNode::isFinished() const
50
{
51
    return in()->eof();
52
}
53
54
//-------
55
56
const char *TeeNodeType::getDescription() const
57
{
58
    return "Splits the input into several output by copying its data.\n";
59
}
60
61
void TeeNodeType::getAttributes(StringMap& attrs) const
62
{
63
}
64
65
Node *TeeNodeType::create(DataflowManager *mgr, StringMap& attrs) const
66
{
67
    checkAttrNames(attrs);
68
69
    Node *node = new TeeNode();
70
    node->setNodeType(this);
71
    mgr->addNode(node);
72
    return node;
73
}
74
75
Port *TeeNodeType::getPort(Node *node, const char *portname) const
76
{
77
    TeeNode *node1 = dynamic_cast<TeeNode *>(node);
78
    if (!strcmp(portname,"next-out"))
79
        return node1->addPort();
80
    else if (!strcmp(portname,"in"))
81
        return &(node1->in);
82
    throw opp_runtime_error("no such port `%s'", portname);
83
}
84
85