SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
feed.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * SHORE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 #ifndef SHORE_PROCESSING_FEED_HPP__
27 #define SHORE_PROCESSING_FEED_HPP__
28 
29 #include <boost/bind.hpp>
30 
31 #include "signalslot.hpp"
32 
33 namespace shore {
34 
36 template<typename T>
37 class feed
38 {
39  public:
40 
41  typedef T current_type;
42  typedef T append_type;
43 
44  private:
45 
46  typedef feed this_type;
47 
49  signal<void> m_sigflush;
50 
51  slot<void> m_slotfreeze;
52  slot<void> m_slotthaw;
53 
54  bool m_frozen;
55 
56 
57  void freeze()
58  {
59  m_frozen=true;
60  }
61 
62  void thaw()
63  {
64  m_frozen=false;
65  }
66 
67  public:
68 
69  feed()
70  :m_slotfreeze(boost::bind(&this_type::freeze,this)),
71  m_slotthaw(boost::bind(&this_type::thaw,this)),
72  m_frozen(false)
73  {}
74 
76  feed(const feed& t)
77  :m_slotfreeze(boost::bind(&this_type::freeze,this)),
78  m_slotthaw(boost::bind(&this_type::thaw,this)),
79  m_frozen(t.m_frozen)
80  {
81  m_slotfreeze.copy_connections(t.m_slotfreeze);
82  m_slotthaw.copy_connections(t.m_slotthaw);
83  }
84 
86  {
87  return m_sigdata;
88  }
89 
90  signal<void>& sigflush()
91  {
92  return m_sigflush;
93  }
94 
99  void append(const append_type &d)
100  {
101  if(m_frozen)
102  throw std::logic_error("append to frozen feed");
103  m_sigdata.emit(d);
104  }
105 
106  void flush()
107  {
108  if(m_frozen)
109  throw std::logic_error("flush frozen feed");
110  m_sigflush.emit();
111  }
112 
113  slot<void>& slotfreeze()
114  {
115  return m_slotfreeze;
116  }
117 
118  slot<void>& slotthaw()
119  {
120  return m_slotthaw;
121  }
122 };
123 
124 } //namespace shore
125 
126 #endif // SHORE_PROCESSING_FEED_HPP__
127