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)
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
44 #ifndef LIB_TIME_CONTROL_IMPL_H
45 #define LIB_TIME_CONTROL_IMPL_H
46 
47 #include "lib/error.hpp"
48 #include "lib/time/mutation.hpp"
49 #include "lib/time/timevalue.hpp"
50 
51 #include <functional>
52 #include <vector>
53 
54 
55 namespace lib {
56 namespace time {
57 namespace mutation {
58 
59  using std::function;
60 
61 
62 
63 
81  template<class TI>
82  class Mutator
83  : public Mutation
84  {
85  typedef function<TI(TI const&)> ValueSetter;
86  typedef function<TI(Offset const&)> Ofsetter;
87  typedef function<TI(int)> Nudger;
88 
89  protected:
90  mutable ValueSetter setVal_;
91  mutable Ofsetter offset_;
92  mutable Nudger nudge_;
93 
94  void
95  ensure_isArmed() const
96  {
97  if (!setVal_)
98  throw error::State("feeding time/value change "
99  "while not (yet) connected to any target to change"
100  ,error::LUMIERA_ERROR_UNCONNECTED);
101  }
102 
103 
104  template<class TAR>
105  void bind_to (TAR& target) const;
106 
107  void unbind();
108 
109  // using default construction and copy
110  };
111 
112 
113 
125  template<class TI>
127  {
128  typedef function<void(TI const&)> ChangeSignal;
129  typedef std::vector<ChangeSignal> ListenerList;
130 
131  ListenerList listeners_;
132 
133  public:
135  template<class SIG>
136  void
137  attach (SIG const& toNotify)
138  {
139  ChangeSignal newListener (std::ref(toNotify));
140  listeners_.push_back (newListener);
141  }
142 
144  void
146  {
147  listeners_.clear();
148  }
149 
151  TI
152  operator() (TI const& changedVal) const
153  {
154  typedef typename ListenerList::const_iterator Iter;
155  Iter p = listeners_.begin();
156  Iter e = listeners_.end();
157 
158  for ( ; p!=e; ++p )
159  (*p) (changedVal);
160  return changedVal;
161  }
162 
163  // using default construction and copy
164  };
165 
166 }}} // lib::time::mutation
167 
168 
169 /* ===== Definition of actual operations ===== */
171 
172 
173 
174 
175 template<class TI>
176 template<class TAR>
177 void
179 {
181 
182  setVal_ = Policy<TI,TI, TAR>::buildChangeHandler (target);
184  nudge_ = Policy<TI,int, TAR>::buildChangeHandler (target);
185 }
186 
187 template<class TI>
188 void
190 {
191  setVal_ = ValueSetter();
192  offset_ = Ofsetter();
193  nudge_ = Nudger();
194 }
195 
196 
197 #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:91
Implementation namespace for support and library code.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
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.