InPortPublisher.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef __InPortPublisher_hxx__
00023 #define __InPortPublisher_hxx__
00024 
00025 #include "InPort.hxx"
00026 #include <typeinfo>
00027 
00028 namespace CLAM
00029 {
00030 
00031 template<typename Token>
00032 class InPortPublisher : public InPortBase
00033 {
00034         typedef InPort<Token> ProperInPort;     
00035         
00037         int GetSize()   { return 0; }
00039         void SetSize(int newSize) {}
00041         int GetHop() { return 0; }
00043         void SetHop(int newHop) {}
00044         
00045 public:
00046         typedef std::list< ProperInPort * > ProperInPortsList;
00047 
00048         InPortPublisher( const std::string & name = "unnamed in port", Processing * proc = 0 )
00049                 : InPortBase( name, proc )
00050         {
00051         }
00052         
00053         virtual ~InPortPublisher()
00054         {       
00055                 if ( GetVisuallyConnectedOutPort() )
00056                         Disconnect();
00057         }
00058 
00059         void PublishInPort( InPortBase & in )
00060         {
00061                 CLAM_ASSERT( SameType(GetTypeId(),in.GetTypeId()), 
00062                 "InPortPublisher<Token>::PublishInPort coudn't connect to outPort "
00063                 "because was not templatized by the same Token type as InPortPublisher" );
00064                 CLAM_ASSERT( not in.IsPublisher(), 
00065                 "InPortPublisher<Token>::PublishInPort() publishing a publisher is not supported");
00066                 
00067                 ConcretePublishInPort( static_cast<ProperInPort&>(in) );
00068         }
00069         //why not pass InPortBase? still not needed to call from the "generic" interface
00070         void UnPublishInPort( ProperInPort& in )
00071         {
00072                 mPublishedInPortsList.remove(&in);
00073         }
00074 
00075         void ConcretePublishInPort( ProperInPort & in )
00076         {
00077                 mPublishedInPortsList.push_back( &in );
00078         }
00079         
00080         
00081         
00082         bool CanConsume()
00083         {
00084                 typename ProperInPortsList::iterator it;
00085                 for(it=mPublishedInPortsList.begin(); it!=mPublishedInPortsList.end(); it++)
00086                         if(!(*it)->CanConsume())
00087                                 return false;
00088                 return true;    
00089         }
00090         
00091 
00092         typename ProperInPortsList::iterator BeginPublishedInPortsList()
00093         {
00094                 return mPublishedInPortsList.begin();
00095         }
00096         
00097         typename ProperInPortsList::iterator EndPublishedInPortsList()
00098         {
00099                 return mPublishedInPortsList.end();
00100         }
00101 
00103         void UnAttachRegion() 
00104         {
00105                 SetVisuallyConnectedOutPort( 0 );
00106                 typename ProperInPortsList::iterator it;
00107                 for(it=mPublishedInPortsList.begin(); it!=mPublishedInPortsList.end(); it++)
00108                 {
00109                         (*it)->UnAttachRegion();
00110                 }
00111         }
00112         
00113         bool IsPublisherOf( InPortBase& in) const
00114         {       
00115                 // BIG TODO: go in-depth (search for publisher-publiser-inport)
00116                 typename ProperInPortsList::const_iterator it;
00117                 for(it=mPublishedInPortsList.begin(); it!=mPublishedInPortsList.end(); it++)
00118                 {
00119                         if( *it == &in)
00120                                 return true;
00121                 }
00122                 return false;
00123         }
00124         bool IsPublisher() const
00125         {
00126                 return true;
00127         }
00128         virtual const std::type_info & GetTypeId() const 
00129         {
00130                 return typeid(Token);
00131         };
00132  protected:
00133 
00134         ProperInPortsList mPublishedInPortsList;
00135 };
00136 
00137 } // namespace CLAM
00138 
00139 #endif // __InPortPublisher_hxx__
00140 
Generated by  doxygen 1.6.3