This file is indexed.

/usr/include/CLAM/OutPort.hxx is in libclam-dev 1.4.0-5build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
 * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
 *                         UNIVERSITAT POMPEU FABRA
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef __OutPort_hxx__
#define __OutPort_hxx__

#include "WritingRegion.hxx"
#include <typeinfo>
#include <list>
#include <string>
#include "InPort.hxx"
#include "InPortPublisher.hxx"

namespace CLAM
{

class Processing;

class OutPortBase
{
public:
	typedef std::list<InPortBase*> InPortsList;
	OutPortBase( const std::string & name = "unnamed out port", Processing * proc = 0 );
	virtual ~OutPortBase();
	const std::string & GetName();
	Processing * GetProcessing();
	InPortsList::iterator BeginVisuallyConnectedInPorts();
	InPortsList::iterator EndVisuallyConnectedInPorts();
	
	virtual void ConnectToIn(InPortBase& in) = 0;
	virtual void DisconnectFromIn(InPortBase & in) = 0;
	virtual void DisconnectFromAll()=0;
	virtual bool IsVisuallyConnectedTo(InPortBase & in) = 0;
	virtual bool IsConnectableTo(InPortBase & ) = 0;
	virtual bool CanProduce()=0;
	virtual int GetSize()=0;
	virtual void SetSize(int newSize)=0;
	virtual int GetHop()=0;
	virtual void SetHop(int newHop)=0;
	bool HasConnections(){ return mVisuallyConnectedPorts.size()!=0; }
	virtual void CenterEvenRegions()=0;
	void SetPublisher( OutPortBase& publisher); 
	void UnsetPublisher(); 
	virtual bool IsPublisher() const { return false; }
	virtual void UnpublishOutPort() =0;
	virtual const std::type_info & GetTypeId() const = 0;
protected:
	InPortsList mVisuallyConnectedPorts;	
	std::string mName;
	Processing * mProcessing;
	OutPortBase* mPublisher;
};


template<typename Token>
class OutPort : public OutPortBase
{
	typedef OutPort<Token> ProperOutPort;
	typedef InPort<Token> ProperInPort;
	typedef InPortPublisher<Token> ProperInPortPublisher;
	typedef WritingRegion<Token> ProperWritingRegion;
public:
	OutPort( const std::string & name = "unnamed out port", Processing * proc = 0 );
	virtual ~OutPort();

	void DisconnectFromAll();
	void ConnectToIn( InPortBase& in);
	void ConnectToConcreteIn(InPort<Token>& in);
	void DisconnectFromIn( InPortBase& in);
	void DisconnectFromConcreteIn(InPort<Token>& in);
	bool IsConnectableTo(InPortBase & in);
	bool IsVisuallyConnectedTo(InPortBase & in);
	bool IsPhysicallyConnectedToIn(InPort<Token>& ); 
	InPortPublisher<Token>* GetPublisherContaining(InPort<Token>&);

	Token & GetData(int offset=0);	
	void SetSize( int newSize );
	int GetSize();
	int GetHop();
	void SetHop( int hop );	
	void Produce();
	bool CanProduce();
	void CenterEvenRegions();
	
	void UnpublishOutPort() {} 
	virtual const std::type_info & GetTypeId() const
        {
                return typeid(Token);
        };

	Token & GetLastWrittenData( int offset = 0 );
protected:	
	bool ConnectToPublisher( ProperInPortPublisher & in );

	bool TryDisconnectFromPublisher( InPortBase & in );
	bool TryDisconnectFromConcreteIn( InPortBase & in );

