CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Flow
Ports
OutPortPublisher.hxx
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3
* UNIVERSITAT POMPEU FABRA
4
*
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*
20
*/
21
22
#ifndef __OutPortPublisher_hxx__
23
#define __OutPortPublisher_hxx__
24
25
#include "
OutPort.hxx
"
26
27
namespace
CLAM
28
{
29
30
template
<
typename
Token >
31
class
OutPortPublisher
:
public
OutPortBase
32
{
33
typedef
OutPort<Token>
ProperOutPort
;
34
public
:
35
OutPortPublisher
(
const
std::string & name =
"unnamed out port publisher"
,
Processing
* proc = 0 )
36
:
OutPortBase
( name, proc ),
mPublishedOutPort
(0)
37
{
38
39
}
40
41
virtual
~OutPortPublisher
()
42
{
43
//disconnect published port
44
if
(
mPublishedOutPort
)
45
{
46
mPublishedOutPort
->
UnsetPublisher
();
47
mPublishedOutPort
->
DisconnectFromAll
();
48
mPublishedOutPort
= 0;
49
}
50
//disconnect visually connected inports
51
for
(InPortsList::iterator it =
BeginVisuallyConnectedInPorts
();
52
it !=
EndVisuallyConnectedInPorts
();
53
it++ )
54
(*it)->SetVisuallyConnectedOutPort(0);
55
56
}
57
58
void
DisconnectFromAll
()
59
{
60
CLAM_DEBUG_ASSERT
(
mPublishedOutPort
!= 0,
"OutPortPublisher - no out port published"
);
61
mPublishedOutPort
->
DisconnectFromAll
();
62
mVisuallyConnectedPorts
.clear();
63
}
64
void
ConnectToIn
(
InPortBase
& in)
65
{
66
CLAM_DEBUG_ASSERT
(
mPublishedOutPort
!= 0,
"OutPortPublisher - no out port published"
);
67
mPublishedOutPort
->
ConnectToIn
( in );
68
in.
SetVisuallyConnectedOutPort
(
this
);
69
mVisuallyConnectedPorts
.push_back(&in);
70
}
71
72
void
PublishOutPort
(
OutPortBase
& out )
73
{
74
CLAM_ASSERT
(
SameType
(
GetTypeId
(),out.
GetTypeId
()),
75
"OutPortPublisher<Token>::PublishOutPort coudn't connect to outPort "
76
"because was not templatized by the same Token type as OutPortPublisher"
);
77
78
CLAM_ASSERT
( not out.
IsPublisher
(),
79
"OutPortPublisher<Token>::PublishOutPort: can not publish a publisher (yet)"
);
80
81
ConcretePublishOutPort
( static_cast<ProperOutPort&>(out) );
82
83
}
84
void
UnpublishOutPort
()
85
{
86
mPublishedOutPort
= 0;
87
}
88
bool
IsPublisher
()
const
89
{
90
return
true
;
91
92
}
93
void
ConcretePublishOutPort
(
ProperOutPort
& out )
94
{
95
mPublishedOutPort
= &out;
96
out.
SetPublisher
( *
this
);
97
}
98
99
void
DisconnectFromIn
(
InPortBase
& in)
100
{
101
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::DisconnectFromIn() A published port is missing. "
102
"Consider using the method PublishOutPort( OutPortBase& out) "
);
103
mPublishedOutPort
->
DisconnectFromIn
( in );
104
mVisuallyConnectedPorts
.remove(&in);
105
}
106
107
bool
IsConnectableTo
(
InPortBase
& in)
108
{
109
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::IsConnectableTo() A published port is missing. "
110
"Consider using the method PublishOutPort( OutPortBase& out) "
);
111
return
mPublishedOutPort
->
IsConnectableTo
( in );
112
}
113
114
bool
IsVisuallyConnectedTo
(
InPortBase
& in)
115
{
116
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher:IsVisuallyConnectedTo() A published port is missing. "
117
"Consider using the method PublishOutPort( OutPortBase& out) "
);
118
return
mPublishedOutPort
->
IsVisuallyConnectedTo
( in );
119
}
120
121
Token &
GetData
(
int
offset=0)
122
{
123
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::GetData() A published port is missing. "
124
"Consider using the method PublishOutPort( OutPortBase& out) "
);
125
return
mPublishedOutPort
->
GetData
( offset );
126
}
127
128
int
GetSize
()
129
{
130
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::GetSize() A published port is missing. "
131
"Consider using the method PublishOutPort( OutPortBase& out) "
);
132
return
mPublishedOutPort
->
GetSize
();
133
}
134
135
void
SetSize
(
int
newSize)
136
{
137
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::SetSize() A published port is missing. "
138
"Consider using the method PublishOutPort( OutPortBase& out) "
);
139
mPublishedOutPort
->
SetSize
( newSize );
140
}
141
142
int
GetHop
()
143
{
144
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::GetHop() A published port is missing. "
145
"Consider using the method PublishOutPort( OutPortBase& out) "
);
146
return
mPublishedOutPort
->
GetHop
();
147
}
148
149
void
SetHop
(
int
newHop)
150
{
151
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::SetHop() A published port is missing. "
152
"Consider using the method PublishOutPort( OutPortBase& out) "
);
153
mPublishedOutPort
->
SetHop
( newHop );
154
}
155
156
157
bool
CanProduce
()
158
{
159
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::CanProduce() A published port is missing. "
160
"Consider using the method PublishOutPort( OutPortBase& out) "
);
161
return
mPublishedOutPort
->
CanProduce
();
162
}
163
164
void
CenterEvenRegions
()
165
{
166
CLAM_ASSERT
(
mPublishedOutPort
,
"OutPortPublisher::CenterEvenRegions() A published port is missing. "
167
"Consider using the method PublishOutPort( OutPortBase& out) "
);
168
mPublishedOutPort
->
CenterEvenRegions
();
169
}
170
Token &
GetLastWrittenData
(
int
offset = 0 )
171
{
172
return
mPublishedOutPort
->
GetLastWrittenData
(offset);
173
}
174
175
virtual
const
std::type_info &
GetTypeId
()
const
176
{
177
return
typeid
(Token);
178
};
179
180
181
protected
:
182
ProperOutPort *
mPublishedOutPort
;
183
};
184
185
186
}
// namespace CLAM
187
188
#endif // __OutPortPublisher_hxx__
189
Generated by
1.8.1