Lumiera  0.pre.03
»edit your freedom«
control-impl.hpp
Go to the documentation of this file.
1 /*
2  CONTROL-IMPL.hpp - time::control implementation building blocks
3 
4  Copyright (C) Lumiera.org
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
53 #ifndef LIB_TIME_CONTROL_IMPL_H
54 #define LIB_TIME_CONTROL_IMPL_H
55 
56 #include "lib/error.hpp"
57 #include "lib/time/mutation.hpp"
58 #include "lib/time/timevalue.hpp"
59 
60 #include <functional>
61 #include <vector>
62 
63 
64 namespace lib {
65 namespace time {
66 namespace mutation {
67 
68  using std::function;
69 
70 
71 
72 
90  template<class TI>
91  class Mutator
92  : public Mutation
93  {
94  typedef function<TI(TI const&)> ValueSetter;
95  typedef function<TI(Offset const&)> Ofsetter;
96  typedef function<TI(int)> Nudger;
97 
98  protected:
99  mutable ValueSetter setVal_;
100  mutable Ofsetter offset_;
101  mutable Nudger nudge_;
102 
103  void
104  ensure_isArmed() const
105  {
106  if (!setVal_)
107  throw error::State("feeding time/value change "
108  "while not (yet) connected to any target to change"
109  ,error::LUMIERA_ERROR_UNCONNECTED);
110  }
111 
112 
113  template<class TAR>
114  void bind_to (TAR& target) const;
115 
116  void unbind();
117 
118  // using default construction and copy
119  };
120 
121 
122 
134  template<class TI>
136  {
137  typedef function<void(TI const&)> ChangeSignal;
138  typedef std::vector<ChangeSignal> ListenerList;
139 
140  ListenerList listeners_;
141 
142  public:
144  template<class SIG>
145  void
146  attach (SIG const& toNotify)
147  {
148  ChangeSignal newListener (std::ref(toNotify));
149  listeners_.push_back (newListener);
150  }
151 
153  void
155  {
156  listeners_.clear();
157  }
158 
160  TI
161  operator() (TI const& changedVal) const
162  {
163  typedef typename ListenerList::const_iterator Iter;
164  Iter p = listeners_.begin();
165  Iter e = listeners_.end();
166 
167  for ( ; p!=e; ++p )
168  (*p) (changedVal);
169  return changedVal;
170  }
171 
172  // using default construction and copy
173  };
174 
175 }}} // lib::time::mutation
176 
177 
178 /* ===== Definition of actual operations ===== */
180 
181 
182 
183 
184 template<class TI>
185 template<class TAR>
186 void
188 {
190 
191  setVal_ = Policy<TI,TI, TAR>::buildChangeHandler (target);
193  nudge_ = Policy<TI,int, TAR>::buildChangeHandler (target);
194 }
195 
196 template<class TI>
197 void
199 {
200  setVal_ = ValueSetter();
201  offset_ = Ofsetter();
202  nudge_ = Nudger();
203 }
204 
205 
206 #endif
Implementation building block: propagate changes to listeners.
Definition of special cases when imposing a change onto concrete time values.
Modifying time and timecode values.
void disconnect()
disconnect any observers
Interface: an opaque change imposed onto some time value.
Definition: mutation.hpp:100
Implementation namespace for support and library code.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:196
void attach(SIG const &toNotify)
install notification receiver
Lumiera error handling (C++ interface).
Policy how to impose changes onto a connected target time value entity This policy will be parametris...
Implementation building block: impose changes to a Time element.
a family of time value like entities and their relationships.