CLAM-Development  1.4.0
InPortPublisher.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 __InPortPublisher_hxx__
23 #define __InPortPublisher_hxx__
24 
25 #include "InPort.hxx"
26 #include <typeinfo>
27 
28 namespace CLAM
29 {
30 
31 template<typename Token>
33 {
34  typedef InPort<Token> ProperInPort;
35 
37  int GetSize() { return 0; }
39  void SetSize(int newSize) {}
41  int GetHop() { return 0; }
43  void SetHop(int newHop) {}
44 
45 public:
46  typedef std::list< ProperInPort * > ProperInPortsList;
47 
48  InPortPublisher( const std::string & name = "unnamed in port", Processing * proc = 0 )
49  : InPortBase( name, proc )
50  {
51  }
52 
53  virtual ~InPortPublisher()
54  {
56  Disconnect();
57  }
58 
60  {
62  "InPortPublisher<Token>::PublishInPort coudn't connect to outPort "
63  "because was not templatized by the same Token type as InPortPublisher" );
64  CLAM_ASSERT( not in.IsPublisher(),
65  "InPortPublisher<Token>::PublishInPort() publishing a publisher is not supported");
66 
67  ConcretePublishInPort( static_cast<ProperInPort&>(in) );
68  }
69  //why not pass InPortBase? still not needed to call from the "generic" interface
71  {
72  mPublishedInPortsList.remove(&in);
73  }
74 
76  {
77  mPublishedInPortsList.push_back( &in );
78  }
79 
80 
81 
82  bool CanConsume()
83  {
84  typename ProperInPortsList::iterator it;
85  for(it=mPublishedInPortsList.begin(); it!=mPublishedInPortsList.end(); it++)
86  if(!(*it)->CanConsume())
87  return false;
88  return true;
89  }
90 
91 
92  typename ProperInPortsList::iterator BeginPublishedInPortsList()
93  {
94  return mPublishedInPortsList.begin();
95  }
96 
97  typename ProperInPortsList::iterator EndPublishedInPortsList()
98  {
99  return mPublishedInPortsList.end();
100  }
101 
104  {
106  typename ProperInPortsList::iterator it;
107  for(it=mPublishedInPortsList.begin(); it!=mPublishedInPortsList.end(); it++)
108  {
109  (*it)->UnAttachRegion();
110  }
111  }
112 
113  bool IsPublisherOf( InPortBase& in) const
114  {
115  // BIG TODO: go in-depth (search for publisher-publiser-inport)
116  typename ProperInPortsList::const_iterator it;
117  for(it=mPublishedInPortsList.begin(); it!=mPublishedInPortsList.end(); it++)
118  {
119  if( *it == &in)
120  return true;
121  }
122  return false;
123  }
124  bool IsPublisher() const
125  {
126  return true;
127  }
128  virtual const std::type_info & GetTypeId() const
129  {
130  return typeid(Token);
131  };
132  protected:
133 
135 };
136 
137 } // namespace CLAM
138 
139 #endif // __InPortPublisher_hxx__
140