#ifndef NETWORKLIB_CONNECTION_LIST_H
#define NETWORKLIB_CONNECTION_LIST_H

class ConnectionListIterator;

class ConnectionList : public NetworkObject {

	public:
		ConnectionList();
		~ConnectionList();

		void Clear();

		Connection & AddConnection( Router & a , Router & b );
		void RemoveConnection( Router & a , Router & b );

		unsigned int GetConnectionNum() const;
		Connection * GetConnection( const Router & a , const Router & b ) const;

		friend class ConnectionListIterator;

	private:
		
		struct ConnectionListEntry { 
						Connection			* connection; 
						ConnectionListEntry * next; 
		};
		
		ConnectionListEntry * first;
};

class ConnectionListIterator {
	public:
		ConnectionListIterator( ConnectionList * par=0 ) { list = par; current = list ? list->first : 0; }
		~ConnectionListIterator()			{}

		void Init( ConnectionList * par )	{ list = par; current = list->first; }
		
		Connection * GetConnection() const	{
												return current ? current->connection : 0;
											}
		
		Connection * operator++(int)		{ 
												if( current ) 
													current = current->next;
												return current ? current->connection : 0;
											}	

		void Begin()						{ current = list->first; }
		bool IsEnd() const					{ return (current == 0); }

	private:
		ConnectionList						* list;
		ConnectionList::ConnectionListEntry * current;
};

#endif // NETWORKLIB_CONNECTION_LIST_H