	ProperWritingRegion mRegion;

};

template<class Token>
OutPort<Token>::OutPort( const std::string & name, Processing * proc )
	: OutPortBase(name,proc)
{
}

template<class Token>
void OutPort<Token>::DisconnectFromAll()
{
	InPortsList::iterator it = mVisuallyConnectedPorts.begin();
	for( it=BeginVisuallyConnectedInPorts(); it!=EndVisuallyConnectedInPorts(); it++ )	
	{ 
		(*it)->UnAttachRegion();
	}
	mVisuallyConnectedPorts.clear();
}

template<class Token>
OutPort<Token>::~OutPort()
{
	DisconnectFromAll();
}


template<class Token>
bool OutPort<Token>::ConnectToPublisher( InPortPublisher<Token> & in )
{
	 
	InPortPublisher<Token> * publisher =  &in;
	
	mVisuallyConnectedPorts.push_back( &in );
	typename InPortPublisher<Token>::ProperInPortsList::iterator it;
	for( it=publisher->BeginPublishedInPortsList(); it!=publisher->EndPublishedInPortsList(); it++)
		(*it)->AttachRegionToOutPort(this, mRegion );

	in.SetVisuallyConnectedOutPort(this);

	return true;
}

template<class Token>
void OutPort<Token>::ConnectToIn( InPortBase& in)
{
	CLAM_ASSERT( IsConnectableTo(in),
		     "OutPort<Token>::connectToIn coudn't connect to inPort "
   		     "because was not templatized by the same Token type as outPort" );
	if (in.IsPublisher())
		ConnectToPublisher( static_cast<ProperInPortPublisher&>(in) );
	else
		ConnectToConcreteIn( static_cast<ProperInPort&>(in) );
}

template<class Token>
void OutPort<Token>::ConnectToConcreteIn(InPort<Token>& in)
{
	CLAM_ASSERT( !in.GetVisuallyConnectedOutPort(), "OutPort<Token>::ConnectToConcreteIn - Trying to connect an inport "
						    "already connected to another out port" );
	CLAM_ASSERT( !IsVisuallyConnectedTo(in), "OutPort<Token>::ConnectToConcreteIn - Trying to connect an in port "
					"already connected to this out port" );
	mVisuallyConnectedPorts.push_back(&in);
	in.AttachRegionToOutPort(this, mRegion );
}

template<class Token>
void OutPort<Token>::DisconnectFromIn( InPortBase& in)
{
	CLAM_ASSERT ( IsConnectableTo(in), 
		     "OutPort<Token>::DisconnectFromIn coudn't discconnect from inPort "
   		     "because was not templatized by the same Token type as outPort" );

	if (in.IsPublisher()) 
		TryDisconnectFromPublisher( in );
	else 
		TryDisconnectFromConcreteIn( in );
}

template<class Token>
bool OutPort<Token>::TryDisconnectFromConcreteIn( InPortBase & in )
{
	CLAM_ASSERT( IsConnectableTo(in), "TryDisconnectFromConcreteIn: expect the same token template");

	ProperInPort * concreteIn = static_cast<ProperInPort*>(&in);
	DisconnectFromConcreteIn( *concreteIn );
	return true;
}

template<class Token>
bool OutPort<Token>::TryDisconnectFromPublisher( InPortBase & in )
{
	CLAM_ASSERT( IsConnectableTo(in), "TryDisconnectFromPublisher: expect the same token template");

	InPortPublisher<Token> *publisher = static_cast<InPortPublisher<Token> *>(&in);
	
	mVisuallyConnectedPorts.remove( &in );
	typename InPortPublisher<Token>::ProperInPortsList::iterator it;
	for( it=publisher->BeginPublishedInPortsList(); it!=publisher->EndPublishedInPortsList(); it++)
	{
		if( (*it)->GetVisuallyConnectedOutPort())
			(*it)->UnAttachRegion();
	}
	return true;
}

template<class Token>
void OutPort<Token>::DisconnectFromConcreteIn(InPort<Token>& in)
{
	CLAM_ASSERT( IsVisuallyConnectedTo(in) || IsPhysicallyConnectedToIn(in), 
			"OutPort::DisconnectFromConcreteIn() in port is not directly neither physically connected" );
	if (IsVisuallyConnectedTo(in) )
	{
		// is directly connected
		mVisuallyConnectedPorts.remove(&in);
	}
	else // then IsPhysicallyConnected()
	{
		InPortPublisher<Token> *pub = GetPublisherContaining(in);
		CLAM_DEBUG_ASSERT(0!=pub, "in port should be published");
		pub->UnPublishInPort(in);
	}
	in.UnAttachRegion();
}

template<class Token>
Token & OutPort<Token>::GetData(int offset )
{
	return mRegion[offset];
}

template<class Token>
void OutPort<Token>::SetSize( int newSize )
{
	mRegion.Size( newSize );
}

template<class Token>
int OutPort<Token>::GetSize()
{
	return mRegion.Size();
}

template<class Token>
int OutPort<Token>::GetHop()
{
	return mRegion.Hop();
}

template<class Token>
void OutPort<Token>::SetHop( int hop )
{
	mRegion.Hop(hop);
}

template<class Token>
void OutPort<Token>::Produce()
{
	mRegion.Produce();
}

template<class Token>
bool OutPort<Token>::CanProduce()
{
	return mRegion.CanProduce();
}

template<class Token>
bool OutPort<Token>::IsConnectableTo(InPortBase & in)
{	
	return SameType(in.GetTypeId(), GetTypeId());
}

template<class Token>
bool OutPort<Token>::IsPhysicallyConnectedToIn(InPort<Token>& in)
{ 
	if (IsVisuallyConnectedTo(in))
		return true;
	
	return ( 0!=GetPublisherContaining(in) );
	
}

template<class Token>
InPortPublisher<Token>* OutPort<Token>::GetPublisherContaining(InPort<Token>& in)
{
	
	InPortsList::iterator it;
	for( it=mVisuallyConnectedPorts.begin(); it!=mVisuallyConnectedPorts.end(); it++ )
		if ( (*it)->IsPublisherOf(in) )
			return static_cast<InPortPublisher<Token> *>(*it);

	return 0;
		
}

template<class Token>
bool OutPort<Token>::IsVisuallyConnectedTo(InPortBase & in)
{
	InPortsList::iterator it;
	for( it=mVisuallyConnectedPorts.begin(); it!=mVisuallyConnectedPorts.end(); it++ )
		if(*it == &in) return true;
	return false;
}
	
template<class Token>
void OutPort<Token>::CenterEvenRegions()
{
	mRegion.CenterEvenRegions();
}

template<class Token>
Token & OutPort<Token>::GetLastWrittenData( int offset )
{
	CLAM_DEBUG_ASSERT( 0 <= offset, "OutPort<Token>::GetLastWrittenData - Index under bounds" );
	CLAM_DEBUG_ASSERT( offset <= GetSize(), "OutPort<Token>::GetLastWrittenData - Index over bounds" );
	return mRegion.GetLastWrittenData( offset );
}

} // namespace CLAM

#endif // __OutPort_hxx__